diff options
author | Thomas Steur <thomas.steur@googlemail.com> | 2014-10-05 15:05:47 +0400 |
---|---|---|
committer | Thomas Steur <thomas.steur@googlemail.com> | 2014-10-05 15:05:47 +0400 |
commit | 5a1eab97f54b44f57356b4276b9c9df2a8eef51b (patch) | |
tree | 83864ece2806ccf6e6bb49abf3fd65de92c13ad8 /tests/PHPUnit/System/BackwardsCompatibility1XTest.php | |
parent | 19bcd2d262343eae9d553378e4c66ce7e033b4d8 (diff) |
refs #5940 put tests in correct folders, better testsuite names, some tests still fail and I cannot figure out why
Diffstat (limited to 'tests/PHPUnit/System/BackwardsCompatibility1XTest.php')
-rw-r--r-- | tests/PHPUnit/System/BackwardsCompatibility1XTest.php | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/PHPUnit/System/BackwardsCompatibility1XTest.php b/tests/PHPUnit/System/BackwardsCompatibility1XTest.php new file mode 100644 index 0000000000..5d20fa81a9 --- /dev/null +++ b/tests/PHPUnit/System/BackwardsCompatibility1XTest.php @@ -0,0 +1,122 @@ +<?php +/** + * 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\System; + +use Piwik\Common; +use Piwik\Db; +use Piwik\Plugins\VisitFrequency\API as VisitFrequencyApi; +use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Fixtures\SqlDump; +use Piwik\Tests\Fixture; + +/** + * Tests that Piwik 2.0 works w/ data from Piwik 1.12. + * + * @group BackwardsCompatibility1XTest + * @group Core + */ +class BackwardsCompatibility1XTest extends SystemTestCase +{ + const FIXTURE_LOCATION = '/tests/resources/piwik-1.13-dump.sql'; + + public static $fixture = null; // initialized below class + + 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)); + } + + // add two visits from same visitor on dec. 29 + $t = Fixture::getTracker(1, '2012-12-29 01:01:30', $defaultInit = true); + $t->setUrl('http://site.com/index.htm'); + $t->setIp('136.5.3.2'); + Fixture::checkResponse($t->doTrackPageView('incredible title!')); + + $t->setForceVisitDateTime('2012-12-29 03:01:30'); + $t->setUrl('http://site.com/other/index.htm'); + $t->DEBUG_APPEND_URL = '&_idvc=2'; // make sure visit is marked as returning + Fixture::checkResponse($t->doTrackPageView('other incredible title!')); + + // launch archiving + VisitFrequencyApi::getInstance()->get(1, 'year', '2012-12-29'); + } + + /** + * @dataProvider getApiForTesting + */ + public function testApi($api, $params) + { + // note: not sure why I have to manually activate plugin in order for `./console tests:run BackwardsCompatibility1XTest` to work + try { + \Piwik\Plugin\Manager::getInstance()->activatePlugin('DevicesDetection'); + } catch(\Exception $e) { + } + + $this->runApiTests($api, $params); + } + + public function getApiForTesting() + { + $idSite = 1; + $dateTime = '2012-03-06 11:22:33'; + + $apiNotToCall = array( + // in the SQL dump, a referrer is named referer.com, but now in OneVisitorTwoVisits it is referrer.com + 'Referrers', + + // changes made to SQL dump to test VisitFrequency change the day of week + 'VisitTime.getByDayOfWeek', + + // we test VisitFrequency explicitly + 'VisitFrequency.get', + + // the Action.getPageTitles test fails for unknown reason, so skipping it + // eg. https://travis-ci.org/piwik/piwik/jobs/24449365 + 'Action.getPageTitles' + ); + + return array( + array('all', array('idSite' => $idSite, 'date' => $dateTime, + 'compareAgainst' => 'OneVisitorTwoVisits', + 'disableArchiving' => true, + 'apiNotToCall' => $apiNotToCall, + 'otherRequestParameters' => array( + 'hideColumns' => 'nb_users', + ))), + + array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-03', 'setDateLastN' => true, + 'disableArchiving' => true, 'testSuffix' => '_multipleDates')), + + array('VisitFrequency.get', array('idSite' => $idSite, 'date' => $dateTime, + 'periods' => array('day', 'week', 'month', 'year'), + 'disableArchiving' => false)), + + array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-06,2012-12-31', + 'periods' => array('range'), 'disableArchiving' => true)), + + array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-03,2012-12-12', 'periods' => array('month'), + 'testSuffix' => '_multipleOldNew', 'disableArchiving' => true)) + ); + } +} + +BackwardsCompatibility1XTest::$fixture = new SqlDump(); +BackwardsCompatibility1XTest::$fixture->dumpUrl = PIWIK_INCLUDE_PATH . BackwardsCompatibility1XTest::FIXTURE_LOCATION; +BackwardsCompatibility1XTest::$fixture->tablesPrefix = ''; |