Exemple #1
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $testingEnvironment = new \Piwik\Tests\Framework\TestingEnvironmentVariables();
     $testingEnvironment->configFileLocal = PIWIK_INCLUDE_PATH . '/plugins/Installation/tests/resources/config.ini.php';
     $testingEnvironment->save();
 }
 public function setUp()
 {
     parent::setUp();
     $self = $this;
     Piwik::addAction('API.Request.dispatch.end', function (&$return, $extra) use($self) {
         if ($extra['module'] !== 'Events') {
             return;
         }
         /** @var DataTable $return*/
         // we make sure processed result is the same at any time
         foreach ($return as &$value) {
             $value->setColumn('sum_event_value', '2');
             $value->setColumn('max_event_value', '2');
             $value->setColumn('min_event_value', '2');
             $value->setColumn('sum_daily_nb_uniq_visitors', '2');
             $value->setColumn('avg_event_value', '2');
             if ($value->isSubtableLoaded()) {
                 $subtable = $value->getSubtable();
                 foreach ($subtable->getRows() as $row) {
                     $row->setColumn('sum_event_value', '2');
                     $row->setColumn('max_event_value', '2');
                     $row->setColumn('min_event_value', '2');
                     $row->setColumn('sum_daily_nb_uniq_visitors', '2');
                     $row->setColumn('avg_event_value', '2');
                 }
             }
         }
     });
 }
Exemple #3
0
 public function setUp()
 {
     parent::setUp();
     $this->api = API::getInstance();
     $this->setSuperUser();
     $this->createSite();
 }
 public function setUp()
 {
     parent::setUp();
     $this->application = new TestConsole(self::$fixture->piwikEnvironment);
     $this->application->setAutoExit(false);
     $this->applicationTester = new ApplicationTester($this->application);
 }
 public function setUp()
 {
     parent::setUp();
     if (!Fixture::siteCreated($this->idSite)) {
         Fixture::createWebsite('2014-01-01 00:00:00');
     }
 }
 public function setUp()
 {
     parent::setUp();
     if (!Fixture::siteCreated($this->idSite)) {
         Fixture::createWebsite('2010-00-00 00:00:00');
     }
     $this->dao = new RawLogDao();
 }
Exemple #7
0
 public function setUp()
 {
     parent::setUp();
     StaticCache::clearAll();
     PluginAwareStaticCache::clearAll();
     Translate::reloadLanguage('en');
     $this->api = API::getInstance();
 }
 public function setUp()
 {
     parent::setUp();
     $application = new Console();
     $application->setAutoExit(false);
     $this->applicationTester = new ApplicationTester($application);
     Config::unsetInstance();
 }
Exemple #9
0
 public function test_sortFilesDescByPathLength_shouldNotChangeOrder_IfAllHaveSameLength()
 {
     $input = array('xyz/1.gif', 'x/xyz.gif', 'xxyyzzgg');
     $result = Filesystem::sortFilesDescByPathLength($input);
     if (SystemTestCase::isPhp7orLater()) {
         $input = array('x/xyz.gif', 'xyz/1.gif', 'xxyyzzgg');
     }
     $this->assertEquals($input, $result);
 }
