Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ManageTest.php
Go to the documentation of this file.
1 <?php
8 
13 {
17  protected $customerSession;
18 
22  protected $coreSession;
23 
27  protected function setUp()
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  }
36 
40  protected function tearDown()
41  {
42  $this->customerSession->setCustomerId(null);
43  $this->coreSession->unsData('_form_key');
44  }
45 
49  public function testSaveAction()
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  }
71 
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  }
98 }
assertRedirect(\PHPUnit\Framework\Constraint\Constraint $urlConstraint=null)
$objectManager
Definition: bootstrap.php:17