Skip to content

Commit 86b2177

Browse files
authored
Merge pull request #559 from uzulla/update-test-fixture
Update fixtures to pass PHPUnit
2 parents b2ea091 + c250bb9 commit 86b2177

File tree

54 files changed

+3764
-5253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3764
-5253
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ jobs:
2323

2424
steps:
2525
- name: Checkout
26-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
2727

2828
- name: Install PHP
2929
uses: shivammathur/setup-php@v2
3030
with:
3131
php-version: ${{ matrix.php }}
3232

3333
- name: Cache PHP dependencies
34-
uses: actions/cache@v2
34+
uses: actions/cache@v4
3535
with:
3636
path: vendor
3737
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}

src/Document.php

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,56 @@ public function __construct(Extractor $extractor)
3131
preg_match('/charset=(?:"|\')?(.*?)(?=$|\s|;|"|\'|>)/i', $contentType, $match);
3232
if (!empty($match[1])) {
3333
$encoding = trim($match[1], ',');
34-
try {
35-
$ret = mb_encoding_aliases($encoding ?? '');
36-
if ($ret === false) {
37-
$encoding = null;
38-
}
39-
} catch (\ValueError $exception) {
40-
$encoding = null;
41-
}
34+
$encoding = $this->getValidEncoding($encoding);
4235
}
4336
if (is_null($encoding) && !empty($html)) {
4437
preg_match('/charset=(?:"|\')?(.*?)(?=$|\s|;|"|\'|>)/i', $html, $match);
4538
if (!empty($match[1])) {
4639
$encoding = trim($match[1], ',');
40+
$encoding = $this->getValidEncoding($encoding);
4741
}
42+
}
43+
$this->document = !empty($html) ? Parser::parse($html, $encoding) : new DOMDocument();
44+
$this->initXPath();
45+
}
46+
47+
/**
48+
* Get valid encoding name if it exists, otherwise return null
49+
*
50+
* Uses mb_encoding_aliases() to verify the encoding is valid.
51+
*
52+
* TODO: When dropping PHP 7.4 support, remove the PHP_VERSION_ID < 80000 branch.
53+
* PHP version differences:
54+
* - PHP 7.4: mb_encoding_aliases() returns false for invalid encoding and throws Warning for empty string
55+
* - PHP 8.0+: mb_encoding_aliases() throws ValueError for invalid/empty encoding
56+
*
57+
* @see https://www.php.net/manual/en/function.mb-encoding-aliases.php
58+
*/
59+
private function getValidEncoding(?string $encoding): ?string
60+
{
61+
if (PHP_VERSION_ID < 80000) {
62+
// PHP 7.4: Check return value (false = invalid encoding)
63+
// Need to check empty() first to avoid Warning
64+
// TODO: Remove this entire branch when PHP 7.4 support is dropped
65+
if (empty($encoding)) {
66+
return null;
67+
}
68+
$ret = mb_encoding_aliases($encoding);
69+
if ($ret === false) {
70+
return null;
71+
} else {
72+
return $encoding;
73+
}
74+
} else {
75+
// PHP 8.0+: ValueError exception is thrown for invalid/empty encoding
4876
try {
49-
$ret = mb_encoding_aliases($encoding ?? '');
50-
if ($ret === false) {
51-
$encoding = null;
52-
}
77+
$aliases = mb_encoding_aliases($encoding ?? '');
78+
// Check if aliases array is not empty (valid encoding should have at least one alias)
79+
return !empty($aliases) ? $encoding : null;
5380
} catch (\ValueError $exception) {
54-
$encoding = null;
81+
return null;
5582
}
5683
}
57-
$this->document = !empty($html) ? Parser::parse($html, $encoding) : new DOMDocument();
58-
$this->initXPath();
5984
}
6085

6186
private function initXPath()

tests/DocumentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testSelectors()
2828
$extractor = self::getEmbed()->get('http://www.wired.com/?p=2064839');
2929
$document = $extractor->getDocument();
3030

31-
$expected = 23;
31+
$expected = 3;
3232

3333
$this->assertCount($expected, $document->select('.//p')->nodes());
3434
$this->assertCount($expected, $document->selectCss('p')->nodes());

tests/cache/www.wired.com..1202600986b37d2c6a30336f82c671f8.php

Lines changed: 1999 additions & 1833 deletions
Large diffs are not rendered by default.