Exemple #10
0
 public function setUp()
 {
     parent::setUp();
     $this->cliMulti = new CliMulti();
     $this->authToken = Fixture::getTokenAuth();
     $this->urls = array('getAnswerToLife' => $this->completeUrl('?module=API&method=ExampleAPI.getAnswerToLife&format=JSON'), 'getPiwikVersion' => $this->completeUrl('?module=API&method=API.getPiwikVersion&format=JSON'));
     $this->responses = array('getAnswerToLife' => '{"value":42}', 'getPiwikVersion' => '{"value":"' . Version::VERSION . '"}');
     \Piwik\Common::$isCliMode = true;
 }
 public function setUp()
 {
     parent::setUp();
     $testingEnvironment = new \Piwik\Tests\Framework\TestingEnvironmentVariables();
     $testingEnvironment->configFileGlobal = null;
     $testingEnvironment->configFileLocal = null;
     $testingEnvironment->configFileCommon = null;
     $testingEnvironment->loadRealTranslations = true;
     $testingEnvironment->save();
 }
 public function testOrderByShouldListAllHighestPositiveValuesFirstThenAllNegativeValuesLowestFirst()
 {
     $this->table->addRowsFromArray(array(array(Row::COLUMNS => array('label' => 'pos1', 'growth' => 12)), array(Row::COLUMNS => array('label' => 'pos2', 'growth' => 7)), array(Row::COLUMNS => array('label' => 'neg1', 'growth' => -9)), array(Row::COLUMNS => array('label' => 'pos3', 'growth' => 10)), array(Row::COLUMNS => array('label' => 'neg2', 'growth' => -11)), array(Row::COLUMNS => array('label' => 'neg3', 'growth' => -13)), array(Row::COLUMNS => array('label' => 'pos4', 'growth' => 9)), array(Row::COLUMNS => array('label' => 'pos5', 'growth' => 10)), array(Row::COLUMNS => array('label' => 'pos6', 'growth' => 0)), array(Row::COLUMNS => array('label' => 'neg4', 'growth' => -7)), array(Row::COLUMNS => array('label' => 'neg5', 'growth' => -8))));
     $this->applyOrderByFilter();
     if (SystemTestCase::isPhp7orLater()) {
         $this->assertOrder(array('pos1', 'pos3', 'pos5', 'pos4', 'pos2', 'pos6', 'neg3', 'neg2', 'neg1', 'neg5', 'neg4'));
     } else {
         $this->assertOrder(array('pos1', 'pos5', 'pos3', 'pos4', 'pos2', 'pos6', 'neg3', 'neg2', 'neg1', 'neg5', 'neg4'));
     }
 }
 public function setUp()
 {
     parent::setUp();
     $idSite = 1;
     $dateTime = '2014-01-01 00:00:01';
     if (!Fixture::siteCreated($idSite)) {
         Fixture::createWebsite($dateTime);
     }
     $this->tracker = Fixture::getTracker($idSite, $dateTime, $defaultInit = true);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // add duplicates for every action
     $table = Common::prefixTable('log_action');
     foreach (Db::fetchAll("SELECT * FROM {$table}") as $row) {
         $insertSql = "INSERT INTO {$table} (name, type, hash, url_prefix)\n                               VALUES (?, ?, CRC32(?), ?)";
         Db::query($insertSql, array($row['name'], $row['type'], $row['name'], $row['url_prefix']));
     }
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $extraSite = Fixture::createWebsite(self::$fixture->dateTime, $ecommerce = 1, "the site");
     Piwik::addAction("ArchiveProcessor.Parameters.getIdSites", function (&$sites, $period) use($extraSite) {
         if (reset($sites) == $extraSite) {
             $sites = array(1, 2, 3);
         }
     });
     Config::getInstance()->General['enable_processing_unique_visitors_multiple_sites'] = 1;
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     DbHelper::createAnonymousUser();
     // the api_internal_call.php uses idSite=7, so we create 7 sites
     for ($i = 0; $i != 7; ++$i) {
         Fixture::createWebsite("2011-01-01 00:00:00", $ecommerce = 1, $siteName = "Site #{$i}");
     }
     // the script uses anonymous token auth, so give the anonymous user access
     \Piwik\Plugins\UsersManager\API::getInstance()->setUserAccess('anonymous', 'view', array(7));
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     // note: not sure why I have to manually install plugin
     \Piwik\Plugin\Manager::getInstance()->loadPlugin('CustomAlerts')->install();
     $result = Fixture::updateDatabase();
     if ($result === false) {
         throw new \Exception("Failed to update pre-2.0 database (nothing to update).");
     }
     // truncate log tables so old data won't be re-archived
     foreach (array('log_visit', 'log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) {
         Db::query("TRUNCATE TABLE " . Common::prefixTable($table));
     }
     self::trackTwoVisitsOnSameDay();
     // launch archiving
     VisitFrequencyApi::getInstance()->get(1, 'year', '2012-12-29');
 }
Exemple #18
0
 /**
  * Given a list of default parameters to set, returns the URLs of APIs to call
  * If any API was specified in $this->apiNotToCall we ensure only these are tested.
  * If any API is set as excluded (see list below) then it will be ignored.
  *
  * @param array $parametersToSet Parameters to set in api call
  * @param array $formats         Array of 'format' to fetch from API
  * @param array $periods         Array of 'period' to query API
  * @param bool  $supertableApi
  * @param bool  $setDateLastN    If set to true, the 'date' parameter will be rewritten to query instead a range of dates, rather than one period only.
  * @param bool|string $language        2 letter language code, defaults to default piwik language
  * @param bool|string $fileExtension
  *
  * @throws Exception
  *
  * @return array of API URLs query strings
  */
 protected function generateApiUrlPermutations($parametersToSet)
 {
     $formats = array($this->testConfig->format);
     $originalDate = $parametersToSet['date'];
     $requestUrls = array();
     $apiMetadata = new DocumentationGenerator();
     // Get the URLs to query against the API for all functions starting with get*
     foreach ($this->getAllApiMethods() as $apiMethodInfo) {
         list($class, $moduleName, $methodName) = $apiMethodInfo;
         $apiId = $moduleName . '.' . $methodName;
         foreach ($this->testConfig->periods as $period) {
             $parametersToSet['period'] = $period;
             // If date must be a date range, we process this date range by adding 6 periods to it
             if ($this->testConfig->setDateLastN) {
                 if (!isset($parametersToSet['dateRewriteBackup'])) {
                     $parametersToSet['dateRewriteBackup'] = $parametersToSet['date'];
                 }
                 $lastCount = $this->testConfig->setDateLastN;
                 $secondDate = date('Y-m-d', strtotime("+{$lastCount} " . $period . "s", strtotime($originalDate)));
                 $parametersToSet['date'] = $originalDate . ',' . $secondDate;
             }
             // Set response language
             if ($this->testConfig->language !== false) {
                 $parametersToSet['language'] = $this->testConfig->language;
             }
             // set idSubtable if subtable API is set
             if ($this->testConfig->supertableApi !== false) {
                 $request = new Request(array('module' => 'API', 'method' => $this->testConfig->supertableApi, 'idSite' => $parametersToSet['idSite'], 'period' => $parametersToSet['period'], 'date' => $parametersToSet['date'], 'format' => 'php', 'serialize' => 0));
                 $content = $request->process();
                 SystemTestCase::assertApiResponseHasNoError($content);
                 // find first row w/ subtable
                 foreach ($content as $row) {
                     if (isset($row['idsubdatatable'])) {
                         $parametersToSet['idSubtable'] = $row['idsubdatatable'];
                         break;
                     }
                 }
                 // if no subtable found, throw
                 if (!isset($parametersToSet['idSubtable'])) {
                     throw new Exception("Cannot find subtable to load for {$apiId} in {$this->testConfig->supertableApi}.");
                 }
             }
             // Generate for each specified format
             foreach ($formats as $format) {
                 $parametersToSet['format'] = $format;
                 $parametersToSet['hideIdSubDatable'] = 1;
                 $parametersToSet['serialize'] = 1;
                 $exampleUrl = $apiMetadata->getExampleUrl($class, $methodName, $parametersToSet);
                 if ($exampleUrl === false) {
                     continue;
                 }
                 // Remove the first ? in the query string
                 $exampleUrl = substr($exampleUrl, 1);
                 $apiRequestId = $apiId;
                 if (strpos($exampleUrl, 'period=') !== false) {
                     $apiRequestId .= '_' . $period;
                 }
                 $apiRequestId .= '.' . $format;
                 if ($this->testConfig->fileExtension) {
                     $apiRequestId .= '.' . $this->testConfig->fileExtension;
                 }
                 $requestUrls[$apiRequestId] = UrlHelper::getArrayFromQueryString($exampleUrl);
             }
         }
     }
     return $requestUrls;
 }
 public function setUp()
 {
     parent::setUp();
     $this->resetTestingEnvironmentChanges();
 }
 protected function tearDown()
 {
     parent::tearDown();
 }
Exemple #21
0
 /**
  * @return string
  */
 protected static function getPythonBinary()
 {
     if (SettingsServer::isWindows()) {
         return "C:\\Python27\\python.exe";
     }
     if (SystemTestCase::isTravisCI()) {
         return 'python2.6';
     }
     return 'python';
 }
 public static function setUpBeforeClass()
 {
     self::setUpConfigOptions();
     parent::setUpBeforeClass();
 }
 public function tearDown()
 {
     parent::tearDown();
     // reset that value after the test
     Proxy::getInstance()->setHideIgnoredFunctions(true);
 }
Exemple #24
0
        }
    }
    public function assertHttpResponseText($expectedResponseText, $url, $message = '')
    {
        self::assertThat($url, new HttpResponseText($expectedResponseText), $message);
    }
    public function assertResponseCode($expectedResponseCode, $url, $message = '')
    {
        self::assertThat($url, new ResponseCode($expectedResponseCode), $message);
    }
    public function assertNotDbConnectionCreated($message = 'A database connection was created but should not.')
    {
        self::assertFalse(Db::hasDatabaseObject(), $message);
    }
    public function assertDbConnectionCreated($message = 'A database connection was not created but should.')
    {
        self::assertTrue(Db::hasDatabaseObject(), $message);
    }
    /**
     * Use this method to return custom container configuration that you want to apply for the tests.
     * This configuration will override Fixture config.
     *
     * @return array
     */
    public static function provideContainerConfigBeforeClass()
    {
        return array();
    }
}
SystemTestCase::$fixture = new \Piwik\Tests\Framework\Fixture();
 public function setUp()
 {
     Cache::getTransientCache()->flushAll();
     parent::setUp();
 }
 public static function tearDownAfterClass()
 {
     // only drop the database if PIWIK_BENCHMARK_DATABASE isn't set
     $dropDatabase = empty($GLOBALS['PIWIK_BENCHMARK_DATABASE']);
     parent::_tearDownAfterClass($dropDatabase);
 }
Exemple #27
0
 public function setUp()
 {
     parent::setUp();
     $this->model = new Model();
 }
Exemple #28
0
 private function normalizeEncodingPhp533($apiResponse)
 {
     if (!SystemTestCase::isPhpVersion53() || strpos($apiResponse, '<result') === false) {
         return $apiResponse;
     }
     return str_replace('&amp;#039;', "'", $apiResponse);
 }
Exemple #29
0
 /**
  * Resets all caches and drops the database
  */
 public function tearDown()
 {
     static::$fixture->clearInMemoryCaches();
     static::$fixture->destroyEnvironment();
     parent::tearDown();
 }
 public function tearDown()
 {
     parent::tearDownAfterClass();
 }