class WebpTest in WebP 8
Simple test to ensure that asserts pass.
@group phpunit_example
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\webp\Unit\WebpTest
Expanded class hierarchy of WebpTest
File
- tests/
src/ Unit/ WebpTest.php, line 12
Namespace
Drupal\Tests\webp\UnitView source
class WebpTest extends UnitTestCase {
/**
* Before a test method is run, setUp() is invoked.
*
* Create new unit object.
*/
public function setUp() {
// Mock the class to avoid the constructor.
$this->webp = $this
->getMockBuilder('\\Drupal\\webp\\Webp')
->disableOriginalConstructor()
->setMethods(NULL)
->getMock();
}
/**
* @covers Drupal\webp\Webp::getWebpSrcset
*/
public function testgetWebpSrcset() {
$this
->assertEquals("testimage.webp", $this->webp
->getWebpSrcset("testimage.jpg"));
$this
->assertEquals("testimage2.webp", $this->webp
->getWebpSrcset("testimage2.png"));
$this
->assertEquals("testimage2.webp", $this->webp
->getWebpSrcset("testimage2.jpeg"));
$this
->assertEquals("testimage2.webp", $this->webp
->getWebpSrcset("testimage2.jpg"));
$this
->assertEquals("testimage2.ext.webp", $this->webp
->getWebpSrcset("testimage2.ext.jpg"));
$this
->assertEquals("testimage2.ext.ext.webp", $this->webp
->getWebpSrcset("testimage2.ext.ext.jpg"));
// Test that double extensions are handled properly.
$this
->assertEquals("testimage2.png.webp", $this->webp
->getWebpSrcset("testimage2.png.jpg"));
$this
->assertEquals("testimage2.jpeg.png.webp", $this->webp
->getWebpSrcset("testimage2.jpeg.png.jpg"));
// Test source sets with width descriptor/pixel density and multiple images.
$this
->assertEquals("some/path/image.webp?itok=vOpRgtYZ 1x", $this->webp
->getWebpSrcset("some/path/image.JPG?itok=vOpRgtYZ 1x"));
$this
->assertEquals("some/path/image.webp?itok=vOpRgtYZ 1x, some/path/image.webp?itok=vOpRgtYZ 2x", $this->webp
->getWebpSrcset("some/path/image.JPG?itok=vOpRgtYZ 1x, some/path/image.JPG?itok=vOpRgtYZ 2x"));
// Test source sets with multiple images but without width descriptor/pixel density.
$this
->assertEquals("some/path/image.webp?itok=vOpRgtYZ, some/path/image.webp?itok=vOpRgtYZ", $this->webp
->getWebpSrcset("some/path/image.JPG?itok=vOpRgtYZ, some/path/image.JPG?itok=vOpRgtYZ"));
// And multiple source sets with multiple images.
$this
->assertEquals("some/path/image.png.webp?itok=vOpRgtYZ 1x, some/path/image.jpg.ext.webp?itok=vOpRgtYZ 2x", $this->webp
->getWebpSrcset("some/path/image.png.JPG?itok=vOpRgtYZ 1x, some/path/image.jpg.ext.JPG?itok=vOpRgtYZ 2x"));
$this
->assertEquals("some/path/image.png.webp?itok=vOpRgtYZ, some/path/image.jpg.ext.webp?itok=vOpRgtYZ", $this->webp
->getWebpSrcset("some/path/image.png.JPG?itok=vOpRgtYZ, some/path/image.jpg.ext.JPG?itok=vOpRgtYZ"));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
WebpTest:: |
public | function |
Before a test method is run, setUp() is invoked. Overrides UnitTestCase:: |
|
WebpTest:: |
public | function | @covers Drupal\webp\Webp::getWebpSrcset |