Skip to content

Commit 752eb5a

Browse files
author
Gabriel Galvao da Gama
committed
Added data provider to tests
1 parent aa11cf5 commit 752eb5a

File tree

2 files changed

+77
-62
lines changed

2 files changed

+77
-62
lines changed

dev/tests/integration/testsuite/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByContentFieldTest.php

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,94 +8,86 @@
88

99
namespace Magento\MediaContentCatalog\Model\ResourceModel;
1010

11+
use Magento\Framework\Exception\InvalidArgumentException;
1112
use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface;
12-
use Magento\Store\Model\StoreManagerInterface;
1313
use Magento\TestFramework\Helper\Bootstrap;
1414
use PHPUnit\Framework\TestCase;
1515

1616
/**
17-
* Test for GetAssetIdByContentFieldTest
17+
* Test for GetAssetIdsByContentFieldTest
1818
*/
1919
class GetAssetIdsByContentFieldTest extends TestCase
2020
{
2121
private const STORE_FIELD = 'store_id';
2222
private const STATUS_FIELD = 'content_status';
2323
private const STATUS_ENABLED = '1';
2424
private const STATUS_DISABLED = '0';
25+
private const FIXTURE_ASSET_ID = 2020;
26+
private const DEFAULT_STORE_ID = '1';
2527

2628
/**
2729
* @var GetAssetIdsByContentFieldInterface
2830
*/
2931
private $getAssetIdsByContentField;
3032

31-
/**
32-
* @var int
33-
*/
34-
private $storeId;
35-
3633
/**
3734
* @inheritdoc
3835
*/
3936
protected function setUp(): void
4037
{
4138
$objectManager = Bootstrap::getObjectManager();
42-
$this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId();
4339
$this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class);
4440
}
4541

4642
/**
47-
* Test for getting asset id by store view of a category
43+
* Test for getting asset id by category fields
4844
*
45+
* @dataProvider testProvider
4946
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
5047
* @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php
48+
* @param string $field
49+
* @param string $value
50+
* @param array $expectedAssetIds
51+
* @throws InvalidArgumentException
5152
*/
52-
public function testCategoryStoreView(): void
53+
public function testCategoryFields(string $field, string $value, array $expectedAssetIds): void
5354
{
5455
$this->assertEquals(
55-
[2020],
56-
$this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId)
56+
$expectedAssetIds,
57+
$this->getAssetIdsByContentField->execute($field, $value)
5758
);
5859
}
5960

6061
/**
61-
* Test for getting asset id by store view of a product
62+
* Test for getting asset id by product fields
6263
*
64+
* @dataProvider testProvider
6365
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
6466
* @magentoDataFixture Magento/MediaContentCatalog/_files/product_with_asset.php
67+
* @param string $field
68+
* @param string $value
69+
* @param array $expectedAssetIds
70+
* @throws InvalidArgumentException
6571
*/
66-
public function testProductStoreView(): void
72+
public function testProductFields(string $field, string $value, array $expectedAssetIds): void
6773
{
6874
$this->assertEquals(
69-
[2020],
70-
$this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId)
75+
$expectedAssetIds,
76+
$this->getAssetIdsByContentField->execute($field, $value)
7177
);
7278
}
7379

7480
/**
75-
* Test for getting asset id by enabled status of a product
81+
* Data provider for tests
7682
*
77-
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
78-
* @magentoDataFixture Magento/MediaContentCatalog/_files/category_with_asset.php
83+
* @return array
7984
*/
80-
public function testProductStatusEnabled(): void
85+
public static function testProvider(): array
8186
{
82-
$this->assertEquals(
83-
[2020],
84-
$this->getAssetIdsByContentField->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->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_DISABLED)
99-
);
87+
return [
88+
[self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]],
89+
[self::STATUS_FIELD, self::STATUS_DISABLED, []],
90+
[self::STORE_FIELD, self::DEFAULT_STORE_ID, [self::FIXTURE_ASSET_ID]],
91+
];
10092
}
10193
}

dev/tests/integration/testsuite/Magento/MediaContentCms/Model/ResourceModel/GetAssetIdsByContentFieldTest.php

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,80 +8,103 @@
88

99
namespace Magento\MediaContentCms\Model\ResourceModel;
1010

11+
use Magento\Framework\Exception\InvalidArgumentException;
1112
use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface;
12-
use Magento\Store\Model\StoreManagerInterface;
1313
use Magento\TestFramework\Helper\Bootstrap;
1414
use PHPUnit\Framework\TestCase;
1515

1616
/**
17-
* Test for GetAssetIdByContentFieldTest
17+
* Test for GetAssetIdsByContentFieldTest
1818
*/
1919
class GetAssetIdsByContentFieldTest extends TestCase
2020
{
2121
private const STORE_FIELD = 'store_id';
2222
private const STATUS_FIELD = 'content_status';
2323
private const STATUS_ENABLED = '1';
2424
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';
2528

2629
/**
2730
* @var GetAssetIdsByContentFieldInterface
2831
*/
2932
private $getAssetIdsByContentField;
3033

31-
/**
32-
* @var int
33-
*/
34-
private $storeId;
35-
3634
/**
3735
* @inheritdoc
3836
*/
3937
protected function setUp(): void
4038
{
4139
$objectManager = Bootstrap::getObjectManager();
42-
$this->storeId = $objectManager->get(StoreManagerInterface::class)->getStore()->getId();
4340
$this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class);
4441
}
4542

4643
/**
47-
* Test for getting asset id by store view of a block
44+
* Test for getting asset id by block field
4845
*
46+
* @dataProvider testBlockDataProvider
4947
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
5048
* @magentoDataFixture Magento/MediaContentCms/_files/block_with_asset.php
49+
*
50+
* @param string $field
51+
* @param string $value
52+
* @param array $expectedAssetIds
53+
* @throws InvalidArgumentException
5154
*/
52-
public function testBlockStoreView(): void
55+
public function testBlockFields(string $field, string $value, array $expectedAssetIds): void
5356
{
5457
$this->assertEquals(
55-
[2020],
56-
$this->getAssetIdsByContentField->execute(self::STORE_FIELD, (string)$this->storeId)
58+
$expectedAssetIds,
59+
$this->getAssetIdsByContentField->execute($field, $value)
5760
);
5861
}
5962

6063
/**
61-
* Test for getting asset id by enabled status of a page
64+
* Test for getting asset id by page field
6265
*
66+
* @dataProvider testPageDataProvider
6367
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
6468
* @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
69+
*
70+
* @param string $field
71+
* @param string $value
72+
* @param array $expectedAssetIds
73+
* @throws InvalidArgumentException
6574
*/
66-
public function testPageStatusEnabled(): void
75+
public function testPageFields(string $field, string $value, array $expectedAssetIds): void
6776
{
6877
$this->assertEquals(
69-
[2020],
70-
$this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED)
78+
$expectedAssetIds,
79+
$this->getAssetIdsByContentField->execute($field, $value)
7180
);
7281
}
7382

7483
/**
75-
* Test for getting asset id by disabled status of a page
84+
* Data provider for block tests
7685
*
77-
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php
78-
* @magentoDataFixture Magento/MediaContentCms/_files/page_with_asset.php
86+
* @return array
7987
*/
80-
public function testPageStatusDisabled(): void
88+
public static function testBlockDataProvider(): array
8189
{
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+
];
86109
}
87110
}

0 commit comments

Comments
 (0)