PageRenderTime 55ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/PHPUnit/Integration/BackwardsCompatibility1XTest.php

https://github.com/CodeYellowBV/piwik
PHP | 122 lines | 78 code | 24 blank | 20 comment | 4 complexity | 5fb33b9cbb1ce26ef8ed7fa2c7aae633 MD5 | raw file
Possible License(s): LGPL-3.0, JSON, MIT, GPL-3.0, LGPL-2.1, GPL-2.0, AGPL-1.0, BSD-2-Clause, BSD-3-Clause
  1. <?php
  2. /**
  3. * Piwik - free/libre analytics platform
  4. *
  5. * @link http://piwik.org
  6. * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  7. */
  8. use Piwik\Common;
  9. use Piwik\Db;
  10. use Piwik\Plugins\CoreUpdater\CoreUpdater;
  11. use Piwik\Plugins\VisitFrequency\API as VisitFrequencyApi;
  12. use Piwik\Updater;
  13. /**
  14. * Tests that Piwik 2.0 works w/ data from Piwik 1.12.
  15. */
  16. class Test_Piwik_Integration_BackwardsCompatibility1XTest extends IntegrationTestCase
  17. {
  18. const FIXTURE_LOCATION = '/tests/resources/piwik-1.13-dump.sql';
  19. public static $fixture = null; // initialized below class
  20. public static function setUpBeforeClass()
  21. {
  22. parent::setUpBeforeClass();
  23. self::updateDatabase();
  24. // truncate log tables so old data won't be re-archived
  25. foreach (array('log_visit', 'log_link_visit_action', 'log_conversion', 'log_conversion_item') as $table) {
  26. Db::query("TRUNCATE TABLE " . Common::prefixTable($table));
  27. }
  28. // add two visits from same visitor on dec. 29
  29. $t = Fixture::getTracker(1, '2012-12-29 01:01:30', $defaultInit = true);
  30. $t->setUrl('http://site.com/index.htm');
  31. $t->setIp('136.5.3.2');
  32. Fixture::checkResponse($t->doTrackPageView('incredible title!'));
  33. $t->setForceVisitDateTime('2012-12-29 03:01:30');
  34. $t->setUrl('http://site.com/other/index.htm');
  35. $t->DEBUG_APPEND_URL = '&_idvc=2'; // make sure visit is marked as returning
  36. Fixture::checkResponse($t->doTrackPageView('other incredible title!'));
  37. // launch archiving
  38. VisitFrequencyApi::getInstance()->get(1, 'year', '2012-12-29');
  39. }
  40. private static function updateDatabase()
  41. {
  42. $updater = new Updater();
  43. $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater);
  44. if (empty($componentsWithUpdateFile)) {
  45. throw new \Exception("Failed to update pre-2.0 database (nothing to update).");
  46. }
  47. $result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile);
  48. if (!empty($result['coreError'])
  49. && !empty($result['warnings'])
  50. && !empty($result['errors'])
  51. ) {
  52. throw new \Exception("Failed to update pre-2.0 database (errors or warnings found): " . print_r($result, true));
  53. }
  54. }
  55. public function setUp()
  56. {
  57. parent::setUp();
  58. $this->defaultApiNotToCall[] = 'Referrers';
  59. // changes made to SQL dump to test VisitFrequency change the day of week
  60. $this->defaultApiNotToCall[] = 'VisitTime.getByDayOfWeek';
  61. // we test VisitFrequency explicitly
  62. $this->defaultApiNotToCall[] = 'VisitFrequency.get';
  63. }
  64. /**
  65. * @dataProvider getApiForTesting
  66. * @group Integration
  67. */
  68. public function testApi($api, $params)
  69. {
  70. $this->runApiTests($api, $params);
  71. }
  72. public function getApiForTesting()
  73. {
  74. $idSite = 1;
  75. $dateTime = '2012-03-06 11:22:33';
  76. return array(
  77. array('all', array('idSite' => $idSite, 'date' => $dateTime,
  78. 'compareAgainst' => 'OneVisitorTwoVisits',
  79. 'disableArchiving' => true,
  80. // the Action.getPageTitles test fails for unknown reason, so skipping it
  81. // eg. https://travis-ci.org/piwik/piwik/jobs/24449365
  82. 'skipGetPageTitles' => true )),
  83. array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-03', 'setDateLastN' => true,
  84. 'disableArchiving' => true, 'testSuffix' => '_multipleDates')),
  85. array('VisitFrequency.get', array('idSite' => $idSite, 'date' => $dateTime,
  86. 'periods' => array('day', 'week', 'month', 'year'),
  87. 'disableArchiving' => false)),
  88. array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-06,2012-12-31',
  89. 'periods' => array('range'), 'disableArchiving' => true)),
  90. array('VisitFrequency.get', array('idSite' => $idSite, 'date' => '2012-03-03,2012-12-12', 'periods' => array('month'),
  91. 'testSuffix' => '_multipleOldNew', 'disableArchiving' => true))
  92. );
  93. }
  94. }
  95. Test_Piwik_Integration_BackwardsCompatibility1XTest::$fixture = new Piwik_Test_Fixture_SqlDump();
  96. Test_Piwik_Integration_BackwardsCompatibility1XTest::$fixture->dumpUrl =
  97. PIWIK_INCLUDE_PATH . Test_Piwik_Integration_BackwardsCompatibility1XTest::FIXTURE_LOCATION;
  98. Test_Piwik_Integration_BackwardsCompatibility1XTest::$fixture->tablesPrefix = 'piwiktests_';