Skip to content

Commit a50b7df

Browse files
committed
ACP2E-1840: added unit tests
1 parent 18800f0 commit a50b7df

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed

app/code/Magento/Cms/Model/ResourceModel/Page/Query/PageIdsList.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ public function execute(array $ids = []): array
6060
if (count($ids)) {
6161
foreach ($ids as $id) {
6262
$select->orWhere(
63-
"MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('block_id=\"$id\"')"
63+
"MATCH (title, meta_keywords, meta_description, identifier, content)
64+
AGAINST ('block_id=\"$id\"')"
6465
);
6566
}
6667
$identifiers = $this->getBlockIdentifiersByIds($ids);
6768
foreach ($identifiers as $identifier) {
6869
$select->orWhere(
69-
"MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('block_id=\"$identifier\"')"
70+
"MATCH (title, meta_keywords, meta_description, identifier, content)
71+
AGAINST ('block_id=\"$identifier\"')"
7072
);
7173
}
7274
} else {
73-
$select->where("MATCH (title, meta_keywords, meta_description, identifier, content) AGAINST ('block_id=')");
75+
$select->where("MATCH (title, meta_keywords, meta_description, identifier, content)
76+
AGAINST ('block_id=')");
7477
}
7578

7679
return $this->connection->fetchCol($select);
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Cms\Test\Unit\Model\ResourceModel\Page\Query;
9+
10+
use Magento\Cms\Model\ResourceModel\Page\Query\PageIdsList;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DB\Adapter\AdapterInterface;
13+
use Magento\Framework\DB\Select;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class PageIdsListTest extends TestCase
18+
{
19+
20+
/**
21+
* @var ResourceConnection|MockObject
22+
*/
23+
private $resourceMock;
24+
25+
/**
26+
* @var AdapterInterface|MockObject
27+
*/
28+
private $connectionMock;
29+
30+
/**
31+
* @var Select|MockObject
32+
*/
33+
private $selectMock;
34+
35+
protected function setUp(): void
36+
{
37+
$this->resourceMock = $this->createMock(ResourceConnection::class);
38+
$this->selectMock = $this->createMock(Select::class);
39+
$this->connectionMock = $this->createMock(AdapterInterface::class);
40+
}
41+
42+
/**
43+
* @param $blockEntityIds
44+
* @param $pageEntityIds
45+
* @param $blockIdentifiers
46+
* @dataProvider getDataProvider
47+
*/
48+
public function testExecute($blockEntityIds, $pageEntityIds, $blockIdentifiers)
49+
{
50+
$this->selectMock->expects($this->any())
51+
->method('from')
52+
->willReturnSelf();
53+
if (count($blockEntityIds)) {
54+
$this->resourceMock->expects($this->any())
55+
->method('getTableName')
56+
->willReturnOnConsecutiveCalls('cms_page', 'cms_block');
57+
$this->selectMock->expects($this->any())
58+
->method('orWhere')
59+
->willReturnSelf();
60+
61+
$this->connectionMock->expects($this->exactly(2))
62+
->method('fetchCol')
63+
->willReturnOnConsecutiveCalls($blockIdentifiers, $pageEntityIds);
64+
65+
$this->connectionMock->expects($this->exactly(2))
66+
->method('select')
67+
->willReturn($this->selectMock);
68+
} else {
69+
$this->connectionMock->expects($this->once())
70+
->method('select')
71+
->willReturn($this->selectMock);
72+
$this->selectMock->expects($this->any())
73+
->method('where')
74+
->willReturnSelf();
75+
$this->connectionMock->expects($this->once())
76+
->method('fetchCol')
77+
->willReturn($pageEntityIds);
78+
}
79+
$this->resourceMock->expects($this->any())
80+
->method('getConnection')
81+
->with()
82+
->willReturn($this->connectionMock);
83+
84+
$this->pageIdsList = new PageIdsList(
85+
$this->resourceMock
86+
);
87+
88+
$this->assertSame($pageEntityIds, $this->pageIdsList->execute($blockEntityIds));
89+
}
90+
91+
/**
92+
* Execute data provider
93+
*
94+
* @return array
95+
*/
96+
public function getDataProvider(): array
97+
{
98+
return [
99+
[[1, 2, 3], [1], ['test1', 'test2', 'test3']],
100+
[[1, 2, 3], [], []],
101+
[[], [], []]
102+
];
103+
}
104+
}

0 commit comments

Comments
 (0)