12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Contact\Controller;
- use Magento\Framework\App\Request\Http as HttpRequest;
- /**
- * Contact index controller test
- */
- class IndexTest extends \Magento\TestFramework\TestCase\AbstractController
- {
- /**
- * Test contacting.
- */
- public function testPostAction()
- {
- $params = [
- 'name' => 'customer name',
- 'comment' => 'comment',
- 'email' => 'user@example.com',
- 'hideit' => '',
- ];
- $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
- $this->dispatch('contact/index/post');
- $this->assertRedirect($this->stringContains('contact/index'));
- $this->assertSessionMessages(
- $this->contains(
- "Thanks for contacting us with your comments and questions. We'll respond to you very soon."
- ),
- \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
- );
- }
- /**
- * Test validation.
- *
- * @param array $params For Request.
- * @param string $expectedMessage Expected response.
- *
- * @dataProvider dataInvalidPostAction
- */
- public function testInvalidPostAction($params, $expectedMessage)
- {
- $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
- $this->dispatch('contact/index/post');
- $this->assertRedirect($this->stringContains('contact/index'));
- $this->assertSessionMessages(
- $this->contains($expectedMessage),
- \Magento\Framework\Message\MessageInterface::TYPE_ERROR
- );
- }
- /**
- * @return array
- */
- public static function dataInvalidPostAction()
- {
- return [
- 'missing_comment' => [
- 'params' => [
- 'name' => 'customer name',
- 'comment' => '',
- 'email' => 'user@example.com',
- 'hideit' => '',
- ],
- 'expectedMessage' => "Enter the comment and try again.",
- ],
- 'missing_name' => [
- 'params' => [
- 'name' => '',
- 'comment' => 'customer comment',
- 'email' => 'user@example.com',
- 'hideit' => '',
- ],
- 'expectedMessage' => "Enter the Name and try again.",
- ],
- 'invalid_email' => [
- 'params' => [
- 'name' => 'customer name',
- 'comment' => 'customer comment',
- 'email' => 'invalidemail',
- 'hideit' => '',
- ],
- 'expectedMessage' => "The email address is invalid. Verify the email address and try again.",
- ],
- ];
- }
- }
|