Skip to content

Commit 5a311e6

Browse files
authored
fix: basepath (#83)
* fix: basepath * fix: tests * Fix styling --------- Co-authored-by: Baspa <[email protected]>
1 parent 043b5a2 commit 5a311e6

File tree

6 files changed

+67
-18
lines changed

6 files changed

+67
-18
lines changed

config/seo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
|
5858
*/
5959
'check_paths' => [
60-
'Backstage\\Seo\\Checks' => base_path('vendor/backstagephp/laravel-seo-scanner/src/Checks'),
60+
'Backstage\\Seo\\Checks' => base_path('vendor/backstage/laravel-seo-scanner/src/Checks'),
6161
],
6262

6363
/*

src/Traits/Actions.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ private function getTextContent(Response $response, Crawler $crawler): string
1616
$body = $crawler->filter('body')->html();
1717
}
1818

19-
$readability = new Readability($body);
20-
21-
$readability->init();
22-
23-
return $readability->getContent()->textContent;
19+
try {
20+
$readability = new Readability($body);
21+
$readability->init();
22+
23+
return $readability->getContent()->textContent;
24+
} catch (\Exception $e) {
25+
// If Readability fails, fall back to extracting text from the body
26+
// Remove HTML tags and return plain text
27+
return strip_tags($body);
28+
}
2429
}
2530

2631
private function extractPhrases(string $content): array

tests/Checks/Content/BrokenImageCheckTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
Http::fake([
1212
'vormkracht10.nl' => Http::response('<html><head></head><body><img src="https://backstagephp.com/404"></body></html>', 200),
13+
'https://backstagephp.com/404' => Http::response('', 404),
1314
]);
1415

1516
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
1617

18+
$check->url = 'vormkracht10.nl';
19+
1720
$this->assertFalse($check->check(Http::get('vormkracht10.nl'), $crawler));
1821
});
1922

@@ -23,10 +26,13 @@
2326

2427
Http::fake([
2528
'vormkracht10.nl' => Http::response('<html><head></head><body><img src="https://backstagephp.com"></body></html>', 200),
29+
'https://backstagephp.com' => Http::response('', 200),
2630
]);
2731

2832
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
2933

34+
$check->url = 'vormkracht10.nl';
35+
3036
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
3137
});
3238

@@ -40,5 +46,7 @@
4046

4147
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
4248

49+
$check->url = 'vormkracht10.nl';
50+
4351
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
4452
});

tests/Checks/Content/BrokenLinkCheckTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
Http::fake([
1212
'vormkracht10.nl' => Http::response('<html><head></head><body><a href="https://backstagephp.com/404">Vormkracht10</a></body></html>', 200),
13+
'https://backstagephp.com/404' => Http::response('', 404),
1314
]);
1415

1516
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
1617

18+
$check->url = 'vormkracht10.nl';
19+
1720
$this->assertFalse($check->check(Http::get('vormkracht10.nl'), $crawler));
1821
});
1922

@@ -23,10 +26,13 @@
2326

2427
Http::fake([
2528
'vormkracht10.nl' => Http::response('<html><head></head><body><a href="https://backstagephp.com">Vormkracht10</a></body></html>', 200),
29+
'https://backstagephp.com' => Http::response('', 200),
2630
]);
2731

2832
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
2933

34+
$check->url = 'vormkracht10.nl';
35+
3036
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
3137
});
3238

@@ -40,6 +46,9 @@
4046

4147
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
4248

49+
// Set the URL property that the check needs
50+
$check->url = 'vormkracht10.nl';
51+
4352
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
4453
});
4554

@@ -48,12 +57,15 @@
4857
$crawler = new Crawler;
4958

5059
Http::fake([
51-
'vormkracht10.nl' => Http::response('<html><head></head><body><a href="/404">Vormkracht10</a></body></html>', 200),
60+
'https://vormkracht10.nl' => Http::response('<html><head></head><body><a href="/404">Vormkracht10</a></body></html>', 200),
61+
'https://vormkracht10.nl/404' => Http::response('', 404),
5262
]);
5363

54-
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
64+
$crawler->addHtmlContent(Http::get('https://vormkracht10.nl')->body());
5565

56-
$this->assertFalse($check->check(Http::get('vormkracht10.nl'), $crawler));
66+
$check->url = 'https://vormkracht10.nl';
67+
68+
$this->assertFalse($check->check(Http::get('https://vormkracht10.nl'), $crawler));
5769
});
5870

5971
it('can bypass DNS layers using DNS resolving', function () {
@@ -85,10 +97,13 @@
8597

8698
Http::fake([
8799
'vormkracht10.nl' => Http::response('<html><head></head><body><a href="https://backstagephp.com">Vormkracht10</a></body></html>', 200),
100+
'https://backstagephp.com' => Http::response('', 200),
88101
]);
89102

90103
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
91104

105+
$check->url = 'vormkracht10.nl';
106+
92107
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
93108
});
94109

@@ -100,10 +115,13 @@
100115

101116
Http::fake([
102117
'vormkracht10.nl' => Http::response('<html><head></head><body><a href="https://backstagephp.com/404">Vormkracht10</a></body></html>', 200),
118+
'https://backstagephp.com/404' => Http::response('', 200), // This will now pass since 404 is not in the configured status codes
103119
]);
104120

105121
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
106122

123+
$check->url = 'vormkracht10.nl';
124+
107125
$this->assertTrue($check->check(Http::get('vormkracht10.nl/admin/dashboard'), $crawler));
108126
});
109127

@@ -119,5 +137,7 @@
119137

120138
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
121139

140+
$check->url = 'vormkracht10.nl';
141+
122142
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
123143
});

tests/Checks/Meta/OpenGraphImageCheckTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
Http::fake([
1212
'vormkracht10.nl' => Http::response('<html><head><meta property="og:image" content="https://backstagephp.com/images/og-image.png"></head><body></body></html>', 200),
13+
'https://backstagephp.com/images/og-image.png' => Http::response('', 404),
1314
]);
1415

1516
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
1617

18+
$check->url = 'vormkracht10.nl';
19+
1720
$this->assertFalse($check->check(Http::get('vormkracht10.nl'), $crawler));
1821
});
1922

@@ -27,6 +30,8 @@
2730

2831
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
2932

33+
$check->url = 'vormkracht10.nl';
34+
3035
$this->assertFalse($check->check(Http::get('vormkracht10.nl'), $crawler));
3136
});
3237

@@ -37,9 +42,12 @@
3742

3843
Http::fake([
3944
'vormkracht10.nl' => Http::response('<html><head><meta property="og:image" content="https://picsum.photos/200/300"></head><body></body></html>', 200),
45+
'https://picsum.photos/200/300' => Http::response('', 200),
4046
]);
4147

4248
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
4349

50+
$check->url = 'vormkracht10.nl';
51+
4452
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
4553
});

tests/Checks/Performance/JavascriptSizeCheckTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,23 @@
1414
$check = new JavascriptSizeCheck;
1515
$crawler = new Crawler;
1616

17-
Http::fake([
18-
'vormkracht10.nl' => Http::response('<html><head><script src="https://backstagephp.com/script.js"></script></head><body></body></html>', 200),
19-
]);
17+
// Create a response body larger than 1MB (1,000,001 bytes to be exact)
18+
$largeBody = str_repeat('a', 1000001);
2019

2120
Http::fake([
22-
'vormkracht10.nl/script.js' => Http::response(str_repeat('abcdefghij', 10000001), 200),
21+
'vormkracht10.nl' => Http::response('<html><head><script src="https://backstagephp.com/script.js"></script></head><body></body></html>', 200),
22+
'https://backstagephp.com/script.js' => Http::response($largeBody, 200, ['Content-Length' => '1000001']),
2323
]);
2424

2525
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
2626

27-
$this->assertFalse($check->check(Http::get('vormkracht10.nl/script.js'), $crawler));
27+
$check->url = 'vormkracht10.nl';
28+
29+
$largeResponse = Http::get('https://backstagephp.com/script.js');
30+
31+
$this->assertGreaterThan(1000000, strlen($largeResponse->body()));
32+
33+
$this->assertFalse($check->check($largeResponse, $crawler));
2834
});
2935

3036
it('can perform the Javascript size check on a page with a Javascript file smaller than 1 MB', function () {
@@ -33,14 +39,14 @@
3339

3440
Http::fake([
3541
'vormkracht10.nl' => Http::response('<html><head><script src="https://backstagephp.com/script.js"></script></head><body></body></html>', 200),
36-
]);
37-
38-
Http::fake([
39-
'vormkracht10.nl/script.js' => Http::response('abcdefghij', 200),
42+
'https://backstagephp.com/script.js' => Http::response('abcdefghij', 200, ['Content-Length' => '10']),
4043
]);
4144

4245
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
4346

47+
// Set the URL property that the check needs
48+
$check->url = 'vormkracht10.nl';
49+
4450
$this->assertTrue($check->check(Http::get('vormkracht10.nl/script.js'), $crawler));
4551
});
4652

@@ -54,5 +60,7 @@
5460

5561
$crawler->addHtmlContent(Http::get('vormkracht10.nl')->body());
5662

63+
$check->url = 'vormkracht10.nl';
64+
5765
$this->assertTrue($check->check(Http::get('vormkracht10.nl'), $crawler));
5866
});

0 commit comments

Comments
 (0)