tests/fixtures/4pda.to.2022-12-04-406834-sostoyalsya_reliz_clown_of_duty_parodii_na_call_of_duty.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
'feeds' => [],
1212
'icon' => 'https://4pda.to/s/as6ywymaTWM6wnea1mxojxCz0Yet7IeumfOBnaxb.png',
1313
'image' => 'https://i.4pda.ws/s/as6yueQrUwnKt0LgJ5m26uBjbZsccTet21FqwJkADfGw.jpg?v=1669981373',
14-
'keywords' => ['состоялся релиз clown of duty — пародии на call of duty'],
14+
'keywords' => [
15+
'состоялся релиз clown of duty — пародии на call of duty'
16+
],
1517
'language' => 'ru-RU',
1618
'languages' => [],
1719
'license' => null,
@@ -23,5 +25,5 @@
2325
'url' => 'https://4pda.to/2022/12/04/406834/sostoyalsya_reliz_clown_of_duty_parodii_na_call_of_duty/',
2426
'linkedData' => [],
2527
'oEmbed' => [],
26-
'allLinkedData' => [],
28+
'allLinkedData' => []
2729
];

tests/fixtures/animoto.com.play-gjsj1gu0wdrfr4pgw12xzq.php

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,55 @@
22
declare(strict_types = 1);
33

