|
1 |
| -<?php |
2 |
| - |
3 |
| -/** |
4 |
| - * Copyright © 2015 Magento. All rights reserved. |
5 |
| - * See COPYING.txt for license details. |
6 |
| - */ |
7 |
| - |
8 |
| -namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Product\Plugin; |
9 |
| - |
10 |
| -use Magento\ImportExport\Model\Import as ImportExport; |
11 |
| -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
12 |
| - |
13 |
| -class ImportTest extends \PHPUnit_Framework_TestCase |
14 |
| -{ |
15 |
| - |
16 |
| - /** |
17 |
| - * @var \Magento\UrlRewrite\Model\UrlPersistInterface|\PHPUnit_Framework_MockObject_MockObject |
18 |
| - */ |
19 |
| - protected $urlPersist; |
20 |
| - |
21 |
| - /** |
22 |
| - * @var \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator|\PHPUnit_Framework_MockObject_MockObject |
23 |
| - */ |
24 |
| - protected $productUrlRewriteGenerator; |
25 |
| - |
26 |
| - /** |
27 |
| - * @var \Magento\Catalog\Api\ProductRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
28 |
| - */ |
29 |
| - protected $productRepository; |
30 |
| - |
31 |
| - /** |
32 |
| - * @var \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import|\PHPUnit_Framework_MockObject_MockObject |
33 |
| - */ |
34 |
| - protected $import; |
35 |
| - |
36 |
| - /** |
37 |
| - * @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject |
38 |
| - */ |
39 |
| - protected $observer; |
40 |
| - |
41 |
| - /** |
42 |
| - * @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject |
43 |
| - */ |
44 |
| - protected $event; |
45 |
| - |
46 |
| - /** |
47 |
| - * @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject |
48 |
| - */ |
49 |
| - protected $adapter; |
50 |
| - |
51 |
| - /** |
52 |
| - * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject |
53 |
| - */ |
54 |
| - protected $object; |
55 |
| - |
56 |
| - /** |
57 |
| - * @var ObjectManagerHelper |
58 |
| - */ |
59 |
| - protected $objectManagerHelper; |
60 |
| - |
61 |
| - public function setUp() |
62 |
| - { |
63 |
| - $this->object = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false); |
64 |
| - $this->adapter = $this->getMock( |
65 |
| - 'Magento\Framework\DB\Adapter\Pdo\Mysql', |
66 |
| - ['getOldSku', '_populateToUrlGeneration'], |
67 |
| - [], |
68 |
| - '', |
69 |
| - false |
70 |
| - ); |
71 |
| - $this->adapter->expects($this->any())->method('_populateToUrlGeneration')->willReturn($this->object); |
72 |
| - $this->adapter->expects($this->any())->method('getOldSku')->willReturn([ |
73 |
| - 'sku' => ['sku' => 'sku', 'url_key' => 'value1', 'entity_id' => '1'], |
74 |
| - 'sku2' => ['sku' => 'sku2', 'url_key' => 'value2', 'entity_id' => '2'] |
75 |
| - ]); |
76 |
| - $this->event = $this->getMock('\Magento\Framework\Event', ['getAdapter', 'getBunch'], [], '', false); |
77 |
| - $this->event->expects($this->any())->method('getAdapter')->willReturn($this->adapter); |
78 |
| - $this->event->expects($this->any())->method('getBunch')->willReturn([ |
79 |
| - ['sku' => 'sku', 'url_key' => 'value1'], ['sku' => 'sku3', 'url_key' => 'value3'] |
80 |
| - ]); |
81 |
| - $this->observer = $this->getMock('\Magento\Framework\Event\Observer', ['getEvent'], [], '', false); |
82 |
| - $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event); |
83 |
| - $this->urlPersist = $this->getMockBuilder('\Magento\UrlRewrite\Model\UrlPersistInterface') |
84 |
| - ->disableOriginalConstructor() |
85 |
| - ->getMock(); |
86 |
| - $this->productUrlRewriteGenerator = |
87 |
| - $this->getMockBuilder('\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator') |
88 |
| - ->disableOriginalConstructor() |
89 |
| - ->setMethods(['generate']) |
90 |
| - ->getMock(); |
91 |
| - $this->productRepository = $this->getMockBuilder('\Magento\Catalog\Api\ProductRepositoryInterface') |
92 |
| - ->disableOriginalConstructor() |
93 |
| - ->getMock(); |
94 |
| - $this->objectManagerHelper = new ObjectManagerHelper($this); |
95 |
| - $this->import = $this->objectManagerHelper->getObject( |
96 |
| - '\Magento\CatalogUrlRewrite\Model\Product\Plugin\Import', |
97 |
| - [ |
98 |
| - 'urlPersist' => $this->urlPersist, |
99 |
| - 'productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, |
100 |
| - 'productRepository' => $this->productRepository, |
101 |
| - ] |
102 |
| - ); |
103 |
| - } |
104 |
| - |
105 |
| - /** |
106 |
| - * Test for afterImportData() |
107 |
| - */ |
108 |
| - public function testAfterImportData() |
109 |
| - { |
110 |
| - $this->productUrlRewriteGenerator->expects($this->any())->method('generate')->willReturn(['url1', 'url2']); |
111 |
| - $this->import->afterImportData($this->observer); |
112 |
| - } |
113 |
| - |
114 |
| - /** |
115 |
| - * Test for clearProductUrls() |
116 |
| - */ |
117 |
| - public function testClearProductUrls() |
118 |
| - { |
119 |
| - $this->import->clearProductUrls($this->observer); |
120 |
| - } |
121 |
| -} |
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright © 2015 Magento. All rights reserved. |
| 5 | + * See COPYING.txt for license details. |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Product\Plugin; |
| 9 | + |
| 10 | +use Magento\ImportExport\Model\Import as ImportExport; |
| 11 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 12 | + |
| 13 | +class ImportTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + |
| 16 | + /** |
| 17 | + * @var \Magento\UrlRewrite\Model\UrlPersistInterface|\PHPUnit_Framework_MockObject_MockObject |
| 18 | + */ |
| 19 | + protected $urlPersist; |
| 20 | + |
| 21 | + /** |
| 22 | + * @var \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator|\PHPUnit_Framework_MockObject_MockObject |
| 23 | + */ |
| 24 | + protected $productUrlRewriteGenerator; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var \Magento\Catalog\Api\ProductRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + protected $productRepository; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var \Magento\CatalogUrlRewrite\Model\Product\Plugin\Import|\PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + protected $import; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject |
| 38 | + */ |
| 39 | + protected $observer; |
| 40 | + |
| 41 | + /** |
| 42 | + * @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject |
| 43 | + */ |
| 44 | + protected $event; |
| 45 | + |
| 46 | + /** |
| 47 | + * @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject |
| 48 | + */ |
| 49 | + protected $adapter; |
| 50 | + |
| 51 | + /** |
| 52 | + * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject |
| 53 | + */ |
| 54 | + protected $object; |
| 55 | + |
| 56 | + /** |
| 57 | + * @var ObjectManagerHelper |
| 58 | + */ |
| 59 | + protected $objectManagerHelper; |
| 60 | + |
| 61 | + public function setUp() |
| 62 | + { |
| 63 | + $this->object = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false); |
| 64 | + $this->adapter = $this->getMock( |
| 65 | + 'Magento\Framework\DB\Adapter\Pdo\Mysql', |
| 66 | + ['getOldSku', '_populateToUrlGeneration'], |
| 67 | + [], |
| 68 | + '', |
| 69 | + false |
| 70 | + ); |
| 71 | + $this->adapter->expects($this->any())->method('_populateToUrlGeneration')->willReturn($this->object); |
| 72 | + $this->adapter->expects($this->any())->method('getOldSku')->willReturn([ |
| 73 | + 'sku' => ['sku' => 'sku', 'url_key' => 'value1', 'entity_id' => '1'], |
| 74 | + 'sku2' => ['sku' => 'sku2', 'url_key' => 'value2', 'entity_id' => '2'] |
| 75 | + ]); |
| 76 | + $this->event = $this->getMock('\Magento\Framework\Event', ['getAdapter', 'getBunch'], [], '', false); |
| 77 | + $this->event->expects($this->any())->method('getAdapter')->willReturn($this->adapter); |
| 78 | + $this->event->expects($this->any())->method('getBunch')->willReturn([ |
| 79 | + ['sku' => 'sku', 'url_key' => 'value1'], ['sku' => 'sku3', 'url_key' => 'value3'] |
| 80 | + ]); |
| 81 | + $this->observer = $this->getMock('\Magento\Framework\Event\Observer', ['getEvent'], [], '', false); |
| 82 | + $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event); |
| 83 | + $this->urlPersist = $this->getMockBuilder('\Magento\UrlRewrite\Model\UrlPersistInterface') |
| 84 | + ->disableOriginalConstructor() |
| 85 | + ->getMock(); |
| 86 | + $this->productUrlRewriteGenerator = |
| 87 | + $this->getMockBuilder('\Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator') |
| 88 | + ->disableOriginalConstructor() |
| 89 | + ->setMethods(['generate']) |
| 90 | + ->getMock(); |
| 91 | + $this->productRepository = $this->getMockBuilder('\Magento\Catalog\Api\ProductRepositoryInterface') |
| 92 | + ->disableOriginalConstructor() |
| 93 | + ->getMock(); |
| 94 | + $this->objectManagerHelper = new ObjectManagerHelper($this); |
| 95 | + $this->import = $this->objectManagerHelper->getObject( |
| 96 | + '\Magento\CatalogUrlRewrite\Model\Product\Plugin\Import', |
| 97 | + [ |
| 98 | + 'urlPersist' => $this->urlPersist, |
| 99 | + 'productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, |
| 100 | + 'productRepository' => $this->productRepository, |
| 101 | + ] |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Test for afterImportData() |
| 107 | + */ |
| 108 | + public function testAfterImportData() |
| 109 | + { |
| 110 | + $this->productUrlRewriteGenerator->expects($this->any())->method('generate')->willReturn(['url1', 'url2']); |
| 111 | + $this->import->afterImportData($this->observer); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Test for clearProductUrls() |
| 116 | + */ |
| 117 | + public function testClearProductUrls() |
| 118 | + { |
| 119 | + $this->import->clearProductUrls($this->observer); |
| 120 | + } |
| 121 | +} |
0 commit comments