forked from magento/adobe-stock-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
magento#1504: [2.1-develop] Insert rendition images to the content fr…
…om media gallery instead of original images - Integration test coverage for GetAssetIdsByContentFieldTest for rendition.
- Loading branch information
1 parent
72ecf87
commit 79cc0e4
Showing
9 changed files
with
400 additions
and
0 deletions.
There are no files selected for viewing
169 changes: 169 additions & 0 deletions
169
...aGalleryRenditions/Test/Integration/Model/ResourceModel/GetAssetIdsByContentFieldTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
* | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\MediaGalleryRenditions\Test\Integration\Model\ResourceModel; | ||
|
||
use Magento\Framework\Exception\InvalidArgumentException; | ||
use Magento\MediaContentApi\Api\GetAssetIdsByContentFieldInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* GetAssetIdsByContentFieldTest for MediaGalleryRenditions | ||
*/ | ||
class GetAssetIdsByContentFieldTest extends TestCase | ||
{ | ||
private const STORE_FIELD = 'store_id'; | ||
private const STATUS_FIELD = 'content_status'; | ||
private const STATUS_ENABLED = '1'; | ||
private const STATUS_DISABLED = '0'; | ||
private const FIXTURE_ASSET_ID = 2020; | ||
private const DEFAULT_STORE_ID = '1'; | ||
private const ADMIN_STORE_ID = '0'; | ||
|
||
/** | ||
* @var GetAssetIdsByContentFieldInterface | ||
*/ | ||
private $getAssetIdsByContentField; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
$this->getAssetIdsByContentField = $objectManager->get(GetAssetIdsByContentFieldInterface::class); | ||
} | ||
|
||
/** | ||
* Test for getting asset id by block field | ||
* | ||
* @dataProvider dataProvider | ||
* @magentoConfigFixture system/media_gallery/enabled 1 | ||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php | ||
* @magentoDataFixture Magento_MediaGalleryRenditions::Test/Integration/_files/cms/block_with_asset.php | ||
* | ||
* @param string $field | ||
* @param string $value | ||
* @param array $expectedAssetIds | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testBlockFields(string $field, string $value, array $expectedAssetIds): void | ||
{ | ||
$this->assertEquals( | ||
$expectedAssetIds, | ||
$this->getAssetIdsByContentField->execute($field, $value) | ||
); | ||
} | ||
|
||
/** | ||
* Test for getting asset id by page field | ||
* | ||
* @dataProvider pageDataProvider | ||
* @magentoConfigFixture system/media_gallery/enabled 1 | ||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php | ||
* @magentoDataFixture Magento_MediaGalleryRenditions::Test/Integration/_files/cms/page_with_asset.php | ||
* | ||
* @param string $field | ||
* @param string $value | ||
* @param array $expectedAssetIds | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testPageFields(string $field, string $value, array $expectedAssetIds): void | ||
{ | ||
$this->assertEquals( | ||
$expectedAssetIds, | ||
$this->getAssetIdsByContentField->execute($field, $value) | ||
); | ||
} | ||
|
||
/** | ||
* Test for getting asset id by category fields | ||
* | ||
* @dataProvider dataProvider | ||
* @magentoConfigFixture system/media_gallery/enabled 1 | ||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php | ||
* @magentoDataFixture Magento_MediaGalleryRenditions::Test/Integration/_files/catalog/category_with_asset.php | ||
* | ||
* @param string $field | ||
* @param string $value | ||
* @param array $expectedAssetIds | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testCategoryFields(string $field, string $value, array $expectedAssetIds): void | ||
{ | ||
$this->assertEquals( | ||
$expectedAssetIds, | ||
$this->getAssetIdsByContentField->execute($field, $value) | ||
); | ||
} | ||
|
||
/** | ||
* Test for getting asset id by product fields | ||
* | ||
* @dataProvider dataProvider | ||
* @magentoConfigFixture system/media_gallery/enabled 1 | ||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php | ||
* @magentoDataFixture Magento_MediaGalleryRenditions::Test/Integration/_files/catalog/product_with_asset.php | ||
* @param string $field | ||
* @param string $value | ||
* @param array $expectedAssetIds | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testProductFields(string $field, string $value, array $expectedAssetIds): void | ||
{ | ||
$this->assertEquals( | ||
$expectedAssetIds, | ||
$this->getAssetIdsByContentField->execute($field, $value) | ||
); | ||
} | ||
|
||
/** | ||
* Test for getting asset when media gallery disabled | ||
* | ||
* @magentoConfigFixture system/media_gallery/enabled 0 | ||
* @magentoDataFixture Magento/MediaGallery/_files/media_asset.php | ||
* @magentoDataFixture Magento_MediaGalleryRenditions::Test/Integration/_files/catalog/product_with_asset.php | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function testProductFieldsWithDisabledMediaGallery(): void | ||
{ | ||
$this->assertEquals( | ||
[], | ||
$this->getAssetIdsByContentField->execute(self::STATUS_FIELD, self::STATUS_ENABLED) | ||
); | ||
} | ||
|
||
/** | ||
* Data provider for block, category and product tests | ||
* | ||
* @return array | ||
*/ | ||
public static function dataProvider(): array | ||
{ | ||
return [ | ||
[self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], | ||
[self::STATUS_FIELD, self::STATUS_DISABLED, []], | ||
[self::STORE_FIELD, self::DEFAULT_STORE_ID, [self::FIXTURE_ASSET_ID]], | ||
]; | ||
} | ||
|
||
/** | ||
* Data provider for page tests | ||
* | ||
* @return array | ||
*/ | ||
public static function pageDataProvider(): array | ||
{ | ||
return [ | ||
[self::STATUS_FIELD, self::STATUS_ENABLED, [self::FIXTURE_ASSET_ID]], | ||
[self::STATUS_FIELD, self::STATUS_DISABLED, []], | ||
[self::STORE_FIELD, self::ADMIN_STORE_ID, [self::FIXTURE_ASSET_ID]], | ||
]; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
MediaGalleryRenditions/Test/Integration/_files/catalog/category_with_asset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Catalog\Model\Category; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** @var Category $category */ | ||
$category = Bootstrap::getObjectManager()->create(Category::class); | ||
$category->isObjectNew(true); | ||
$category->setId( | ||
28767 | ||
)->setCreatedAt( | ||
'2014-06-23 09:50:07' | ||
)->setName( | ||
'Category 1' | ||
)->setDescription( | ||
'content {{media url=".renditions/testDirectory/path.jpg"}} content' | ||
)->setParentId( | ||
2 | ||
)->setPath( | ||
'1/2/333' | ||
)->setLevel( | ||
2 | ||
)->setAvailableSortBy( | ||
['position', 'name'] | ||
)->setDefaultSortBy( | ||
'name' | ||
)->setIsActive( | ||
true | ||
)->setPosition( | ||
1 | ||
)->save(); |
20 changes: 20 additions & 0 deletions
20
MediaGalleryRenditions/Test/Integration/_files/catalog/category_with_asset_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** @var \Magento\Framework\Registry $registry */ | ||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
|
||
/** @var $category \Magento\Catalog\Model\Category */ | ||
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class); | ||
$category->load(28767); | ||
if ($category->getId()) { | ||
$category->delete(); | ||
} | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |
47 changes: 47 additions & 0 deletions
47
MediaGalleryRenditions/Test/Integration/_files/catalog/product_with_asset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\Product\Type; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\ObjectManager; | ||
|
||
/** @var ObjectManager $objectManager */ | ||
$objectManager = Bootstrap::getObjectManager(); | ||
|
||
/** @var $product Product */ | ||
$product = $objectManager->create(Product::class); | ||
$product->isObjectNew(true); | ||
$product->setTypeId(Type::TYPE_SIMPLE) | ||
->setId(1567) | ||
->setAttributeSetId(4) | ||
->setName('Simple Product') | ||
->setSku('simple_with_asset') | ||
->setPrice(10) | ||
->setWeight(1) | ||
->setShortDescription('content {{media url=".renditions/testDirectory/path.jpg"}} content') | ||
->setTaxClassId(0) | ||
->setDescription('content {{media url=".renditions/testDirectory/path.jpg"}} content') | ||
->setMetaTitle('meta title') | ||
->setMetaKeyword('meta keyword') | ||
->setMetaDescription('meta description') | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData( | ||
[ | ||
'use_config_manage_stock' => 1, | ||
'qty' => 100, | ||
'is_qty_decimal' => 0, | ||
'is_in_stock' => 1, | ||
] | ||
); | ||
|
||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = $objectManager->create(ProductRepositoryInterface::class); | ||
$productRepository->save($product); |
25 changes: 25 additions & 0 deletions
25
MediaGalleryRenditions/Test/Integration/_files/catalog/product_with_asset_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
|
||
\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize(); | ||
|
||
/** @var \Magento\Framework\Registry $registry */ | ||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
|
||
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ | ||
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() | ||
->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); | ||
try { | ||
$product = $productRepository->get('simple_with_asset', false, null, true); | ||
$productRepository->delete($product); | ||
} catch (NoSuchEntityException $e) { | ||
} | ||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |
25 changes: 25 additions & 0 deletions
25
MediaGalleryRenditions/Test/Integration/_files/cms/block_with_asset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\Cms\Model\Block; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** @var $block Block */ | ||
$block = Bootstrap::getObjectManager()->create(Block::class); | ||
$block->setTitle( | ||
'CMS Block Title' | ||
)->setIdentifier( | ||
'fixture_block_with_asset' | ||
)->setContent( | ||
'content {{media url=".renditions/testDirectory/path.jpg"}} content' | ||
)->setIsActive( | ||
1 | ||
)->setStores( | ||
[ | ||
Bootstrap::getObjectManager()->get(StoreManagerInterface::class)->getStore()->getId() | ||
] | ||
)->save(); |
30 changes: 30 additions & 0 deletions
30
MediaGalleryRenditions/Test/Integration/_files/cms/block_with_asset_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Cms\Api\BlockRepositoryInterface; | ||
use Magento\Cms\Api\Data\BlockInterface; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
|
||
/** @var BlockRepositoryInterface $blockRepository */ | ||
$blockRepository = $objectManager->get(BlockRepositoryInterface::class); | ||
|
||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ | ||
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class); | ||
$searchCriteria = $searchCriteriaBuilder->addFilter(BlockInterface::IDENTIFIER, 'fixture_block_with_asset') | ||
->create(); | ||
$result = $blockRepository->getList($searchCriteria); | ||
|
||
/** | ||
* Tests which are wrapped with MySQL transaction clear all data by transaction rollback. | ||
* In that case there is "if" which checks that "fixture_block_with_asset" still exists in database. | ||
*/ | ||
foreach ($result->getItems() as $item) { | ||
$blockRepository->delete($item); | ||
} |
19 changes: 19 additions & 0 deletions
19
MediaGalleryRenditions/Test/Integration/_files/cms/page_with_asset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** @var $page \Magento\Cms\Model\Page */ | ||
$page = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Cms\Model\Page::class); | ||
$page->setTitle('Cms Page 100') | ||
->setIdentifier('fixture_page_with_asset') | ||
->setStores([0]) | ||
->setIsActive(1) | ||
->setContent('content {{media url=".renditions/testDirectory/path.jpg"}} content') | ||
->setContentHeading('<h2>Cms Page 100 Title</h2>') | ||
->setMetaTitle('Cms Meta title for page100') | ||
->setMetaKeywords('Cms Meta Keywords for page100') | ||
->setMetaDescription('Cms Meta Description for page100') | ||
->setPageLayout('1column') | ||
->save(); |
Oops, something went wrong.