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

Public Member Functions

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

Protected Member Functions

 setUp ()
 
 tearDown ()
 
- Protected Member Functions inherited from AbstractController
 _getBootstrap ()
 
 setUp ()
 
 tearDown ()
 
 assertPostConditions ()
 
 getMessages ( $messageType=null, $messageManagerClass=\Magento\Framework\Message\Manager::class)
 

Protected Attributes

 $customerSession
 
 $coreSession
 
- Protected Attributes inherited from AbstractController
 $_runCode = ''
 
 $_runScope = 'store'
 
 $_runOptions = []
 
 $_request
 
 $_response
 
 $_objectManager
 
 $_assertSessionErrors = false
 

Detailed Description

@magentoDbIsolation enabled

Definition at line 12 of file ManageTest.php.

Member Function Documentation

◆ setUp()

setUp ( )
protected

Test setup

Definition at line 27 of file ManageTest.php.

28  {
29  parent::setUp();
31  $this->customerSession = $objectManager->get(\Magento\Customer\Model\Session::class);
32  $this->customerSession->setCustomerId(1);
33  $this->coreSession = $objectManager->get(\Magento\Framework\Session\Generic::class);
34  $this->coreSession->setData('_form_key', 'formKey');
35  }
$objectManager
Definition: bootstrap.php:17

◆ tearDown()

tearDown ( )
protected

test tearDown

Definition at line 40 of file ManageTest.php.

41  {
42  $this->customerSession->setCustomerId(null);
43  $this->coreSession->unsData('_form_key');
44  }

◆ testSaveAction()

testSaveAction ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Check that errors

Check that success message

Definition at line 49 of file ManageTest.php.

50  {
51  $this->getRequest()
52  ->setParam('form_key', 'formKey')
53  ->setParam('is_subscribed', '1');
54  $this->dispatch('newsletter/manage/save');
55 
56  $this->assertRedirect($this->stringContains('customer/account/'));
57 
61  $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
62 
66  $this->assertSessionMessages(
67  $this->equalTo(['We have saved your subscription.']),
68  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
69  );
70  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

◆ testSaveActionRemoveSubscription()

testSaveActionRemoveSubscription ( )

@magentoDataFixture Magento/Customer/_files/customer.php

Check that errors

Check that success message

Definition at line 75 of file ManageTest.php.

76  {
77 
78  $this->getRequest()
79  ->setParam('form_key', 'formKey')
80  ->setParam('is_subscribed', '0');
81  $this->dispatch('newsletter/manage/save');
82 
83  $this->assertRedirect($this->stringContains('customer/account/'));
84 
88  $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
89 
93  $this->assertSessionMessages(
94  $this->equalTo(['We have updated your subscription.']),
95  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
96  );
97  }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)

Field Documentation

◆ $coreSession

$coreSession
protected

Definition at line 22 of file ManageTest.php.

◆ $customerSession

$customerSession
protected

Definition at line 17 of file ManageTest.php.


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