diff --git a/phpstan.neon b/phpstan.neon index 9643cfb3..6084afbe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ parameters: level: 7 paths: - - maintenance/Rector + #- maintenance/Rector - src - tests @@ -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#' diff --git a/src/HttpClient/Plugin/CookiePlugin.php b/src/HttpClient/Plugin/CookiePlugin.php index 487ed6d6..8666f775 100644 --- a/src/HttpClient/Plugin/CookiePlugin.php +++ b/src/HttpClient/Plugin/CookiePlugin.php @@ -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; diff --git a/tests/GrabyFunctionalTest.php b/tests/GrabyFunctionalTest.php index 683827a3..0a9ef800 100644 --- a/tests/GrabyFunctionalTest.php +++ b/tests/GrabyFunctionalTest.php @@ -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();