|
7 | 7 |
|
8 | 8 | namespace Magento\Sales\Controller\Guest;
|
9 | 9 |
|
| 10 | +use Magento\Framework\Stdlib\CookieManagerInterface; |
| 11 | +use Magento\Sales\Api\Data\OrderInterfaceFactory; |
| 12 | +use Magento\Sales\Api\OrderRepositoryInterface; |
10 | 13 | use Magento\TestFramework\Request;
|
11 | 14 | use Magento\TestFramework\TestCase\AbstractController;
|
12 | 15 |
|
13 | 16 | /**
|
14 |
| - * Test for \Magento\Sales\Controller\Guest\View class. |
| 17 | + * Test for orders and returns controller. |
| 18 | + * |
| 19 | + * @see \Magento\Sales\Controller\Guest\View |
15 | 20 | */
|
16 | 21 | class ViewTest extends AbstractController
|
17 | 22 | {
|
| 23 | + /** @var CookieManagerInterface */ |
| 24 | + private $cookieManager; |
| 25 | + |
| 26 | + /** @var OrderInterfaceFactory */ |
| 27 | + private $orderFactory; |
| 28 | + |
| 29 | + /** @var OrderRepositoryInterface */ |
| 30 | + private $orderRepository; |
| 31 | + |
| 32 | + /** |
| 33 | + * @inheritdoc |
| 34 | + */ |
| 35 | + protected function setUp(): void |
| 36 | + { |
| 37 | + parent::setUp(); |
| 38 | + |
| 39 | + $this->cookieManager = $this->_objectManager->get(CookieManagerInterface::class); |
| 40 | + $this->orderFactory = $this->_objectManager->get(OrderInterfaceFactory::class); |
| 41 | + $this->orderRepository = $this->_objectManager->get(OrderRepositoryInterface::class); |
| 42 | + } |
| 43 | + |
18 | 44 | /**
|
19 | 45 | * Check that controller applied GET requests.
|
| 46 | + * |
| 47 | + * @return void |
20 | 48 | */
|
21 |
| - public function testExecuteWithGetRequest() |
| 49 | + public function testExecuteWithGetRequest(): void |
22 | 50 | {
|
23 | 51 | $this->getRequest()->setMethod(Request::METHOD_GET);
|
24 | 52 | $this->dispatch('sales/guest/view/');
|
25 | 53 |
|
26 | 54 | $this->assertRedirect($this->stringContains('sales/guest/form'));
|
27 | 55 | }
|
| 56 | + |
| 57 | + /** |
| 58 | + * @magentoDataFixture Magento/Sales/_files/order.php |
| 59 | + * |
| 60 | + * @return void |
| 61 | + */ |
| 62 | + public function testExecuteWithWrongCookie(): void |
| 63 | + { |
| 64 | + $order = $this->orderFactory->create()->loadByIncrementId('100000001'); |
| 65 | + $order->setProtectCode('0e6640'); |
| 66 | + $this->orderRepository->save($order); |
| 67 | + $cookieValue = base64_encode('0' . ':' . $order->getIncrementId()); |
| 68 | + $this->cookieManager->setPublicCookie(\Magento\Sales\Helper\Guest::COOKIE_NAME, $cookieValue); |
| 69 | + $this->getRequest()->setMethod(Request::METHOD_GET); |
| 70 | + $this->dispatch('sales/guest/view/'); |
| 71 | + $this->assertRedirect($this->stringContains('sales/guest/form/')); |
| 72 | + $this->assertSessionMessages( |
| 73 | + $this->containsEqual((string)__('You entered incorrect data. Please try again.')) |
| 74 | + ); |
| 75 | + } |
28 | 76 | }
|
0 commit comments