diff --git a/tests/php/GraphQL/FileTypeCreatorTest.php b/tests/php/GraphQL/FileTypeCreatorTest.php index 009e5d126..32e959ece 100644 --- a/tests/php/GraphQL/FileTypeCreatorTest.php +++ b/tests/php/GraphQL/FileTypeCreatorTest.php @@ -49,28 +49,22 @@ public function testThumbnail() $image->setFromLocalFile(__DIR__.'/../Forms/fixtures/largeimage.png', 'TestImage.png'); $image->write(); - // Image original is unset - $thumbnail = FileTypeResolver::resolveFileThumbnail($image, [], [], null); - $this->assertNull($thumbnail); - - // Generate thumbnails by viewing this file's data - $assetAdmin->getObjectFromData($image, false); - + // Image original is NOT unset - we generate as soon as we request information about the file. // protected image should have inline thumbnail $thumbnail = FileTypeResolver::resolveFileThumbnail($image, [], [], null); - $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAADr', $thumbnail); + $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAAEI', $thumbnail); // public image should have url $image->publishSingle(); $thumbnail = FileTypeResolver::resolveFileThumbnail($image, [], [], null); - $this->assertEquals('/assets/FileTypeCreatorTest/TestImage__FitMaxWzM1MiwyNjRd.png', $thumbnail); + $this->assertEquals('/assets/FileTypeCreatorTest/TestImage__FillWzM1MiwyNjRd.png', $thumbnail); // Public assets can be set to inline ThumbnailGenerator::config()->merge('thumbnail_links', [ AssetStore::VISIBILITY_PUBLIC => ThumbnailGenerator::INLINE, ]); $thumbnail = FileTypeResolver::resolveFileThumbnail($image, [], [], null); - $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAADr', $thumbnail); + $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAAEI', $thumbnail); // Protected assets can be set to url // This uses protected asset adapter, so not direct asset link @@ -79,6 +73,6 @@ public function testThumbnail() ]); $image->doUnpublish(); $thumbnail = FileTypeResolver::resolveFileThumbnail($image, [], [], null); - $this->assertEquals('/assets/8cf6c65fa7/TestImage__FitMaxWzM1MiwyNjRd.png', $thumbnail); + $this->assertEquals('/assets/8cf6c65fa7/TestImage__FillWzM1MiwyNjRd.png', $thumbnail); } } diff --git a/tests/php/GraphQL/Legacy/FileTypeCreatorTest.php b/tests/php/GraphQL/Legacy/FileTypeCreatorTest.php index b26d713fc..bcd0c8c30 100644 --- a/tests/php/GraphQL/Legacy/FileTypeCreatorTest.php +++ b/tests/php/GraphQL/Legacy/FileTypeCreatorTest.php @@ -50,28 +50,22 @@ public function testThumbnail() $image->setFromLocalFile(__DIR__.'/../../Forms/fixtures/largeimage.png', 'TestImage.png'); $image->write(); - // Image original is unset - $thumbnail = $type->resolveThumbnailField($image, [], [], null); - $this->assertNull($thumbnail); - - // Generate thumbnails by viewing this file's data - $assetAdmin->getObjectFromData($image, false); - + // Image original is NOT unset - we generate as soon as we request information about the file. // protected image should have inline thumbnail $thumbnail = $type->resolveThumbnailField($image, [], [], null); - $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAADr', $thumbnail); + $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAAEI', $thumbnail); // public image should have url $image->publishSingle(); $thumbnail = $type->resolveThumbnailField($image, [], [], null); - $this->assertEquals('/assets/FileTypeCreatorTest/TestImage__FitMaxWzM1MiwyNjRd.png', $thumbnail); + $this->assertEquals('/assets/FileTypeCreatorTest/TestImage__FillWzM1MiwyNjRd.png', $thumbnail); // Public assets can be set to inline ThumbnailGenerator::config()->merge('thumbnail_links', [ AssetStore::VISIBILITY_PUBLIC => ThumbnailGenerator::INLINE, ]); $thumbnail = $type->resolveThumbnailField($image, [], [], null); - $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAADr', $thumbnail); + $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWAAAAEI', $thumbnail); // Protected assets can be set to url // This uses protected asset adapter, so not direct asset link @@ -80,6 +74,6 @@ public function testThumbnail() ]); $image->doUnpublish(); $thumbnail = $type->resolveThumbnailField($image, [], [], null); - $this->assertEquals('/assets/8cf6c65fa7/TestImage__FitMaxWzM1MiwyNjRd.png', $thumbnail); + $this->assertEquals('/assets/8cf6c65fa7/TestImage__FillWzM1MiwyNjRd.png', $thumbnail); } } diff --git a/tests/php/Model/ThumbnailGeneratorTest.php b/tests/php/Model/ThumbnailGeneratorTest.php index 139d135a6..0536d696c 100644 --- a/tests/php/Model/ThumbnailGeneratorTest.php +++ b/tests/php/Model/ThumbnailGeneratorTest.php @@ -39,7 +39,7 @@ public function testGenerateThumbnail() // protected image should have inline thumbnail $thumbnail = $generator->generateThumbnail($image, 100, 200); $this->assertEquals(100, $thumbnail->getWidth()); - $this->assertEquals(50, $thumbnail->getHeight()); // Note: Aspect ratio of original image retained + $this->assertEquals(200, $thumbnail->getHeight()); // Build non-image $file = new File(); @@ -57,6 +57,20 @@ public function testGenerateThumbnail() $this->assertNull($thumbnail); } + public function testGenerateThumbnailFitMax() + { + ThumbnailGenerator::config()->set('method', 'FitMax'); + $generator = new ThumbnailGenerator(); + // Build image + $image = new Image(); + $image->setFromLocalFile(__DIR__ . '/../Forms/fixtures/testimage.png', 'TestImage.png'); + $image->write(); + + $thumbnail = $generator->generateThumbnail($image, 100, 200); + $this->assertEquals(100, $thumbnail->getWidth()); + $this->assertEquals(50, $thumbnail->getHeight()); // Note: Aspect ratio of original image retained + } + public function testGenerateLink() { $generator = new ThumbnailGenerator(); @@ -82,7 +96,7 @@ public function testGenerateLink() // protected image should have inline thumbnail $thumbnail = $generator->generateThumbnailLink($image, 100, 200); - $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAy', $thumbnail); + $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAADI', $thumbnail); // but not if it's too big Config::nest(); @@ -92,20 +106,20 @@ public function testGenerateLink() $this->assertNull($thumbnail); // With graceful thumbnails, it should come back as a URL $thumbnail = $generator->generateThumbnailLink($image, 100, 200, true); - $this->assertMatchesRegularExpression('#/assets/[A-Za-z0-9]+/TestImage__FitMaxWzEwMCwyMDBd\.png$#', $thumbnail); + $this->assertMatchesRegularExpression('#/assets/[A-Za-z0-9]+/TestImage__FillWzEwMCwyMDBd\.png$#', $thumbnail); Config::unnest(); // public image should have url $image->publishSingle(); $thumbnail = $generator->generateThumbnailLink($image, 100, 200); - $this->assertEquals('/assets/ThumbnailGeneratorTest/TestImage__FitMaxWzEwMCwyMDBd.png', $thumbnail); + $this->assertEquals('/assets/ThumbnailGeneratorTest/TestImage__FillWzEwMCwyMDBd.png', $thumbnail); // Public assets can be set to inline ThumbnailGenerator::config()->merge('thumbnail_links', [ AssetStore::VISIBILITY_PUBLIC => ThumbnailGenerator::INLINE, ]); $thumbnail = $generator->generateThumbnailLink($image, 100, 200); - $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAy', $thumbnail); + $this->assertStringStartsWith('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAADI', $thumbnail); // Protected assets can be set to url // This uses protected asset adapter, so not direct asset link @@ -114,6 +128,6 @@ public function testGenerateLink() ]); $image->doUnpublish(); $thumbnail = $generator->generateThumbnailLink($image, 100, 200); - $this->assertEquals('/assets/906835357d/TestImage__FitMaxWzEwMCwyMDBd.png', $thumbnail); + $this->assertEquals('/assets/906835357d/TestImage__FillWzEwMCwyMDBd.png', $thumbnail); } }