Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
NewsletterTemplateTest.php
Go to the documentation of this file.
1 <?php
7 
12 {
16  private $formKey;
17 
21  protected $model;
22 
26  protected function setUp()
27  {
28  parent::setUp();
29  $formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
30  $this->formKey = $formKey->getFormKey();
31  $post = [
32  'code' => 'test data',
33  'subject' => 'test data2',
34  'sender_email' => '[email protected]',
35  'sender_name' => 'Test Sender Name',
36  'text' => 'Template Content',
37  'form_key' => $this->formKey,
38  ];
39  $this->getRequest()->setPostValue($post)->setMethod(\Zend\Http\Request::METHOD_POST);
41  \Magento\Newsletter\Model\Template::class
42  );
43  }
44 
48  protected function tearDown()
49  {
53  \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Backend\Model\Session::class)
54  ->destroy();
55  $this->model = null;
56  }
57 
63  {
64  $this->getRequest()->setParam('id', $this->model->getId());
65  $this->dispatch('backend/newsletter/template/save');
69  $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
73  $this->assertSessionMessages(
74  $this->equalTo(['The newsletter template has been saved.']),
75  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
76  );
77  }
78 
84  {
85  // Loading by code, since ID will vary. template_code is not actually used to load anywhere else.
86  $this->model->load('some_unique_code', 'template_code');
87 
88  // Ensure that template is actually loaded so as to prevent a false positive on saving a *new* template
89  // instead of existing one.
90  $this->assertEquals('some_unique_code', $this->model->getTemplateCode());
91 
92  $this->getRequest()->setParam('id', $this->model->getId());
93  $this->dispatch('backend/newsletter/template/save');
94 
98  $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
99 
103  $this->assertSessionMessages(
104  $this->equalTo(['The newsletter template has been saved.']),
105  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
106  );
107  }
108 
114  {
115  // Loading by code, since ID will vary. template_code is not actually used to load anywhere else.
116  $this->model->load('some_unique_code', 'template_code');
117 
118  $this->getRequest()->setParam('id', $this->model->getId());
119  $this->dispatch('backend/newsletter/template/delete');
120 
124  $this->assertSessionMessages($this->isEmpty(), \Magento\Framework\Message\MessageInterface::TYPE_ERROR);
125 
129  $this->assertSessionMessages(
130  $this->equalTo(['The newsletter template has been deleted.']),
131  \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
132  );
133  }
134 
140  {
141  // Loading by code, since ID will vary. template_code is not actually used to load anywhere else.
142  $this->model->load('some_unique_code', 'template_code');
143 
144  $this->getRequest()->setMethod(\Zend\Http\Request::METHOD_GET)->setParam('id', $this->model->getId());
145  $this->dispatch('backend/newsletter/template/save');
146 
147  $this->assertEquals(404, $this->getResponse()->getStatusCode());
148  }
149 }
assertSessionMessages(\PHPUnit\Framework\Constraint\Constraint $constraint, $messageType=null, $messageManagerClass=\Magento\Framework\Message\Manager::class)