-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathResourceMatcherTest.php
More file actions
79 lines (73 loc) · 2.95 KB
/
ResourceMatcherTest.php
File metadata and controls
79 lines (73 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
declare(strict_types=1);
namespace B13\Http2\Tests\Unit;
/*
* This file is part of TYPO3 CMS-based extension "http2" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/
use B13\Http2\ResourceMatcher;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
class ResourceMatcherTest extends TestCase
{
public static function matchDataProvider()
{
return [
'nothing useful' => [
'<title>Good things must come</title>',
[],
[],
],
'simple script tag' => [
'<script src="https://www.example.com/myfile.js" />',
['https://www.example.com/myfile.js'],
[],
],
'simple script tag with parameter' => [
'<script src="https://www.example.com/myfile.js?foo" />',
['https://www.example.com/myfile.js?foo'],
[],
],
'simple script tag with parameter and value' => [
'<script src="https://www.example.com/myfile.js?foo=bar" />',
['https://www.example.com/myfile.js?foo=bar'],
[],
],
'multiple script tags' => [
'<script src="https://www.example.com/myfile.js" /><link><script src="/myfile.js"></script>',
['https://www.example.com/myfile.js', '/myfile.js'],
[],
],
'multiple script tags with the same value finds duplicate hits' => [
'<script src="https://www.example.com/myfile.js" /><link><script src="/myfile.js"></script><script src="/myfile.js" />',
['https://www.example.com/myfile.js', '/myfile.js', '/myfile.js'],
[],
],
'multiple script and link tags' => [
'<script src="https://www.example.com/myfile.js" /><link href="http://example.com/favicon.ico"><script src="/myfile.js"></script>',
['https://www.example.com/myfile.js', '/myfile.js'],
[],
],
'multiple script and valid link tags' => [
'<script src="https://www.example.com/myfile.js" /><link href="http://example.com/base.css"><script src="/myfile.js"></script>',
['https://www.example.com/myfile.js', '/myfile.js'],
['http://example.com/base.css'],
],
];
}
#[DataProvider('matchDataProvider')]
#[Test]
public function matchExtractsProperInformation($input, $expectedScripts, $expectedStyles)
{
$expectedResult = [
'scripts' => $expectedScripts,
'styles' => $expectedStyles,
];
$result = (new ResourceMatcher())->match($input);
self::assertEquals($expectedResult, $result);
}
}