Skip to content

Commit 545f886

Browse files
author
Gabriel Galvao da Gama
committed
Added integration tests
1 parent 8955147 commit 545f886

File tree

3 files changed

+189
-0
lines changed

3 files changed

+189
-0
lines changed

app/code/Magento/MediaContent/Model/GetAssetIdByContentFieldComposite.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function execute(string $field, string $value): array
4141
throw new InvalidArgumentException(__('The field argument is invalid.'));
4242
}
4343
$ids = [];
44+
/** @var GetAssetIdByContentFieldInterface $getAssetIdByContentField */
4445
foreach ($this->getAssetIdByContentFieldArray[$field] as $getAssetIdByContentField) {
4546
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
4647
$ids = array_merge($ids, $getAssetIdByContentField->execute($value));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaContentCatalog\Model\ResourceModel;
10+
11+
use Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test for GetAssetIdByContentFieldTest
18+
*/
19+
class GetAssetIdByContentFieldTest extends TestCase
20+
{
21+
private const STORE_FIELD = 'store_id';
22+
private const STATUS_FIELD = 'content_status';
23+
private const STATUS_ENABLED = '1';
24+
private const STATUS_DISABLED = '0';
25+
26+
/**
27+
* @var GetAssetIdByContentFieldInterface
28+
*/
29+
private $getAssetIdByContentField;
30+
31+
/**
32+
* @var int
33+
*/
34+
private $storeId;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp(): void
40+
{
41+
$objectManager = Bootstrap::getObjectManager();
42+
$this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId();
43+
$this->getAssetIdByContentField = $objectManager->get(GetAssetIdByContentFieldInterface::class);
44+
}
45+
46+
/**
47+
* Test for getting asset id by store view of a category
48+
*
49+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
50+
* @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php
51+
*/
52+
public function testCategoryStoreView(): void
53+
{
54+
$this->assertEquals(
55+
[2020],
56+
$this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId)
57+
);
58+
}
59+
60+
/**
61+
* Test for getting asset id by store view of a product
62+
*
63+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
64+
* @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php
65+
*/
66+
public function testProductStoreView(): void
67+
{
68+
$this->assertEquals(
69+
[2020],
70+
$this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId)
71+
);
72+
}
73+
74+
/**
75+
* Test for getting asset id by enabled status of a product
76+
*
77+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
78+
* @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php
79+
*/
80+
public function testProductStatusEnabled(): void
81+
{
82+
$this->assertEquals(
83+
[2020],
84+
$this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED)
85+
);
86+
}
87+
88+
/**
89+
* Test for getting asset id by disabled status of a product
90+
*
91+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
92+
* @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php
93+
*/
94+
public function testProductStatusDisabled(): void
95+
{
96+
$this->assertEquals(
97+
[],
98+
$this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED)
99+
);
100+
}
101+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Magento\MediaContentCms\Model\ResourceModel;
10+
11+
use Magento\MediaContentApi\Api\GetAssetIdByContentFieldInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Test for GetAssetIdByContentFieldTest
18+
*/
19+
class GetAssetIdByContentFieldTest extends TestCase
20+
{
21+
private const STORE_FIELD = 'store_id';
22+
private const STATUS_FIELD = 'content_status';
23+
private const STATUS_ENABLED = '1';
24+
private const STATUS_DISABLED = '0';
25+
26+
/**
27+
* @var GetAssetIdByContentFieldInterface
28+
*/
29+
private $getAssetIdByContentField;
30+
31+
/**
32+
* @var int
33+
*/
34+
private $storeId;
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
protected function setUp(): void
40+
{
41+
$objectManager = Bootstrap::getObjectManager();
42+
$this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId();
43+
$this->getAssetIdByContentField = $objectManager->get(GetAssetIdByContentFieldInterface::class);
44+
}
45+
46+
/**
47+
* Test for getting asset id by store view of a block
48+
*
49+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
50+
* @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php
51+
*/
52+
public function testBlockStoreView(): void
53+
{
54+
$this->assertEquals(
55+
[2020],
56+
$this->getAssetIdByContentField->execute(self::STORE_FIELD, (string)$this->storeId)
57+
);
58+
}
59+
60+
/**
61+
* Test for getting asset id by enabled status of a page
62+
*
63+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
64+
* @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
65+
*/
66+
public function testPageStatusEnabled(): void
67+
{
68+
$this->assertEquals(
69+
[2020],
70+
$this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED)
71+
);
72+
}
73+
74+
/**
75+
* Test for getting asset id by disabled status of a page
76+
*
77+
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
78+
* @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
79+
*/
80+
public function testPageStatusDisabled(): void
81+
{
82+
$this->assertEquals(
83+
[],
84+
$this->getAssetIdByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED)
85+
);
86+
}
87+
}

0 commit comments

Comments
 (0)