Skip to content

Commit

Permalink
test: modernize and reformat test code
Browse files Browse the repository at this point in the history
  • Loading branch information
adevade committed Jan 31, 2023
1 parent c4ef328 commit 5b1995f
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 202 deletions.
27 changes: 12 additions & 15 deletions tests/PathEncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,28 @@ class PathEncodingTest extends TestCase

public function testBracketEncoding()
{
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);

$url = $builder->createURL('/ <>[]{}|\\^%.jpg');
$this->assertEquals(
'https://sdk-test.imgix.net/%20%3C%3E%5B%5D%7B%7D%7C%5C%5E%25.jpg',
$url
);

$this->assertEquals('https://sdk-test.imgix.net/%20%3C%3E%5B%5D%7B%7D%7C%5C%5E%25.jpg', $url);
}

public function testSpecialCharsEncoding()
{
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);

$url = $builder->createURL('&$+,:;=?@#.jpg');
$this->assertEquals(
'https://sdk-test.imgix.net/%26%24%2B%2C:%3B%3D%3F@%23.jpg',
$url
);

$this->assertEquals('https://sdk-test.imgix.net/%26%24%2B%2C:%3B%3D%3F@%23.jpg', $url);
}

public function testUnicodeEncoding()
{
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);

$url = $builder->createURL('/ساندویچ.jpg');
$this->assertEquals(
'https://sdk-test.imgix.net/%D8%B3%D8%A7%D9%86%D8%AF%D9%88%DB%8C%DA%86.jpg',
$url
);

$this->assertEquals('https://sdk-test.imgix.net/%D8%B3%D8%A7%D9%86%D8%AF%D9%88%DB%8C%DA%86.jpg', $url);
}
}
11 changes: 6 additions & 5 deletions tests/ReadMeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

class ReadMeTest extends TestCase
{
private const HOST = 'demos.imgix.net';
public const HOST = 'demos.imgix.net';

public function testFixedWidthImages()
{
$builder = new UrlBuilder(self::HOST, true, 'my-key', false);

$actual = $builder->createSrcSet('image.png', ['h' => 800, 'ar' => '3:2', 'fit' => 'crop']);
$expected =
'https://demos.imgix.net/image.png?ar=3%3A2&dpr=1&fit=crop&h=800&q=75&s=b6b4a327a9e5a9ce5c9251b736c98633 1x,
Expand All @@ -25,7 +26,7 @@ public function testFixedWidthImages()

public function testFixedWidthVariableQualityEnabled()
{
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);
$actual = $builder->createSrcSet('image.jpg', ['w' => 100]);

$expected =
Expand All @@ -40,7 +41,7 @@ public function testFixedWidthVariableQualityEnabled()

public function testFluidWidthCustomWidths()
{
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);

$actual = $builder->createSrcSet('image.jpg', [], ['widths' => [144, 240, 320, 446, 640]]);
$expected =
Expand All @@ -56,7 +57,7 @@ public function testFluidWidthCustomWidths()
public function testFluidWidthRanges()
{
// Now test custom tolerances (also within a range).
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);

$actual = $builder->createSrcSet('image.jpg', [], ['start' => 500, 'stop' => 2000]);
$expected =
Expand All @@ -77,7 +78,7 @@ public function testFluidWidthRanges()

public function testFluidWidthRangesTolerance()
{
$builder = new UrlBuilder(self::HOST, true, '', false);
$builder = new UrlBuilder(self::HOST, includeLibraryParam: false);

$actual = $builder->createSrcSet('image.jpg', [], ['start' => 100, 'stop' => 384, 'tol' => 0.20]);
$expected =
Expand Down
Loading

0 comments on commit 5b1995f

Please sign in to comment.