Skip to content
Extraits de code Groupes Projets
JsProxyTest.php 2,65 ko
Newer Older
  • Learn to ignore specific revisions
  • diosmosis's avatar
    diosmosis a validé
    /**
     * Piwik - free/libre analytics platform
     *
     * @link http://piwik.org
     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
     */
    
    
    namespace Piwik\Tests\Integration;
    
    
    diosmosis's avatar
    diosmosis a validé
    
    
    /**
     * @group Core
     */
    class JsProxyTest extends \PHPUnit_Framework_TestCase
    
        public function testPiwikJs()
    
        {
            $curlHandle = curl_init();
            curl_setopt($curlHandle, CURLOPT_URL, $this->getStaticSrvUrl() . '/js/');
            curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
            $fullResponse = curl_exec($curlHandle);
            $responseInfo = curl_getinfo($curlHandle);
            curl_close($curlHandle);
    
    
            $this->assertEquals(200, $responseInfo["http_code"], 'Ok response');
    
    
            $piwik_js = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
    
            $this->assertEquals($piwik_js, $fullResponse, 'script content');
        }
    
    
        public function testPiwikJsNoComment()
    
        {
            $curlHandle = curl_init();
            curl_setopt($curlHandle, CURLOPT_URL, $this->getStaticSrvUrl() . '/js/tracker.php');
            curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
            $fullResponse = curl_exec($curlHandle);
            $responseInfo = curl_getinfo($curlHandle);
            curl_close($curlHandle);
    
            $this->assertEquals(200, $responseInfo["http_code"], 'Ok response');
    
            $piwikJs = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . '/piwik.js');
            $piwikNoCommentJs = substr($piwikJs, strpos($piwikJs, "*/\n") + 3);
            $this->assertEquals($piwikNoCommentJs, $fullResponse, 'script content (if comment shows, $byteStart value in /js/tracker.php)');
    
        public function testPiwikPhp()
    
        {
            $curlHandle = curl_init();
    
            $url = $this->getStaticSrvUrl() . '/js/?idsite=1';
    
            curl_setopt($curlHandle, CURLOPT_URL, $url);
            curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
            $fullResponse = curl_exec($curlHandle);
            $responseInfo = curl_getinfo($curlHandle);
            curl_close($curlHandle);
    
    
            $this->assertEquals(200, $responseInfo["http_code"], var_export($responseInfo, true));
    
            $expected = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==";
            $processed = base64_encode($fullResponse);
            if ($expected != $processed) {
                $this->markTestSkipped("testPiwikPhp invalid response content: " . $fullResponse);
    
    mattab's avatar
    mattab a validé
                'checking for image content' . "\n\n\n\nRaw content: \n\n\n" . $fullResponse
    
        }
    
        /**
         * Helper methods
         */
        private function getStaticSrvUrl()
        {
    
            return Fixture::getRootUrl();