Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProductUrlRewriteDatabaseMapTest.php
Go to the documentation of this file.
1 <?php
7 
16 
20 class DataProductUrlRewriteDatabaseMapTest extends \PHPUnit\Framework\TestCase
21 {
23  private $hashMapPoolMock;
24 
26  private $dataProductMapMock;
27 
29  private $temporaryTableServiceMock;
30 
32  private $connectionMock;
33 
35  private $model;
36 
37  protected function setUp()
38  {
39  $this->hashMapPoolMock = $this->createMock(HashMapPool::class);
40  $this->dataProductMapMock = $this->createMock(DataProductHashMap::class);
41  $this->temporaryTableServiceMock = $this->createMock(TemporaryTableService::class);
42  $this->connectionMock = $this->createMock(ResourceConnection::class);
43 
44  $this->hashMapPoolMock->expects($this->any())
45  ->method('getDataMap')
46  ->willReturn($this->dataProductMapMock);
47 
48  $this->model = (new ObjectManager($this))->getObject(
49  DataProductUrlRewriteDatabaseMap::class,
50  [
51  'connection' => $this->connectionMock,
52  'hashMapPool' => $this->hashMapPoolMock,
53  'temporaryTableService' => $this->temporaryTableServiceMock
54  ]
55  );
56  }
57 
61  public function testGetAllData()
62  {
63  $productStoreIds = [
64  '1' => ['store_id' => 1, 'product_id' => 1],
65  '2' => ['store_id' => 2, 'product_id' => 1],
66  '3' => ['store_id' => 3, 'product_id' => 1],
67  '4' => ['store_id' => 1, 'product_id' => 2],
68  '5' => ['store_id' => 2, 'product_id' => 2],
69  ];
70 
71  $connectionMock = $this->createMock(AdapterInterface::class);
72  $selectMock = $this->createMock(Select::class);
73 
74  $this->connectionMock->expects($this->any())
75  ->method('getConnection')
76  ->willReturn($connectionMock);
77  $connectionMock->expects($this->any())
78  ->method('select')
79  ->willReturn($selectMock);
80  $connectionMock->expects($this->any())
81  ->method('fetchAll')
82  ->willReturn($productStoreIds[3]);
83  $selectMock->expects($this->any())
84  ->method('from')
85  ->willReturnSelf();
86  $selectMock->expects($this->any())
87  ->method('joinInner')
88  ->willReturnSelf();
89  $selectMock->expects($this->any())
90  ->method('where')
91  ->willReturnSelf();
92 
93  $this->dataProductMapMock->expects($this->any())
94  ->method('getAllData')
95  ->willReturn([]);
96 
97  $this->temporaryTableServiceMock->expects($this->any())
98  ->method('createFromSelect')
99  ->withConsecutive(
100  $selectMock,
101  $connectionMock,
102  [
103  'PRIMARY' => ['url_rewrite_id'],
104  'HASHKEY_ENTITY_STORE' => ['hash_key'],
105  'ENTITY_STORE' => ['entity_id', 'store_id']
106  ]
107  )
108  ->willReturn('tempTableName');
109 
110  $this->assertEquals($productStoreIds[3], $this->model->getData(1, '3_1'));
111  }
112 }