44
return [
5-
'authorName' => null,
6-
'authorUrl' => null,
5+
'authorName' => '@animoto',
6+
'authorUrl' => 'https://twitter.com/animoto',
77
'cms' => null,
8-
'code' => [
9-
'html' => '<iframe id="vp1GjsJ1" title="Video Player" width="640" height="360" frameborder="0" src="https://s3.amazonaws.com/embed.animoto.com/play.html?w=swf/production/vp1&e=1617549702&f=GjsJ1gu0WDRfr4pGw12xZQ&d=0&m=p&r=360p&i=m&asset_domain=s3-p.animoto.com&animoto_domain=animoto.com&options=start_hq" allowfullscreen></iframe>',
10-
'width' => 640,
11-
'height' => 360,
12-
'ratio' => 56.25
8+
'code' => null,
9+
'description' => 'Create, edit, and share videos with our free video maker. Combine your photos, video clips, and music to make quality videos in minutes. Get started free!',
10+
'favicon' => 'https://animoto.com/favicon-32x32.png?v=f7bad0df2a4af8688773dca5ee0b1ed6',
11+
'feeds' => [
12+
'https://animoto.com/rss.xml'
1313
],
14-
'description' => 'Animoto makes video creation easy! Animoto\'s video maker turns your photos and video clips into professional videos in minutes. Fast and shockingly simple!',
15-
'favicon' => 'https://d14pr3cu5atb0x.cloudfront.net/images/icons/favicon-fbb19e53d0.ico',
16-
'feeds' => [],
17-
'icon' => 'https://d14pr3cu5atb0x.cloudfront.net/images/icons/touchicon-144-4a42d97241.png',
18-
'image' => 'https://d2m23yiuv18ohn.cloudfront.net/Video/GjsJ1gu0WDRfr4pGw12xZQ/cover_648x360.jpg',
14+
'icon' => 'https://animoto.com/icons/icon-48x48.png?v=f7bad0df2a4af8688773dca5ee0b1ed6',
15+
'image' => null,
1916
'keywords' => [],
2017
'language' => null,
2118
'languages' => [],
2219
'license' => null,
2320
'providerName' => 'Animoto',
24-
'providerUrl' => 'https://animoto.com/',
21+
'providerUrl' => 'https://animoto.com',
2522
'publishedTime' => null,
2623
'redirect' => null,
27-
'title' => 'taco bell',
24+
'title' => 'Free Video Maker | Create & Edit Your Videos Easily',
2825
'url' => 'https://animoto.com/play/GjsJ1gu0WDRfr4pGw12xZQ',
29-
'linkedData' => [],
26+
'linkedData' => [
27+
'@context' => 'http://schema.org',
28+
'@type' => 'WebSite',
29+
'url' => 'https://animoto.com',
30+
'name' => 'Animoto video maker - Stand out on social media. Easily.',
31+
'alternateName' => ''
32+
],
3033
'oEmbed' => [
31-
'version' => 1.0,
32-
'provider_name' => 'Animoto',
33-
'provider_url' => 'https://animoto.com/',
34-
'type' => 'video',
35-
'author_name' => null,
36-
'title' => 'taco bell',
37-
'description' => '',
38-
'thumbnail_url' => 'https://d2m23yiuv18ohn.cloudfront.net/Video/GjsJ1gu0WDRfr4pGw12xZQ/cover_648x360.jpg',
39-
'thumbnail_height' => 360,
40-
'thumbnail_width' => 648,
41-
'icon_url' => 'https://d2m23yiuv18ohn.cloudfront.net/Video/GjsJ1gu0WDRfr4pGw12xZQ/cover_224x126.jpg',
42-
'icon_height' => 54,
43-
'icon_width' => 54,
44-
'width' => 640,
45-
'height' => 360,
46-
'cache_age' => 604800,
47-
'video_url' => 'https://d150hyw1dtprld.cloudfront.net/swf/w.swf?w=swf/production/vp1&e=1617549702&f=GjsJ1gu0WDRfr4pGw12xZQ&d=0&m=p&r=360p&i=m&asset_domain=s3-p.animoto.com&animoto_domain=animoto.com&options=start_hq',
48-
'html' => '<iframe id="vp1GjsJ1" title="Video Player" width="640" height="360" frameborder="0" src="https://s3.amazonaws.com/embed.animoto.com/play.html?w=swf/production/vp1&e=1617549702&f=GjsJ1gu0WDRfr4pGw12xZQ&d=0&m=p&r=360p&i=m&asset_domain=s3-p.animoto.com&animoto_domain=animoto.com&options=start_hq" allowfullscreen></iframe>'
34+
'error' => 'URL not supported or not found',
35+
'url' => 'https://animoto.com/play/GjsJ1gu0WDRfr4pGw12xZQ'
4936
],
50-
'allLinkedData' => []
37+
'allLinkedData' => [
38+
[
39+
'@context' => 'http://schema.org',
40+
'@type' => 'WebSite',
41+
'url' => 'https://animoto.com',
42+
'name' => 'Animoto video maker - Stand out on social media. Easily.',
43+
'alternateName' => ''
44+
],
45+
[
46+
'@context' => 'http://schema.org',
47+
'@type' => 'VideoObject',
48+
'name' => 'Animoto: Free Online Video Maker',
49+
'contentUrl' => 'https://d2of6bhnpl91ni.cloudfront.net/cms/animoto-free-online-video-maker-e8d6870030.mp4',
50+
'description' => 'With Animoto, you\'ll have everything you need to create your own professional videos in minutes. No experience required. All it takes is an idea. ',
51+
'thumbnailUrl' => '//images.ctfassets.net/00i767ygo3tc/010bacg5wwIhMMx6xYS3qj/18e39c5d16f5614a3b477a284faea1a2/free-online-video-maker.webp',
52+
'transcript' => 'We all have a story to tell, and video is the best way to make yours stand out. With Animoto, you\'ll have everything you need to create your own professional videos in minutes. No experience required. All it takes is an idea. We\'ve made it easy to get started with customizable templates for everything from saying Happy Birthday to selling your product. From there, it\'s as simple as dragging and dropping your photos and video clips, choosing from our millions of Getty stock images or recording with our built-in screen and webcam recorder. Customize your videos with transitions, music, voiceovers, and more. Then bring your videos on brand with a single click. Make sure your story is heard with Animoto. Everything you need to create your own videos is right at your fingertips. Start creating for free.',
53+
'uploadDate' => '2020-09-15T21:58:55.636Z'
54+
]
55+
]
5156
];

tests/fixtures/archive.org.details-dn2015-0220_vid.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
],
4444
'oEmbed' => [],
4545
'api' => [
46-
'server' => 'ia802600.us.archive.org',
47-
'dir' => '/20/items/dn2015-0220_vid',
46+
'server' => 'ia801600.us.archive.org',
47+
'dir' => '/34/items/dn2015-0220_vid',
4848
'metadata' => [
4949
'identifier' => [
5050
'dn2015-0220_vid'
@@ -786,11 +786,12 @@
786786
'/dn2015-0220_vid_files.xml' => [
787787
'source' => 'original',
788788
'format' => 'Metadata',
789-
'md5' => '745ea2f6dde93e4b70b1c0b238d4c0e2'
789+
'md5' => 'c8085d21bd5d528af0697f7d1cfff599',
790+
'summation' => 'md5'
790791
],
791792
'/dn2015-0220_vid_meta.xml' => [
792793
'source' => 'original',
793-
'mtime' => '1542757137',
794+
'mtime' => '1675274129',
794795
'size' => '1973',
795796
'format' => 'Metadata',
796797
'md5' => '6a144c80a58ab5f08c0ecffdb580954a',
@@ -799,12 +800,12 @@
799800
]
800801
],
801802
'misc' => [
802-
'image' => 'https://ia802600.us.archive.org/20/items/dn2015-0220_vid/dn2015-0220.gif',
803+
'image' => 'https://ia801600.us.archive.org/34/items/dn2015-0220_vid/dn2015-0220.gif',
803804
'collection-title' => 'Democracy Now!'
804805
],
805806
'item' => [
806-
'downloads' => 132,
807-
'month' => 2,
807+
'downloads' => 156,
808+
'month' => 0,
808809
'item_size' => 3667677269,
809810
'files_count' => 68,
810811
'item_count' => null,

tests/fixtures/codepen.io.zhouzi-pen-jorazp.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
return [
55
'authorName' => 'Gabin Aureche',
6-
'authorUrl' => 'https://codepen.io/Zhouzi/',
6+
'authorUrl' => 'https://codepen.io/Zhouzi',
77
'cms' => null,
88
'code' => [
9-
'html' => '<iframe id="cp_embed_JoRazP" src="https://codepen.io/Zhouzi/embed/preview/JoRazP?height=300&amp;slug-hash=JoRazP&amp;default-tabs=js,result&amp;host=https://codepen.io" title="TheaterJS" scrolling="no" frameborder="0" height="300" allowtransparency="true" class="cp_embed_iframe" style="width: 100%; overflow: hidden;"></iframe>',
9+
'html' => '<iframe id="cp_embed_JoRazP" src="https://codepen.io/Zhouzi/embed/preview/JoRazP?default-tabs=js%2Cresult&amp;height=300&amp;host=https%3A%2F%2Fcodepen.io&amp;slug-hash=JoRazP" title="TheaterJS" scrolling="no" frameborder="0" height="300" allowtransparency="true" class="cp_embed_iframe" style="width: 100%; overflow: hidden;"></iframe>',
1010
'width' => 800,
1111
'height' => 300,
1212
'ratio' => 37.5
@@ -15,7 +15,7 @@
1515
'favicon' => 'https://codepen.io/favicon.ico',
1616
'feeds' => [],
1717
'icon' => null,
18-
'image' => 'https://assets.codepen.io/99102/internal/screenshots/pens/JoRazP.default.png?fit=cover&format=auto&ha=true&height=360&quality=75&v=2&version=1467971314&width=640',
18+
'image' => 'https://shots.codepen.io/username/pen/JoRazP-512.jpg?version=1467971314',
1919
'keywords' => [],
2020
'language' => 'en-US',
2121
'languages' => [],
@@ -35,13 +35,13 @@
3535
'provider_url' => 'https://codepen.io',
3636
'title' => 'TheaterJS',
3737
'author_name' => 'Gabin Aureche',
38-
'author_url' => 'https://codepen.io/Zhouzi/',
38+
'author_url' => 'https://codepen.io/Zhouzi',
3939
'height' => '300',
4040
'width' => '800',
4141
'thumbnail_width' => '384',
4242
'thumbnail_height' => '225',
43-
'thumbnail_url' => 'https://assets.codepen.io/99102/internal/screenshots/pens/JoRazP.default.png?fit=cover&amp;format=auto&amp;ha=true&amp;height=360&amp;quality=75&amp;v=2&amp;version=1467971314&amp;width=640',
44-
'html' => '<iframe id="cp_embed_JoRazP" src="https://codepen.io/Zhouzi/embed/preview/JoRazP?height=300&amp;slug-hash=JoRazP&amp;default-tabs=js,result&amp;host=https://codepen.io" title="TheaterJS" scrolling="no" frameborder="0" height="300" allowtransparency="true" class="cp_embed_iframe" style="width: 100%; overflow: hidden;"></iframe>'
43+
'thumbnail_url' => 'https://shots.codepen.io/username/pen/JoRazP-512.jpg?version=1467971314',
44+
'html' => '<iframe id="cp_embed_JoRazP" src="https://codepen.io/Zhouzi/embed/preview/JoRazP?default-tabs=js%2Cresult&amp;height=300&amp;host=https%3A%2F%2Fcodepen.io&amp;slug-hash=JoRazP" title="TheaterJS" scrolling="no" frameborder="0" height="300" allowtransparency="true" class="cp_embed_iframe" style="width: 100%; overflow: hidden;"></iframe>'
4545
],
4646
'allLinkedData' => []
4747
];

tests/fixtures/drive.google.com.file-d-0b2rwn8wabvswbmfjdudnv2vsttg-view.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
'cms' => null,
88
'code' => null,
99
'description' => null,
10-
'favicon' => 'https://ssl.gstatic.com/images/branding/product/1x/drive_2020q4_32dp.png',
10+
'favicon' => 'https://drive.google.com/favicon.ico',
1111
'feeds' => [],
1212
'icon' => null,
1313
'image' => null,
1414
'keywords' => [],
1515
'language' => null,
1616
'languages' => [],
1717
'license' => null,
18-
'providerName' => 'Google Docs',
18+
'providerName' => 'Google',
1919
'providerUrl' => 'https://drive.google.com',
2020
'publishedTime' => null,
2121
'redirect' => null,
22-
'title' => 'Entrevista_Rianxo_RadioFusion_150724.mp3',
22+
'title' => null,
2323
'url' => 'https://drive.google.com/file/d/0B2rwN8wAbVSWbmFJdUdnV2VSTTg/view',
2424
'linkedData' => [],
2525
'oEmbed' => [],

0 commit comments

Comments
 (0)