Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
pboivin committed Sep 1, 2022
1 parent f02fbda commit 85d09a1
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Pboivin\Flou\Tests;

use PHPUnit\Framework\TestCase;
use Pboivin\Flou\Tests\Concerns\Mocking;

class IntegrationTest extends TestCase
{
use Mocking;

private $factory;

protected function setUp(): void
{
$flou = $this->getFactory();

$flou
->inspector()
->shouldReceive('getSize')
->andReturn(['width' => 123, 'height' => 123]);

$flou
->glideServer()
->shouldReceive('makeImage')
->andReturn('cached.jpg');

$this->factory = $flou;
}

public function test_can_handle_single_image()
{
$image = $this->factory->image('source.jpg');

$output = $image->render()->img();

$this->assertEquals(
'<img class="lazyload" alt="" src="/images/cache/cached.jpg" data-src="/images/source/source.jpg" width="123" height="123">',
$output
);
}

public function test_can_handle_simple_imageset()
{
$set = $this->factory->imageSet([
'image' => 'source.jpg',
'widths' => [400],
]);

$output = $set->render()->img();

$this->assertEquals(
'<img class="lazyload" alt="" src="/images/cache/cached.jpg" width="123" height="123" data-src="/images/cache/cached.jpg" data-srcset="/images/cache/cached.jpg" data-sizes="100vw">',
$output
);
}

public function test_can_handle_responsive_imageset()
{
$set = $this->factory->imageSet([
'image' => 'source.jpg',
'widths' => [400, 800, 1200],
'sizes' => '66vw',
]);

$output = $set->render()->img();

$this->assertEquals(
'<img class="lazyload" alt="" src="/images/cache/cached.jpg" width="123" height="123" data-src="/images/cache/cached.jpg" data-srcset="/images/cache/cached.jpg 400w, /images/cache/cached.jpg 800w, /images/cache/cached.jpg 1200w" data-sizes="66vw">',
$output
);
}

public function test_can_handle_multi_imageset()
{
$set = $this->factory->imageSet([
[
'image' => 'source1.jpg',
'media' => '(max-width: 1023px)',
'widths' => [400, 800],
],
[
'image' => 'source2.jpg',
'media' => '(min-width: 1024px)',
'widths' => [1200, 1600],
],
]);

$output = $set->render()->picture();

$this->assertEquals(
'<picture ><source media="(max-width: 1023px)" data-srcset="/images/cache/cached.jpg 400w, /images/cache/cached.jpg 800w"><source media="(min-width: 1024px)" data-srcset="/images/cache/cached.jpg 1200w, /images/cache/cached.jpg 1600w"><img class="lazyload" alt="" src="/images/cache/cached.jpg" data-src="/images/cache/cached.jpg" width="123" height="123"></picture>',
$output
);
}
}

0 comments on commit 85d09a1

Please sign in to comment.