Skip to content

Commit 7b1697f

Browse files
committed
Sync tests with changes in the WPT
1 parent e5aaf70 commit 7b1697f

6 files changed

Lines changed: 52 additions & 4 deletions

File tree

tests/WhatWg/FailureTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FailureTest extends WhatwgTestCase
1313
{
1414
public static function urlTestDataFailureProvider(): iterable
1515
{
16-
foreach (self::loadTestData('urltestdata.json') as $inputs) {
16+
foreach (self::loadCombinedUrlTestData() as $inputs) {
1717
if (isset($inputs['failure']) && $inputs['base'] === null) {
1818
yield [$inputs];
1919
}

tests/WhatWg/IdnaV2Test.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rowbot\URL\Tests\WhatWg;
6+
7+
use PHPUnit\Framework\Attributes\DataProvider;
8+
use Rowbot\URL\Exception\TypeError;
9+
use Rowbot\URL\URL;
10+
11+
/**
12+
* @see https://github.com/web-platform-tests/wpt/blob/master/url/IdnaTestV2.window.js
13+
*/
14+
class IdnaV2Test extends WhatwgTestCase
15+
{
16+
public static function idnaTestProvider(): iterable
17+
{
18+
foreach (self::loadTestData('IdnaTestV2.json') as $inputs) {
19+
if ($inputs['input'] !== '') {
20+
yield [$inputs];
21+
}
22+
}
23+
}
24+
25+
#[DataProvider('idnaTestProvider')]
26+
public function testIdna($idnaTest)
27+
{
28+
if ($idnaTest['output'] === null) {
29+
$this->expectException(TypeError::class);
30+
}
31+
32+
$url = new URL("https://{$idnaTest['input']}/x");
33+
self::assertSame($idnaTest['output'], $url->host);
34+
self::assertSame($idnaTest['output'], $url->hostname);
35+
self::assertSame('/x', $url->pathname);
36+
self::assertSame("https://{$idnaTest['output']}/x", $url->href);
37+
}
38+
}

tests/WhatWg/URLConstructorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class URLConstructorTest extends WhatwgTestCase
1515
{
1616
public static function urlTestDataSuccessProvider(): iterable
1717
{
18-
foreach (self::loadTestData('urltestdata.json') as $inputs) {
18+
foreach (self::loadCombinedUrlTestData() as $inputs) {
1919
if (isset($inputs['base']) && !isset($inputs['failure'])) {
2020
yield [$inputs];
2121
}
@@ -47,7 +47,7 @@ public function testUrlConstructorSucceeded(array $expected): void
4747

4848
public static function urlTestDataFailureProvider(): iterable
4949
{
50-
foreach (self::loadTestData('urltestdata.json') as $inputs) {
50+
foreach (self::loadCombinedUrlTestData() as $inputs) {
5151
if (isset($inputs['failure'])) {
5252
yield [$inputs];
5353
}

tests/WhatWg/URLOriginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class URLOriginTest extends WhatwgTestCase
1212
{
1313
public static function urlTestDataOriginProvider(): iterable
1414
{
15-
foreach (self::loadTestData('urltestdata.json') as $inputs) {
15+
foreach (self::loadCombinedUrlTestData() as $inputs) {
1616
if (isset($inputs['origin'])) {
1717
yield [$inputs];
1818
}

tests/WhatWg/URLStaticsCanParseTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class URLStaticsCanParseTest extends TestCase
1515
{
1616
#[TestWith(['url' => 'a:b', 'base' => null, 'expected' => true])]
1717
#[TestWith(['url' => 'a:/b', 'base' => null, 'expected' => true])]
18+
#[TestWith(['url' => 'undefined', 'base' => 'aaa:b', 'expected' => false])]
19+
#[TestWith(['url' => 'undefined', 'base' => 'https://test:test/', 'expected' => false])]
1820
#[TestWith(['url' => 'https://test:test', 'base' => null, 'expected' => false])]
1921
#[TestWith(['url' => 'a', 'base' => 'https://b/', 'expected' => true])]
2022
public function testCanParse(string $url, ?string $base, bool $expected): void

tests/WhatWg/WhatwgTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,12 @@ protected static function loadTestData(string $url): array
5959

6060
return json_decode($data, true, self::JSON_DEPTH, JSON_THROW_ON_ERROR);
6161
}
62+
63+
protected static function loadCombinedUrlTestData(): array
64+
{
65+
return [
66+
...self::loadTestData('urltestdata.json'),
67+
...self::loadTestData('urltestdata-javascript-only.json'),
68+
];
69+
}
6270
}

0 commit comments

Comments
 (0)