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