Skip to content

Commit f63761f

Browse files
committed
Cover changes with integration tests
1 parent 7d69498 commit f63761f

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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\MediaGallery\Model\ResourceModel;
9+
10+
use Magento\Framework\Api\FilterBuilder;
11+
use Magento\Framework\Api\Search\FilterGroupBuilder;
12+
use Magento\Framework\Api\SearchCriteriaBuilder;
13+
use Magento\MediaGalleryApi\Api\SearchAssetsInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Verify SearchAssets By searchCriteria
19+
*/
20+
class SearchAssetsTest extends TestCase
21+
{
22+
private const FIXTURE_ASSET_PATH = 'testDirectory/path.jpg';
23+
24+
/**
25+
* @var SearchAssetsInterfcae
26+
*/
27+
private $searchAssets;
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
protected function setUp(): void
33+
{
34+
$this->filterBuilder = Bootstrap::getObjectManager()->get(FilterBuilder::class);
35+
$this->filterGroupBuilder = Bootstrap::getObjectManager()->get(FilterGroupBuilder::class);
36+
$this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
37+
$this->searchAssets = Bootstrap::getObjectManager()->get(SearchAssetsInterface::class);
38+
}
39+
40+
/**
41+
* Verify search asstes by searching with search criteria
42+
*
43+
* @dataProvider searchCriteriaProvider
44+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
45+
*/
46+
public function testExecute(array $searchCriteriaData): void
47+
{
48+
$titleFilter = $this->filterBuilder->setField($searchCriteriaData['field'])
49+
->setConditionType($searchCriteriaData['conditionType'])
50+
->setValue($searchCriteriaData['value'])
51+
->create();
52+
$searchCriteria = $this->searchCriteriaBuilder
53+
->setFilterGroups([$this->filterGroupBuilder->setFilters([$titleFilter])->create()])
54+
->create();
55+
56+
$assets = $this->searchAssets->execute($searchCriteria);
57+
58+
$this->assertCount(1, $assets);
59+
$this->assertEquals($assets[0]->getPath(), self::FIXTURE_ASSET_PATH);
60+
}
61+
62+
/**
63+
* Search criteria params provider
64+
*
65+
* @return array
66+
*/
67+
public function searchCriteriaProvider(): array
68+
{
69+
return [
70+
[
71+
['field' => 'id', 'conditionType' => 'eq', 'value' => 2020],
72+
],
73+
[
74+
['field' => 'title', 'conditionType' => 'fulltext', 'value' => 'Img'],
75+
],
76+
[
77+
['field' => 'content_type', 'conditionType' => 'eq', 'value' => 'image']
78+
],
79+
[
80+
['field' => 'description', 'conditionType' => 'fulltext', 'value' => 'description']
81+
]
82+
];
83+
}
84+
}

dev/tests/integration/testsuite/Magento/MediaGallery/_files/media_asset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
[
1919
'id' => 2020,
2020
'path' => 'testDirectory/path.jpg',
21+
'description' => 'Description of an image',
2122
'contentType' => 'image',
2223
'title' => 'Img',
2324
'source' => 'Local',

0 commit comments

Comments
 (0)