-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
24 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
/vendor/ | ||
/.idea/ | ||
/node_modules | ||
webroot/modified |
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
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,26 @@ | ||
<?xml version="1.0"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<php> | ||
<!-- E_ALL => 32767 --> | ||
<!-- E_ALL & ~E_USER_DEPRECATED => 16383 --> | ||
<ini name="error_reporting" value="16383"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="assets"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<listeners> | ||
<listener class="Cake\TestSuite\Fixture\FixtureInjector"> | ||
<arguments> | ||
<object class="Cake\TestSuite\Fixture\FixtureManager"/> | ||
</arguments> | ||
</listener> | ||
</listeners> | ||
<!-- Prevent coverage reports from looking in tests, vendors, config folders --> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
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
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
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,66 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Assets\Test\Utilities; | ||
|
||
use Assets\Utilities\ImageAsset; | ||
use Cake\TestSuite\TestCase; | ||
|
||
class ImageAssetTest extends TestCase | ||
{ | ||
protected const DATA_IMAGES = __DIR__ . DS; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
if (!defined('PLUGIN_ROOT')) { | ||
include __DIR__ . DS . '..' . DS . 'bootstrap.php'; | ||
} | ||
} | ||
|
||
public function testCreateFromPathWithInvalidPath(): void | ||
{ | ||
static::expectException(\InvalidArgumentException::class); | ||
$image = ImageAsset::createFromPath('invalid-path'); | ||
} | ||
|
||
public function testCreateFromPathWithValidPath(): void | ||
{ | ||
$path = static::DATA_IMAGES . 'cake.jpg'; | ||
$image = ImageAsset::createFromPath($path); | ||
static::assertInstanceOf(ImageAsset::class, $image); | ||
|
||
$renderedPath = WWW_ROOT . $image->toWebp()->scaleWidth(120)->getPath(); | ||
static::assertFileExists($renderedPath); | ||
$splFileInfo = new \SplFileInfo($renderedPath); | ||
static::assertEquals('image/webp', mime_content_type($renderedPath)); | ||
static::assertEquals(6178, $splFileInfo->getSize()); | ||
|
||
$renderedPathOfLargeJpg = WWW_ROOT . $image->toJpg()->scaleWidth(240)->getPath(); | ||
static::assertFileExists($renderedPathOfLargeJpg); | ||
$splFileInfoJpg = new \SplFileInfo($renderedPathOfLargeJpg); | ||
static::assertEquals('image/jpeg', mime_content_type($renderedPathOfLargeJpg)); | ||
static::assertEquals(22336, $splFileInfoJpg->getSize()); | ||
} | ||
|
||
public function testHtmlCreation(): void | ||
{ | ||
$path = static::DATA_IMAGES . 'cake.jpg'; | ||
$image = ImageAsset::createFromPath($path); | ||
static::assertInstanceOf(ImageAsset::class, $image); | ||
|
||
$html = $image | ||
->scaleWidth(230) | ||
->setCSS('some-css') | ||
->setLazyLoading(false) | ||
->getHTML([ | ||
'data-test' => 123, | ||
]); | ||
|
||
static::assertNotEmpty($html); | ||
static::assertStringContainsString('width="230"', $html); | ||
static::assertStringContainsString('class="some-css"', $html); | ||
static::assertStringContainsString('data-test="123"', $html); | ||
static::assertStringContainsString('loading="eager"', $html); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.