Skip to content

Commit

Permalink
Merge e3504a5 into a7aecce
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r authored Jun 30, 2022
2 parents a7aecce + e3504a5 commit 4573755
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
6 changes: 1 addition & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
parameters:
level: 7
paths:
- maintenance/Rector
#- maintenance/Rector
- src
- tests

Expand All @@ -20,10 +20,6 @@ parameters:
-
message: '#\$innerHTML#'
path: %currentWorkingDirectory%
# can't find a way to cast or properly defined some return elements
-
message: '#DOMNode, object given#'
path: %currentWorkingDirectory%/src/Extractor/ContentExtractor.php
# other stuff I might have fucked up with DOM* classes
-
message: '#DOMNode::\$tagName#'
Expand Down
3 changes: 2 additions & 1 deletion src/HttpClient/Plugin/CookiePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function __construct(CookieJar $cookieJar)
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
{
$cookies = [];
// inject cookies previously defined (like when it's defined in site config)
$cookies = $request->getHeader('Cookie');
foreach ($this->cookieJar->getCookies() as $cookie) {
if ($cookie->isExpired()) {
continue;
Expand Down
31 changes: 31 additions & 0 deletions tests/GrabyFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,37 @@ public function testCookie(): void
$this->assertSame('Michael Flynn\'s Contradictory Line On Russia', $res['title']);
}

public function testCookieOnMultiplePages(): void
{
// Rector: do not add mock client – we are testing if the cookie is set.
$graby = new Graby([
'debug' => true,
'extractor' => [
'config_builder' => [
'site_config' => [__DIR__ . '/fixtures/site_config'],
],
],
]);
$res = $graby->fetchContent('https://www.golem.de/news/app-entwicklung-cross-platform-oder-nativ-programmieren-2202-162600.html');

$this->assertCount(11, $res);

$this->assertArrayHasKey('status', $res);
$this->assertArrayHasKey('html', $res);
$this->assertArrayHasKey('title', $res);
$this->assertArrayHasKey('language', $res);
$this->assertArrayHasKey('date', $res);
$this->assertArrayHasKey('authors', $res);
$this->assertArrayHasKey('url', $res);
$this->assertArrayHasKey('summary', $res);
$this->assertArrayHasKey('image', $res);
$this->assertArrayHasKey('native_ad', $res);
$this->assertArrayHasKey('headers', $res);

$this->assertSame(200, $res['status']);
$this->assertStringNotContainsString('Golem.de mit Cookies', $res['html']);
}

public function testSaveXmlUnknownEncoding(): void
{
$httpMockClient = new HttpMockClient();
Expand Down

0 comments on commit 4573755

Please sign in to comment.