IndexTest.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Contact\Controller;
  7. use Magento\Framework\App\Request\Http as HttpRequest;
  8. /**
  9. * Contact index controller test
  10. */
  11. class IndexTest extends \Magento\TestFramework\TestCase\AbstractController
  12. {
  13. /**
  14. * Test contacting.
  15. */
  16. public function testPostAction()
  17. {
  18. $params = [
  19. 'name' => 'customer name',
  20. 'comment' => 'comment',
  21. 'email' => 'user@example.com',
  22. 'hideit' => '',
  23. ];
  24. $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
  25. $this->dispatch('contact/index/post');
  26. $this->assertRedirect($this->stringContains('contact/index'));
  27. $this->assertSessionMessages(
  28. $this->contains(
  29. "Thanks for contacting us with your comments and questions. We&#039;ll respond to you very soon."
  30. ),
  31. \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
  32. );
  33. }
  34. /**
  35. * Test validation.
  36. *
  37. * @param array $params For Request.
  38. * @param string $expectedMessage Expected response.
  39. *
  40. * @dataProvider dataInvalidPostAction
  41. */
  42. public function testInvalidPostAction($params, $expectedMessage)
  43. {
  44. $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
  45. $this->dispatch('contact/index/post');
  46. $this->assertRedirect($this->stringContains('contact/index'));
  47. $this->assertSessionMessages(
  48. $this->contains($expectedMessage),
  49. \Magento\Framework\Message\MessageInterface::TYPE_ERROR
  50. );
  51. }
  52. /**
  53. * @return array
  54. */
  55. public static function dataInvalidPostAction()
  56. {
  57. return [
  58. 'missing_comment' => [
  59. 'params' => [
  60. 'name' => 'customer name',
  61. 'comment' => '',
  62. 'email' => 'user@example.com',
  63. 'hideit' => '',
  64. ],
  65. 'expectedMessage' => "Enter the comment and try again.",
  66. ],
  67. 'missing_name' => [
  68. 'params' => [
  69. 'name' => '',
  70. 'comment' => 'customer comment',
  71. 'email' => 'user@example.com',
  72. 'hideit' => '',
  73. ],
  74. 'expectedMessage' => "Enter the Name and try again.",
  75. ],
  76. 'invalid_email' => [
  77. 'params' => [
  78. 'name' => 'customer name',
  79. 'comment' => 'customer comment',
  80. 'email' => 'invalidemail',
  81. 'hideit' => '',
  82. ],
  83. 'expectedMessage' => "The email address is invalid. Verify the email address and try again.",
  84. ],
  85. ];
  86. }
  87. }