|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Newsletter\Controller; |
| 8 | + |
| 9 | +use Magento\TestFramework\TestCase\AbstractController; |
| 10 | + |
| 11 | +/** |
| 12 | + * Test Unsubscriber controller |
| 13 | + * |
| 14 | + * @magentoDataFixture Magento/Newsletter/_files/subscribers.php |
| 15 | + * @magentoAppArea frontend |
| 16 | + */ |
| 17 | +class UnSubscriberTest extends AbstractController |
| 18 | +{ |
| 19 | + |
| 20 | + /** |
| 21 | + * @var Subscriber |
| 22 | + */ |
| 23 | + private $model; |
| 24 | + |
| 25 | + protected function setUp() |
| 26 | + { |
| 27 | + $this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( |
| 28 | + \Magento\Newsletter\Model\Subscriber::class |
| 29 | + ); |
| 30 | + parent::setUp(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @return void |
| 35 | + */ |
| 36 | + public function testSuccessUnsubscribeSubscribedUser() |
| 37 | + { |
| 38 | + $subscriber = $this->model->loadByCustomerId(1); |
| 39 | + $this->getRequest() |
| 40 | + ->setParam('id', $subscriber->getId()) |
| 41 | + ->setParam('code', 'zxayquyajua23iq29gxwu2eax2qb6gvy'); |
| 42 | + |
| 43 | + $this->dispatch('newsletter/subscriber/unsubscribe'); |
| 44 | + |
| 45 | + $this->assertSessionMessages($this->equalTo(['You unsubscribed.'])); |
| 46 | + $this->assertRedirect($this->anything()); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @return void |
| 51 | + */ |
| 52 | + public function testFailureUnsubscribeSubscribedUser() |
| 53 | + { |
| 54 | + $subscriber = $this->model->loadByCustomerId(1); |
| 55 | + $this->getRequest() |
| 56 | + ->setParam('id', $subscriber->getId()) |
| 57 | + ->setParam('code', 'randomcode'); |
| 58 | + |
| 59 | + $this->dispatch('newsletter/subscriber/unsubscribe'); |
| 60 | + |
| 61 | + $this->assertSessionMessages($this->equalTo(['This is an invalid subscription confirmation code.'])); |
| 62 | + $this->assertRedirect($this->anything()); |
| 63 | + } |
| 64 | +} |
0 commit comments