|
8 | 8 |
|
9 | 9 | namespace Magento\MediaContentCms\Model\ResourceModel;
|
10 | 10 |
|
| 11 | +use Magento\Framework\Exception\InvalidArgumentException; |
11 | 12 | use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface;
|
12 |
| -use Magento\Store\Model\StoreManagerInterface; |
13 | 13 | use Magento\TestFramework\Helper\Bootstrap;
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 |
|
16 | 16 | /**
|
17 |
| - * Test for GetAssetIdByContentFieldTest |
| 17 | + * Test for GetAssetIdsByContentFieldTest |
18 | 18 | */
|
19 | 19 | class GetAssetIdsByContentFieldTest extends TestCase
|
20 | 20 | {
|
21 | 21 | private const STORE_FIELD = 'store_id';
|
22 | 22 | private const STATUS_FIELD = 'content_status';
|
23 | 23 | private const STATUS_ENABLED = '1';
|
24 | 24 | private const STATUS_DISABLED = '0';
|
| 25 | + private const FIXTURE_ASSET_ID = 2020; |
| 26 | + private const DEFAULT_STORE_ID = '1'; |
| 27 | + private const ADMIN_STORE_ID = '0'; |
25 | 28 |
|
26 | 29 | /**
|
27 | 30 | * @var GetAssetIdsByContentFieldInterface
|
28 | 31 | */
|
29 | 32 | private $getAssetIdsByContentField;
|
30 | 33 |
|
31 |
| - /** |
32 |
| - * @var int |
33 |
| - */ |
34 |
| - private $storeId; |
35 |
| - |
36 | 34 | /**
|
37 | 35 | * @inheritdoc
|
38 | 36 | */
|
39 | 37 | protected function setUp(): void
|
40 | 38 | {
|
41 | 39 | $objectManager = Bootstrap::getObjectManager();
|
42 |
| - $this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId(); |
43 | 40 | $this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class);
|
44 | 41 | }
|
45 | 42 |
|
46 | 43 | /**
|
47 |
| - * Test for getting asset id by store view of a block |
| 44 | + * Test for getting asset id by block field |
48 | 45 | *
|
| 46 | + * @dataProvider testBlockDataProvider |
49 | 47 | * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
|
50 | 48 | * @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php
|
| 49 | + * |
| 50 | + * @param string $field |
| 51 | + * @param string $value |
| 52 | + * @param array $expectedAssetIds |
| 53 | + * @throws InvalidArgumentException |
51 | 54 | */
|
52 |
| - public function testBlockStoreView(): void |
| 55 | + public function testBlockFields(string $field, string $value, array $expectedAssetIds): void |
53 | 56 | {
|
54 | 57 | $this->assertEquals(
|
55 |
| - [2020], |
56 |
| - $this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId) |
| 58 | + $expectedAssetIds, |
| 59 | + $this->getAssetIdsByContentField->execute($field, $value) |
57 | 60 | );
|
58 | 61 | }
|
59 | 62 |
|
60 | 63 | /**
|
61 |
| - * Test for getting asset id by enabled status of a page |
| 64 | + * Test for getting asset id by page field |
62 | 65 | *
|
| 66 | + * @dataProvider testPageDataProvider |
63 | 67 | * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
|
64 | 68 | * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
|
| 69 | + * |
| 70 | + * @param string $field |
| 71 | + * @param string $value |
| 72 | + * @param array $expectedAssetIds |
| 73 | + * @throws InvalidArgumentException |
65 | 74 | */
|
66 |
| - public function testPageStatusEnabled(): void |
| 75 | + public function testPageFields(string $field, string $value, array $expectedAssetIds): void |
67 | 76 | {
|
68 | 77 | $this->assertEquals(
|
69 |
| - [2020], |
70 |
| - $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) |
| 78 | + $expectedAssetIds, |
| 79 | + $this->getAssetIdsByContentField->execute($field, $value) |
71 | 80 | );
|
72 | 81 | }
|
73 | 82 |
|
74 | 83 | /**
|
75 |
| - * Test for getting asset id by disabled status of a page |
| 84 | + * Data provider for block tests |
76 | 85 | *
|
77 |
| - * @magentoDataFixture Magento/MediaGallery/_files/media_asset.php |
78 |
| - * @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php |
| 86 | + * @return array |
79 | 87 | */
|
80 |
| - public function testPageStatusDisabled(): void |
| 88 | + public static function testBlockDataProvider(): array |
81 | 89 | {
|
82 |
| - $this->assertEquals( |
83 |
| - [], |
84 |
| - $this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED) |
85 |
| - ); |
| 90 | + return [ |
| 91 | + [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], |
| 92 | + [self::STATUS_FIELD, self::STATUS_DISABLED, []], |
| 93 | + [self::STORE_FIELD, self::DEFAULT_STORE_ID, [self::FIXTURE_ASSET_ID]], |
| 94 | + ]; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Data provider for page tests |
| 99 | + * |
| 100 | + * @return array |
| 101 | + */ |
| 102 | + public static function testPageDataProvider(): array |
| 103 | + { |
| 104 | + return [ |
| 105 | + [self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], |
| 106 | + [self::STATUS_FIELD, self::STATUS_DISABLED, []], |
| 107 | + [self::STORE_FIELD, self::ADMIN_STORE_ID, [self::FIXTURE_ASSET_ID]], |
| 108 | + ]; |
86 | 109 | }
|
87 | 110 | }
|
0 commit comments