forked from magento/magento2
-
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/adobe-stock-integration#1504: Extracted logic from wysiwyg On…
…Insert controller to a model - Integration test
- Loading branch information
1 parent
408cdb7
commit 45849cc
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
app/code/Magento/Cms/Test/Integration/Model/Wysiwyg/Images/GetInsertImageContentTest.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,132 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Cms\Test\Integration\Model\Wysiwyg\Images; | ||
|
||
use Magento\Cms\Helper\Wysiwyg\Images as ImagesHelper; | ||
use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GetInsertImageContentTest extends TestCase | ||
{ | ||
private const TEST_IMAGE_FILE = '/test-image.jpg'; | ||
|
||
/** | ||
* @var GetInsertImageContent | ||
*/ | ||
private $getInsertImageContent; | ||
|
||
/** | ||
* @var ImagesHelper | ||
*/ | ||
private $imagesHelper; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->getInsertImageContent = Bootstrap::getObjectManager()->get(GetInsertImageContent::class); | ||
$this->imagesHelper = Bootstrap::getObjectManager()->get(ImagesHelper::class); | ||
} | ||
|
||
/** | ||
* Test for GetInsertImageContent::execute | ||
* | ||
* @dataProvider imageDataProvider | ||
* @param string $encodedFilename | ||
* @param bool $forceStaticPath | ||
* @param bool $renderAsTag | ||
* @param int|null $storeId | ||
*/ | ||
public function testExecute( | ||
string $encodedFilename, | ||
bool $forceStaticPath, | ||
bool $renderAsTag, | ||
?int $storeId = null | ||
): void { | ||
$getImageForInsert = $this->getInsertImageContent->execute( | ||
$encodedFilename, | ||
$forceStaticPath, | ||
$renderAsTag, | ||
$storeId | ||
); | ||
|
||
if (!$forceStaticPath) { | ||
if ($renderAsTag) { | ||
$html = $this->imagesHelper->getImageHtmlDeclaration( | ||
self::TEST_IMAGE_FILE, | ||
true | ||
); | ||
$this->assertEquals( | ||
$getImageForInsert, | ||
$html | ||
); | ||
} else { | ||
$html = $this->imagesHelper->getImageHtmlDeclaration( | ||
self::TEST_IMAGE_FILE, | ||
false | ||
); | ||
$this->assertEquals( | ||
$getImageForInsert, | ||
$html | ||
); | ||
} | ||
} else { | ||
$this->assertEquals( | ||
$getImageForInsert, | ||
parse_url( | ||
$this->imagesHelper->getCurrentUrl() . self::TEST_IMAGE_FILE, | ||
PHP_URL_PATH | ||
) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Data provider for testExecute | ||
* | ||
* @return array[] | ||
*/ | ||
public function imageDataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'L3Rlc3QtaW1hZ2UuanBn', | ||
false, | ||
true, | ||
1, | ||
], | ||
[ | ||
'L3Rlc3QtaW1hZ2UuanBn', | ||
true, | ||
false, | ||
1, | ||
], | ||
[ | ||
'L3Rlc3QtaW1hZ2UuanBn', | ||
false, | ||
false, | ||
1, | ||
], | ||
[ | ||
'L3Rlc3QtaW1hZ2UuanBn', | ||
false, | ||
true, | ||
2, | ||
], | ||
[ | ||
'L3Rlc3QtaW1hZ2UuanBn', | ||
false, | ||
true, | ||
null, | ||
], | ||
]; | ||
} | ||
} |