|
| 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\Cms\Test\Integration\Model\Wysiwyg\Images; |
| 10 | + |
| 11 | +use Magento\Cms\Helper\Wysiwyg\Images as ImagesHelper; |
| 12 | +use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent; |
| 13 | +use Magento\TestFramework\Helper\Bootstrap; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +class GetInsertImageContentTest extends TestCase |
| 17 | +{ |
| 18 | + private const TEST_IMAGE_FILE = '/test-image.jpg'; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var GetInsertImageContent |
| 22 | + */ |
| 23 | + private $getInsertImageContent; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var ImagesHelper |
| 27 | + */ |
| 28 | + private $imagesHelper; |
| 29 | + |
| 30 | + /** |
| 31 | + * @inheritdoc |
| 32 | + */ |
| 33 | + protected function setUp(): void |
| 34 | + { |
| 35 | + $this->getInsertImageContent = Bootstrap::getObjectManager()->get(GetInsertImageContent::class); |
| 36 | + $this->imagesHelper = Bootstrap::getObjectManager()->get(ImagesHelper::class); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Test for GetInsertImageContent::execute |
| 41 | + * |
| 42 | + * @dataProvider imageDataProvider |
| 43 | + * @param string $encodedFilename |
| 44 | + * @param bool $forceStaticPath |
| 45 | + * @param bool $renderAsTag |
| 46 | + * @param int|null $storeId |
| 47 | + */ |
| 48 | + public function testExecute( |
| 49 | + string $encodedFilename, |
| 50 | + bool $forceStaticPath, |
| 51 | + bool $renderAsTag, |
| 52 | + ?int $storeId = null |
| 53 | + ): void { |
| 54 | + $getImageForInsert = $this->getInsertImageContent->execute( |
| 55 | + $encodedFilename, |
| 56 | + $forceStaticPath, |
| 57 | + $renderAsTag, |
| 58 | + $storeId |
| 59 | + ); |
| 60 | + |
| 61 | + if (!$forceStaticPath) { |
| 62 | + if ($renderAsTag) { |
| 63 | + $html = $this->imagesHelper->getImageHtmlDeclaration( |
| 64 | + self::TEST_IMAGE_FILE, |
| 65 | + true |
| 66 | + ); |
| 67 | + $this->assertEquals( |
| 68 | + $getImageForInsert, |
| 69 | + $html |
| 70 | + ); |
| 71 | + } else { |
| 72 | + $html = $this->imagesHelper->getImageHtmlDeclaration( |
| 73 | + self::TEST_IMAGE_FILE, |
| 74 | + false |
| 75 | + ); |
| 76 | + $this->assertEquals( |
| 77 | + $getImageForInsert, |
| 78 | + $html |
| 79 | + ); |
| 80 | + } |
| 81 | + } else { |
| 82 | + $this->assertEquals( |
| 83 | + $getImageForInsert, |
| 84 | + parse_url( |
| 85 | + $this->imagesHelper->getCurrentUrl() . self::TEST_IMAGE_FILE, |
| 86 | + PHP_URL_PATH |
| 87 | + ) |
| 88 | + ); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Data provider for testExecute |
| 94 | + * |
| 95 | + * @return array[] |
| 96 | + */ |
| 97 | + public function imageDataProvider(): array |
| 98 | + { |
| 99 | + return [ |
| 100 | + [ |
| 101 | + 'L3Rlc3QtaW1hZ2UuanBn', |
| 102 | + false, |
| 103 | + true, |
| 104 | + 1, |
| 105 | + ], |
| 106 | + [ |
| 107 | + 'L3Rlc3QtaW1hZ2UuanBn', |
| 108 | + true, |
| 109 | + false, |
| 110 | + 1, |
| 111 | + ], |
| 112 | + [ |
| 113 | + 'L3Rlc3QtaW1hZ2UuanBn', |
| 114 | + false, |
| 115 | + false, |
| 116 | + 1, |
| 117 | + ], |
| 118 | + [ |
| 119 | + 'L3Rlc3QtaW1hZ2UuanBn', |
| 120 | + false, |
| 121 | + true, |
| 122 | + 2, |
| 123 | + ], |
| 124 | + [ |
| 125 | + 'L3Rlc3QtaW1hZ2UuanBn', |
| 126 | + false, |
| 127 | + true, |
| 128 | + null, |
| 129 | + ], |
| 130 | + ]; |
| 131 | + } |
| 132 | +} |
0 commit comments