diff --git a/src/EuCookieConsent.php b/src/EuCookieConsent.php index 6032604..5382e1e 100644 --- a/src/EuCookieConsent.php +++ b/src/EuCookieConsent.php @@ -82,7 +82,7 @@ private static function getCookie(string $cookieName) */ public static function getPopup($forced = false) { - if(!$forced && !empty($_COOKIE[config('eu-cookie-consent.cookie_name')])){ + if(!$forced && !empty(request()->cookie(config('eu-cookie-consent.cookie_name')))){ return ''; } diff --git a/tests/EuCookieConsentTest.php b/tests/EuCookieConsentTest.php index 10faf6c..896481d 100644 --- a/tests/EuCookieConsentTest.php +++ b/tests/EuCookieConsentTest.php @@ -30,11 +30,23 @@ public function getPopup_returns_html_if_cookie_is_not_set() } /** @test */ - public function getPopup_returns_empty_string_if_cookie_is_not_set() + public function getHTML_returns_empty_string_if_cookie_is_not_set() { $html = EuCookieConsent::getHTML('header'); $this->assertEmpty($html); } + /** + * @test + */ + public function getPopup_returns_empty_string_if_cookie_is_set() + { + $response = $this->call('POST', '/saveTheCookie', ['session'=>'1', 'xsrf-token'=>'1'], ['laravel_eu_cookie_consent'=>json_encode(['session'=>'1', 'xsrf-token'=>'1'])]); + $response->assertCookie('laravel_eu_cookie_consent', '{"session":"1","xsrf-token":"1"}', false); + + $response = EuCookieConsent::getPopup(); + $this->assertEquals('', $response); + } + }