/** * Test that removeCookie leaves non-cookie headers * * @runInSeparateProcess * @covers Mixpanel\DataStorage\Cookie::storeState * @covers Mixpanel\DataStorage\Cookie::setHeader * @covers Mixpanel\DataStorage\Cookie::getState * @covers Mixpanel\DataStorage\Cookie::getStorageKey * @covers Mixpanel\DataStorage\Cookie::getLifetime * @covers Mixpanel\DataStorage\Cookie::getCookiePath * @covers Mixpanel\DataStorage\Cookie::getCookieDomain * @covers Mixpanel\DataStorage\Cookie::getHeaderList * @covers Mixpanel\DataStorage\Cookie::removeHeader * @covers Mixpanel\DataStorage\Cookie::removeCookie */ public function testRemoveCookieLeavesNonCookieHeaders() { $aweHeader = 'X-The-Sum-Of-Awe: http://tech.vg.no/'; $setHeader = new ReflectionMethod('Mixpanel\\DataStorage\\Cookie', 'setHeader'); $setHeader->setAccessible(true); $setHeader->invoke($this->cookie, $aweHeader); $this->cookie->set('mix', 'panel'); $this->cookie->set('foo', 'bar'); $getHeaderList = new ReflectionMethod('Mixpanel\\DataStorage\\Cookie', 'getHeaderList'); $getHeaderList->setAccessible(true); $headers = $getHeaderList->invoke($this->cookie); $mpCookies = 0; $sumOfAwe = 0; foreach ($headers as $header) { if (preg_match('#^Set-Cookie:\\s*' . preg_quote($this->cookieName) . '=#', $header)) { $mpCookies++; } else { if ($header == $aweHeader) { $sumOfAwe++; } } } $this->assertSame(1, $mpCookies); $this->assertSame(1, $sumOfAwe); }
/** * Gets an instance of a data storage adapter * * @return StorageInterface */ public function getDataStorage() { if (!is_null($this->storage)) { return $this->storage; } // Use default data storage (cookie-based) $cookie = new DataStorage\Cookie(); $cookie->setProjectToken($this->token); // Set data storage adapter $this->setDataStorage($cookie); // Only set user ID after data storage has been initialized $this->storage->setUserUuid($this->getDistinctId()); return $this->storage; }