|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\CmsUrlRewrite\Test\Unit\Plugin\Cms\Model\Resource; |
| 7 | + |
| 8 | +use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; |
| 9 | +use Magento\CmsUrlRewrite\Model\CmsPageUrlRewriteGenerator; |
| 10 | + |
| 11 | +class PageTest extends \PHPUnit_Framework_TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Magento\CmsUrlRewrite\Plugin\Cms\Model\Resource\Page |
| 15 | + */ |
| 16 | + protected $pageObject; |
| 17 | + |
| 18 | + /** |
| 19 | + * @var \Magento\UrlRewrite\Model\UrlPersistInterface|\PHPUnit_Framework_MockObject_MockObject |
| 20 | + */ |
| 21 | + protected $urlPersistMock; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var \Magento\Cms\Model\Page|\PHPUnit_Framework_MockObject_MockObject |
| 25 | + */ |
| 26 | + protected $cmsPageMock; |
| 27 | + |
| 28 | + /** |
| 29 | + * @var \Magento\Cms\Model\Resource\Page|\PHPUnit_Framework_MockObject_MockObject |
| 30 | + */ |
| 31 | + protected $cmsPageResourceMock; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var \Closure |
| 35 | + */ |
| 36 | + protected $closureMock; |
| 37 | + |
| 38 | + public function setUp() |
| 39 | + { |
| 40 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 41 | + |
| 42 | + $this->closureMock = function () { |
| 43 | + return 'URL Rewrite Result'; |
| 44 | + }; |
| 45 | + |
| 46 | + $this->urlPersistMock = $this->getMockBuilder('Magento\UrlRewrite\Model\UrlPersistInterface') |
| 47 | + ->getMockForAbstractClass(); |
| 48 | + |
| 49 | + $this->cmsPageMock = $this->getMockBuilder('Magento\Cms\Model\Page') |
| 50 | + ->disableOriginalConstructor() |
| 51 | + ->getMock(); |
| 52 | + |
| 53 | + $this->cmsPageResourceMock = $this->getMockBuilder('Magento\Cms\Model\Resource\Page') |
| 54 | + ->disableOriginalConstructor() |
| 55 | + ->getMock(); |
| 56 | + |
| 57 | + $this->pageObject = $objectManager->getObject( |
| 58 | + 'Magento\CmsUrlRewrite\Plugin\Cms\Model\Resource\Page', |
| 59 | + [ |
| 60 | + 'urlPersist' => $this->urlPersistMock |
| 61 | + ] |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + public function testAroundDeletePositive() |
| 66 | + { |
| 67 | + $productId = 100; |
| 68 | + |
| 69 | + $this->cmsPageMock->expects($this->once()) |
| 70 | + ->method('getId') |
| 71 | + ->willReturn($productId); |
| 72 | + |
| 73 | + $this->cmsPageMock->expects($this->once()) |
| 74 | + ->method('isDeleted') |
| 75 | + ->willReturn(true); |
| 76 | + |
| 77 | + $this->urlPersistMock->expects($this->once()) |
| 78 | + ->method('deleteByData') |
| 79 | + ->with( |
| 80 | + [ |
| 81 | + UrlRewrite::ENTITY_ID => $productId, |
| 82 | + UrlRewrite::ENTITY_TYPE => CmsPageUrlRewriteGenerator::ENTITY_TYPE |
| 83 | + ] |
| 84 | + ); |
| 85 | + |
| 86 | + $this->assertEquals( |
| 87 | + 'URL Rewrite Result', |
| 88 | + $this->pageObject->aroundDelete( |
| 89 | + $this->cmsPageResourceMock, |
| 90 | + $this->closureMock, |
| 91 | + $this->cmsPageMock |
| 92 | + ) |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + public function testAroundDeleteNegative() |
| 97 | + { |
| 98 | + $this->cmsPageMock->expects($this->once()) |
| 99 | + ->method('isDeleted') |
| 100 | + ->willReturn(false); |
| 101 | + |
| 102 | + $this->urlPersistMock->expects($this->never()) |
| 103 | + ->method('deleteByData'); |
| 104 | + |
| 105 | + $this->assertEquals( |
| 106 | + 'URL Rewrite Result', |
| 107 | + $this->pageObject->aroundDelete( |
| 108 | + $this->cmsPageResourceMock, |
| 109 | + $this->closureMock, |
| 110 | + $this->cmsPageMock |
| 111 | + ) |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
0 commit comments