Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions
IndexTest Class Reference
Inheritance diagram for IndexTest:
AbstractController

Public Member Functions

 testPostAction ()
 
 testInvalidPostAction ($params, $expectedMessage)
 
- Public Member Functions inherited from AbstractController
 getRequest ()
 
 getResponse ()
 
 assert404NotFound ()
 
 assertHeaderPcre ($headerName, $valueRegex)
 
 assertRedirect (\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
 

Static Public Member Functions

static dataInvalidPostAction ()
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractController
 _getBootstrap ()
 
 setUp ()
 
 tearDown ()
 
 assertPostConditions ()
 
 getMessages ( $messageType=null, $messageManagerClass=\Magento\Framework\Message\Manager::class)
 
- Protected Attributes inherited from AbstractController
 $_runCode = ''
 
 $_runScope = 'store'
 
 $_runOptions = []
 
 $_request
 
 $_response
 
 $_objectManager
 
 $_assertSessionErrors = false
 

Detailed Description

Contact index controller test

Definition at line 14 of file IndexTest.php.

Member Function Documentation

◆ dataInvalidPostAction()

static dataInvalidPostAction ( )
static
Returns
array

Definition at line 62 of file IndexTest.php.

63  {
64  return [
65  'missing_comment' => [
66  'params' => [
67  'name' => 'customer name',
68  'comment' => '',
69  'email' => '[email protected]',
70  'hideit' => '',
71  ],
72  'expectedMessage' => "Enter the comment and try again.",
73  ],
74  'missing_name' => [
75  'params' => [
76  'name' => '',
77  'comment' => 'customer comment',
78  'email' => '[email protected]',
79  'hideit' => '',
80  ],
81  'expectedMessage' => "Enter the Name and try again.",
82  ],
83  'invalid_email' => [
84  'params' => [
85  'name' => 'customer name',
86  'comment' => 'customer comment',
87  'email' => 'invalidemail',
88  'hideit' => '',
89  ],
90  'expectedMessage' => "The email address is invalid. Verify the email address and try again.",
91  ],
92  ];
93  }

◆ testInvalidPostAction()

testInvalidPostAction (   $params,
  $expectedMessage 
)

Test validation.

Parameters
array$paramsFor Request.
string$expectedMessageExpected response.

@dataProvider dataInvalidPostAction

Definition at line 47 of file IndexTest.php.

48  {
49  $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
50 
51  $this->dispatch('contact/index/post');
52  $this->assertRedirect($this->stringContains('contact/index'));
53  $this->assertSessionMessages(
54  $this->contains($expectedMessage),
55  \Magento\Framework\Message\MessageInterface::TYPE_ERROR
56  );
57  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

◆ testPostAction()

testPostAction ( )

Test contacting.

Definition at line 19 of file IndexTest.php.

20  {
21  $params = [
22  'name' => 'customer name',
23  'comment' => 'comment',
24  'email' => '[email protected]',
25  'hideit' => '',
26  ];
27  $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST);
28 
29  $this->dispatch('contact/index/post');
30  $this->assertRedirect($this->stringContains('contact/index'));
31  $this->assertSessionMessages(
32  $this->contains(
33  "Thanks for contacting us with your comments and questions. We'll respond to you very soon."
34  ),
35  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
36  );
37  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18

The documentation for this class was generated from the following file: