diff options
167 files changed, 1348 insertions, 1177 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a02516f4..172c780bfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,6 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API' ## Piwik 2.8.0 -### New API Features -* The pivotBy and related query parameters can be used to pivot reports by another dimension. Read more about the new query parameters [here](http://developer.piwik.org/api-reference/reporting-api#optional-api-parameters). - -### Library updates -* Updated AngularJS from 1.2.13 to 1.2.25 - ### Breaking Changes * The Auth interface has been modified, existing Auth implementations will have to be modified. Changes include: * The initSession method has been moved. Since this behavior must be executed for every Auth implementation, it has been put into a new class: SessionInitializer. @@ -23,7 +17,17 @@ This is a changelog for Piwik platform developers. All changes for our HTTP API' * `Piwik\Unzip\UncompressInterface` has been moved and renamed to `Piwik\Decompress\DecompressInterface` (inside the new repository). ### Deprecations -* The Piwik::setUserHasSuperUserAccess method is deprecated, instead use Access::doAsSuperUser. This method will ensure that super user access is properly rescinded after the callback finishes. +* The `Piwik::setUserHasSuperUserAccess` method is deprecated, instead use Access::doAsSuperUser. This method will ensure that super user access is properly rescinded after the callback finishes. +* The class is `\IntegrationTestCase` deprecated and will be removed from December 6th 2014. Use `\Piwik\Tests\Impl\SystemTestCase` instead. +* The class is `\DatabaseTestCase` deprecated and will be removed from December 6th 2014. Use `\Piwik\Tests\Impl\IntegrationTestCase` instead. +* The class is `\Piwik\Tests\Fixture` deprecated and will be removed from December 6th 2014. Use `\Piwik\Tests\Impl\Fixture` instead. +* The class is `\Piwik\Tests\OverrideLogin` deprecated and will be removed from December 6ths 2014. Use `\Piwik\Tests\Impl\OverrideLogin` instead. + +### New API Features +* The pivotBy and related query parameters can be used to pivot reports by another dimension. Read more about the new query parameters [here](http://developer.piwik.org/api-reference/reporting-api#optional-api-parameters). + +### Library updates +* Updated AngularJS from 1.2.13 to 1.2.25 ### New commands * `generate:angular-directive` Let's you easily generate a template for a new angular directive for any plugin. diff --git a/plugins/API/tests/Integration/RowEvolutionTest.php b/plugins/API/tests/Integration/RowEvolutionTest.php index 555921e56e..cb3dc66a99 100644 --- a/plugins/API/tests/Integration/RowEvolutionTest.php +++ b/plugins/API/tests/Integration/RowEvolutionTest.php @@ -9,14 +9,15 @@ namespace Piwik\Plugins\API\tests\Integration; use Piwik\Plugins\API\RowEvolution; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group API * @group RowEvolutionTest * @group Plugins */ -class RowEvolutionTest extends \IntegrationTestCase +class RowEvolutionTest extends IntegrationTestCase { public function setUp() diff --git a/plugins/API/tests/Integration/RssRendererTest.php b/plugins/API/tests/Integration/RssRendererTest.php index 8bc9fb0792..3011273d69 100644 --- a/plugins/API/tests/Integration/RssRendererTest.php +++ b/plugins/API/tests/Integration/RssRendererTest.php @@ -11,13 +11,14 @@ namespace Piwik\Plugins\API\tests\Integration; use Piwik\Access; use Piwik\DataTable; use Piwik\Plugins\API\Renderer\Rss; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group Plugin * @group API */ -class RssRendererTest extends \IntegrationTestCase +class RssRendererTest extends IntegrationTestCase { /** * @var Rss diff --git a/plugins/Contents/tests/Fixtures/TwoVisitsWithContents.php b/plugins/Contents/tests/Fixtures/TwoVisitsWithContents.php index 0446672cbd..9d4c08746a 100644 --- a/plugins/Contents/tests/Fixtures/TwoVisitsWithContents.php +++ b/plugins/Contents/tests/Fixtures/TwoVisitsWithContents.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\Contents\tests\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API as APIGoals; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use PiwikTracker; /** diff --git a/plugins/Contents/tests/System/ContentsTest.php b/plugins/Contents/tests/System/ContentsTest.php index d348133c2b..c5304fb19e 100644 --- a/plugins/Contents/tests/System/ContentsTest.php +++ b/plugins/Contents/tests/System/ContentsTest.php @@ -7,7 +7,7 @@ */ namespace Piwik\Plugins\Contents\tests\System; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\SystemTestCase; use Piwik\Plugins\Contents\tests\Fixtures\TwoVisitsWithContents; use Piwik\Translate; diff --git a/plugins/CoreConsole/Commands/TestsSetupFixture.php b/plugins/CoreConsole/Commands/TestsSetupFixture.php index 159a381f76..42beae0988 100644 --- a/plugins/CoreConsole/Commands/TestsSetupFixture.php +++ b/plugins/CoreConsole/Commands/TestsSetupFixture.php @@ -11,7 +11,7 @@ namespace Piwik\Plugins\CoreConsole\Commands; use Piwik\Config; use Piwik\Plugin\ConsoleCommand; use Piwik\Url; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -216,7 +216,9 @@ class TestsSetupFixture extends ConsoleCommand require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php'; - require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/SystemTestCase.php'; + require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php'; + require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Impl/SystemTestCase.php'; + require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Impl/Fixture.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixture.php'; $fixturesToLoad = array( diff --git a/plugins/CoreConsole/tests/Integration/TravisYmlViewTest.php b/plugins/CoreConsole/tests/Integration/TravisYmlViewTest.php index f20e1c6d0f..7dd32b2b67 100644 --- a/plugins/CoreConsole/tests/Integration/TravisYmlViewTest.php +++ b/plugins/CoreConsole/tests/Integration/TravisYmlViewTest.php @@ -44,8 +44,8 @@ class TravisYmlViewTest extends PHPUnit_Framework_TestCase $this->assertContains(array('secure' => 'githubtoken'), $yaml['env']['global']); $this->assertNotEmpty($yaml['env']['matrix']); - $this->assertContains("TEST_SUITE=IntegrationTests MYSQL_ADAPTER=PDO_MYSQL", $yaml['env']['matrix']); - $this->assertContains("TEST_SUITE=IntegrationTests MYSQL_ADAPTER=PDO_MYSQL TEST_AGAINST_CORE=latest_stable", $yaml['env']['matrix']); + $this->assertContains("TEST_SUITE=PluginTests MYSQL_ADAPTER=PDO_MYSQL", $yaml['env']['matrix']); + $this->assertContains("TEST_SUITE=PluginTests MYSQL_ADAPTER=PDO_MYSQL TEST_AGAINST_CORE=latest_stable", $yaml['env']['matrix']); $this->assertNotContains("TEST_SUITE=UITests MYSQL_ADAPTER=PDO_MYSQL", $yaml['env']['matrix']); $this->assertBuildSectionsNotEmpty($yaml); @@ -61,7 +61,7 @@ class TravisYmlViewTest extends PHPUnit_Framework_TestCase $view->setPlugin('ExamplePlugin'); $view->setExtraGlobalEnvVars(array('secure: artifactspass', 'secure: githubtoken')); $view->setGenerateYmlCommand('./console generate:travis-yml arg1 arg2'); - $view->processExistingTravisYml(PIWIK_INCLUDE_PATH . '/plugins/CoreConsole/tests/Integration/resources/test.travis.yml'); + $view->processExistingTravisYml(PIWIK_INCLUDE_PATH . '/plugins/CoreConsole/tests/resources/test.travis.yml'); $output = $view->render(); $yaml = Spyc::YAMLLoadString($output); diff --git a/plugins/CoreConsole/tests/Integration/resources/test.travis.yml b/plugins/CoreConsole/tests/resources/test.travis.yml index 3d469b75ff..e92dabeba1 100644 --- a/plugins/CoreConsole/tests/Integration/resources/test.travis.yml +++ b/plugins/CoreConsole/tests/resources/test.travis.yml @@ -9,7 +9,7 @@ env: - secure: anotherpreservedvar matrix: - TEST_SUITE=UnitTests MYSQL_ADAPTER=PDO_MYSQL - - TEST_SUITE=IntegrationTests MYSQL_ADAPTER=PDO_MYSQL + - TEST_SUITE=PluginTests MYSQL_ADAPTER=PDO_MYSQL script: ./travis.sh diff --git a/plugins/CorePluginsAdmin/tests/Integration/UpdateCommunicationTest.php b/plugins/CorePluginsAdmin/tests/Integration/UpdateCommunicationTest.php index c57a3e0058..5743c42e46 100644 --- a/plugins/CorePluginsAdmin/tests/Integration/UpdateCommunicationTest.php +++ b/plugins/CorePluginsAdmin/tests/Integration/UpdateCommunicationTest.php @@ -11,13 +11,14 @@ namespace Piwik\Plugins\CorePluginsAdmin\tests\Integration; use Piwik\Config; use Piwik\Option; use Piwik\Plugins\CorePluginsAdmin\UpdateCommunication; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Plugins_CorePluginsAdmin_UpdateCommunicationTest * * @group Plugins */ -class UpdateCommunicationTest extends \IntegrationTestCase +class UpdateCommunicationTest extends IntegrationTestCase { /** * @var UpdateCommunication diff --git a/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php b/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php index d4ee8932c9..10f408206f 100644 --- a/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php +++ b/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php @@ -13,13 +13,14 @@ use Piwik\Option; use Piwik\Plugins\CoreUpdater\UpdateCommunication; use Piwik\UpdateCheck; use Piwik\Version; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Plugins_CoreUpdater_UpdateCommunicationTest * * @group Plugins */ -class UpdateCommunicationTest extends \IntegrationTestCase +class UpdateCommunicationTest extends IntegrationTestCase { public function setUp() { diff --git a/plugins/CustomAlerts b/plugins/CustomAlerts -Subproject f5557b8bcdb2ef6936b651a39f4e4f510b83bf6 +Subproject 643984c1bab2bc48f120e3cb83fac39b270d948 diff --git a/plugins/CustomVariables/tests/Commands/InfoTest.php b/plugins/CustomVariables/tests/Commands/InfoTest.php index e207cc914a..455cdd10e2 100644 --- a/plugins/CustomVariables/tests/Commands/InfoTest.php +++ b/plugins/CustomVariables/tests/Commands/InfoTest.php @@ -13,6 +13,7 @@ use Piwik\Plugins\CustomVariables\Commands\Info; use Piwik\Plugins\CustomVariables\Model; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group CustomVariables @@ -20,7 +21,7 @@ use Symfony\Component\Console\Tester\CommandTester; * @group Plugins * @group Plugins */ -class InfoTest extends \IntegrationTestCase +class InfoTest extends IntegrationTestCase { public function testExecute_ShouldOutputInfoSuccess_IfEverythingIsOk() { diff --git a/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php b/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php index 2c0d705994..f48473b5e9 100644 --- a/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php +++ b/plugins/CustomVariables/tests/Commands/SetNumberOfCustomVariablesTest.php @@ -13,6 +13,7 @@ use Piwik\Plugins\CustomVariables\Commands\SetNumberOfCustomVariables; use Piwik\Plugins\CustomVariables\CustomVariables; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group CustomVariables @@ -20,7 +21,7 @@ use Symfony\Component\Console\Tester\CommandTester; * @group Plugins * @group Plugins */ -class SetNumberOfCustomVariablesTest extends \IntegrationTestCase +class SetNumberOfCustomVariablesTest extends IntegrationTestCase { /** * @expectedException \RuntimeException diff --git a/plugins/CustomVariables/tests/Fixtures/VisitWithManyCustomVariables.php b/plugins/CustomVariables/tests/Fixtures/VisitWithManyCustomVariables.php index 8060eb25a7..82b8129bbb 100644 --- a/plugins/CustomVariables/tests/Fixtures/VisitWithManyCustomVariables.php +++ b/plugins/CustomVariables/tests/Fixtures/VisitWithManyCustomVariables.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\CustomVariables\tests\Fixtures; use Piwik\Plugins\CustomVariables\Model; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site with two goals and tracks two visits with custom variables. diff --git a/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php b/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php index 25a158589e..5144dc4489 100644 --- a/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php +++ b/plugins/CustomVariables/tests/Integration/CustomVariablesTest.php @@ -9,13 +9,14 @@ namespace Piwik\Plugins\CustomVariables\tests; use Piwik\Plugins\CustomVariables\CustomVariables; use Piwik\Tracker\Cache; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group CustomVariables * @group CustomVariablesTest * @group Plugins */ -class CustomVariablesTest extends \IntegrationTestCase +class CustomVariablesTest extends IntegrationTestCase { public function testGetMaxCustomVariables_ShouldDetectCorrectNumberOfVariables() { diff --git a/plugins/CustomVariables/tests/Integration/ModelTest.php b/plugins/CustomVariables/tests/Integration/ModelTest.php index 11d444b748..384d204478 100644 --- a/plugins/CustomVariables/tests/Integration/ModelTest.php +++ b/plugins/CustomVariables/tests/Integration/ModelTest.php @@ -9,6 +9,7 @@ namespace Piwik\Plugins\CustomVariables\tests; use Piwik\Db; use Piwik\Plugins\CustomVariables\Model; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group CustomVariables @@ -16,7 +17,7 @@ use Piwik\Plugins\CustomVariables\Model; * @group Plugins * @group CustomVariables_ModelTest */ -class ModelTest extends \IntegrationTestCase +class ModelTest extends IntegrationTestCase { private static $cvarScopes = array('log_link_visit_action', 'log_visit', 'log_conversion'); diff --git a/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php b/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php index 1bcdf9f838..00158a1e48 100644 --- a/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php +++ b/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php @@ -8,7 +8,7 @@ namespace Piwik\Plugins\CustomVariables\tests; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\SystemTestCase; /** * @group CustomVariables diff --git a/plugins/ExamplePlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php b/plugins/ExamplePlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php index 2d455ce70a..2c0b38d172 100644 --- a/plugins/ExamplePlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php +++ b/plugins/ExamplePlugin/tests/Fixtures/SimpleFixtureTrackFewVisits.php @@ -8,7 +8,7 @@ namespace Piwik\Plugins\ExamplePlugin\tests\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Generates tracker testing data for our SimpleSystemTest diff --git a/plugins/ExamplePlugin/tests/Integration/SimpleTest.php b/plugins/ExamplePlugin/tests/Integration/SimpleTest.php index c096b2946b..01ff197cf8 100644 --- a/plugins/ExamplePlugin/tests/Integration/SimpleTest.php +++ b/plugins/ExamplePlugin/tests/Integration/SimpleTest.php @@ -8,12 +8,14 @@ namespace Piwik\Plugins\ExamplePlugin\tests\Integration; +use Piwik\Tests\Impl\IntegrationTestCase; + /** * @group ExamplePlugin * @group SimpleTest * @group Plugins */ -class SimpleTest extends \IntegrationTestCase +class SimpleTest extends IntegrationTestCase { public function testSimpleAddition() diff --git a/plugins/ExamplePlugin/tests/System/SimpleSystemTest.php b/plugins/ExamplePlugin/tests/System/SimpleSystemTest.php index 574e6b5a79..873c4e4fbe 100644 --- a/plugins/ExamplePlugin/tests/System/SimpleSystemTest.php +++ b/plugins/ExamplePlugin/tests/System/SimpleSystemTest.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\ExamplePlugin\tests\System; use Piwik\Plugins\ExamplePlugin\tests\fixtures\SimpleFixtureTrackFewVisits; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\SystemTestCase; /** * @group ExamplePlugin diff --git a/plugins/Goals/tests/Integration/APITest.php b/plugins/Goals/tests/Integration/APITest.php index 6251628430..bc3a960e83 100644 --- a/plugins/Goals/tests/Integration/APITest.php +++ b/plugins/Goals/tests/Integration/APITest.php @@ -7,10 +7,12 @@ */ namespace Piwik\Plugins\Goals\tests\Integration; + use Piwik\Access; use Piwik\Piwik; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group Goals @@ -18,7 +20,7 @@ use Piwik\Tests\Fixture; * @group APITest * @group Plugins */ -class APITest extends \IntegrationTestCase +class APITest extends IntegrationTestCase { /** * @var API diff --git a/plugins/Insights/tests/Fixtures/SomeVisitsDifferentPathsOnTwoDays.php b/plugins/Insights/tests/Fixtures/SomeVisitsDifferentPathsOnTwoDays.php index c5314d3aa3..7041e6b573 100644 --- a/plugins/Insights/tests/Fixtures/SomeVisitsDifferentPathsOnTwoDays.php +++ b/plugins/Insights/tests/Fixtures/SomeVisitsDifferentPathsOnTwoDays.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\Insights\tests\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one website and tracks several visits from one visitor on diff --git a/plugins/Insights/tests/Integration/ApiTest.php b/plugins/Insights/tests/Integration/ApiTest.php index 356bc769de..292ba3e85a 100644 --- a/plugins/Insights/tests/Integration/ApiTest.php +++ b/plugins/Insights/tests/Integration/ApiTest.php @@ -12,7 +12,7 @@ use Piwik\DataTable; use Piwik\DataTable\Row; use Piwik\Plugins\Insights\API; use Piwik\Plugins\Insights\tests\Fixtures\SomeVisitsDifferentPathsOnTwoDays; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\SystemTestCase; use Piwik\Translate; /** diff --git a/plugins/Insights/tests/Integration/ModelTest.php b/plugins/Insights/tests/Integration/ModelTest.php index 94ff52201d..4f62630bd9 100644 --- a/plugins/Insights/tests/Integration/ModelTest.php +++ b/plugins/Insights/tests/Integration/ModelTest.php @@ -11,7 +11,7 @@ namespace Piwik\Plugins\Insights\tests; use Piwik\DataTable; use Piwik\Plugins\Insights\Model; use Piwik\Plugins\Insights\tests\Fixtures\SomeVisitsDifferentPathsOnTwoDays; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\SystemTestCase; /** * @group Insights diff --git a/plugins/LeftMenu/tests/Integration/APITest.php b/plugins/LeftMenu/tests/Integration/APITest.php index 0677f57c73..e4500b2e41 100644 --- a/plugins/LeftMenu/tests/Integration/APITest.php +++ b/plugins/LeftMenu/tests/Integration/APITest.php @@ -12,13 +12,14 @@ use Piwik\Access; use Piwik\Plugins\LeftMenu\API; use Piwik\Plugins\LeftMenu\Settings; use \FakeAccess; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group LeftMenu * @group APITest * @group Plugins */ -class APITest extends \IntegrationTestCase +class APITest extends IntegrationTestCase { /** * @var API diff --git a/plugins/Live/tests/Integration/APITest.php b/plugins/Live/tests/Integration/APITest.php index 7c49eb2eae..fcfc410bcf 100644 --- a/plugins/Live/tests/Integration/APITest.php +++ b/plugins/Live/tests/Integration/APITest.php @@ -14,8 +14,8 @@ use Piwik\Plugins\Goals\API as GoalsApi; use Piwik\Plugins\Live\API; use FakeAccess; use Piwik\Access; -use Piwik\Tests\Fixture; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\SystemTestCase; /** * @group Live diff --git a/plugins/Login/tests/Integration/LoginTest.php b/plugins/Login/tests/Integration/LoginTest.php index 4af87cc115..4007061bd5 100644 --- a/plugins/Login/tests/Integration/LoginTest.php +++ b/plugins/Login/tests/Integration/LoginTest.php @@ -13,7 +13,7 @@ use Piwik\AuthResult; use Piwik\DbHelper; use Piwik\Plugins\Login\Auth; use Piwik\Plugins\UsersManager\API; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use FakeAccess; require_once PIWIK_INCLUDE_PATH . '/plugins/Login/Auth.php'; diff --git a/plugins/MobileMessaging/tests/Integration/MobileMessagingTest.php b/plugins/MobileMessaging/tests/Integration/MobileMessagingTest.php index 35479dcea8..6d2eb9849b 100644 --- a/plugins/MobileMessaging/tests/Integration/MobileMessagingTest.php +++ b/plugins/MobileMessaging/tests/Integration/MobileMessagingTest.php @@ -14,7 +14,7 @@ use Piwik\Plugins\MobileMessaging\MobileMessaging; use Piwik\Plugins\MobileMessaging\SMSProvider; use Piwik\Plugins\ScheduledReports\API as APIScheduledReports; use Piwik\Plugins\SitesManager\API as APISitesManager; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use FakeAccess; /** diff --git a/plugins/MultiSites/tests/Integration/MultiSitesTest.php b/plugins/MultiSites/tests/Integration/MultiSitesTest.php index 5f07c7131c..a5f372b7a5 100644 --- a/plugins/MultiSites/tests/Integration/MultiSitesTest.php +++ b/plugins/MultiSites/tests/Integration/MultiSitesTest.php @@ -11,7 +11,7 @@ namespace Piwik\Plugins\MultiSites\tests\Integration; use Piwik\Access; use Piwik\Plugins\MultiSites\API as APIMultiSites; use Piwik\Plugins\SitesManager\API as APISitesManager; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Plugins_MultiSitesTest diff --git a/plugins/PiwikDebugger b/plugins/PiwikDebugger new file mode 160000 +Subproject 1d4fc9ae7b66005d6758798c6fe5030128db42c diff --git a/plugins/PrivacyManager/tests/Integration/PrivacyManagerConfigTest.php b/plugins/PrivacyManager/tests/Integration/PrivacyManagerConfigTest.php index 88194e78f1..07092248fe 100644 --- a/plugins/PrivacyManager/tests/Integration/PrivacyManagerConfigTest.php +++ b/plugins/PrivacyManager/tests/Integration/PrivacyManagerConfigTest.php @@ -10,7 +10,7 @@ namespace Piwik\Plugins\PrivacyManager\tests; use Piwik\Option; use Piwik\Plugins\PrivacyManager\Config as PrivacyManagerConfig; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Plugins_SitesManagerTest diff --git a/plugins/PrivacyManager/tests/Integration/PrivacyManagerTest.php b/plugins/PrivacyManager/tests/Integration/PrivacyManagerTest.php index f9e3b43079..50fce5f0a7 100644 --- a/plugins/PrivacyManager/tests/Integration/PrivacyManagerTest.php +++ b/plugins/PrivacyManager/tests/Integration/PrivacyManagerTest.php @@ -9,7 +9,7 @@ namespace Piwik\Plugins\PrivacyManager\tests; use Piwik\Plugins\PrivacyManager\PrivacyManager; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Plugins_SitesManagerTest diff --git a/plugins/SEO/tests/Unit/SEOTest.php b/plugins/SEO/tests/Integration/SEOTest.php index 71cc2e341d..14f8666d61 100644 --- a/plugins/SEO/tests/Unit/SEOTest.php +++ b/plugins/SEO/tests/Integration/SEOTest.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\SEO\tests\Unit; +namespace Piwik\Plugins\SEO\tests\Integration; use Piwik\Access; use Piwik\DataTable\Renderer; diff --git a/plugins/ScheduledReports/tests/Integration/ApiTest.php b/plugins/ScheduledReports/tests/Integration/ApiTest.php index 7f5f1649e0..419834a0e7 100644 --- a/plugins/ScheduledReports/tests/Integration/ApiTest.php +++ b/plugins/ScheduledReports/tests/Integration/ApiTest.php @@ -19,7 +19,7 @@ use Piwik\ScheduledTask; use Piwik\ScheduledTime\Monthly; use Piwik\ScheduledTime; use Piwik\Site; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use FakeAccess; use Exception; use ReflectionMethod; diff --git a/plugins/ScheduledReports/tests/Integration/ScheduledReportsTest.php b/plugins/ScheduledReports/tests/Integration/ScheduledReportsTest.php index 241e063aa0..b0bb56363f 100644 --- a/plugins/ScheduledReports/tests/Integration/ScheduledReportsTest.php +++ b/plugins/ScheduledReports/tests/Integration/ScheduledReportsTest.php @@ -12,14 +12,15 @@ use Piwik\Db; use Piwik\Piwik; use Piwik\Plugins\ScheduledReports\API; use Piwik\Plugins\ScheduledReports\ScheduledReports; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group ScheduledReports * @group ScheduledReportsTest * @group Plugins */ -class ScheduledReportsTest extends \IntegrationTestCase +class ScheduledReportsTest extends IntegrationTestCase { /** * @var ScheduledReports diff --git a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php index 3fd322b62f..e5d863e92c 100644 --- a/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php +++ b/plugins/SegmentEditor/tests/Integration/SegmentEditorTest.php @@ -14,7 +14,7 @@ use Piwik\Piwik; use Piwik\Plugins\SegmentEditor\API; use Piwik\Plugins\SegmentEditor\Model; use Piwik\Plugins\SitesManager\API as APISitesManager; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use FakeAccess; use Exception; diff --git a/plugins/SitesManager/tests/Integration/SiteUrlsTest.php b/plugins/SitesManager/tests/Integration/SiteUrlsTest.php index 2ab2711c8d..8cc7cc5b14 100644 --- a/plugins/SitesManager/tests/Integration/SiteUrlsTest.php +++ b/plugins/SitesManager/tests/Integration/SiteUrlsTest.php @@ -10,13 +10,14 @@ namespace Piwik\Plugins\SitesManager\tests\Integration; use Piwik\CacheFile; use Piwik\Plugins\SitesManager\API; use Piwik\Plugins\SitesManager\SiteUrls; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group SitesManager * @group SiteUrlsTest * @group Plugins */ -class SiteUrlsTest extends \IntegrationTestCase +class SiteUrlsTest extends IntegrationTestCase { /** * @var SiteUrls diff --git a/plugins/SitesManager/tests/Integration/SitesManagerTest.php b/plugins/SitesManager/tests/Integration/SitesManagerTest.php index dc8ab0713c..2d2ac466ef 100644 --- a/plugins/SitesManager/tests/Integration/SitesManagerTest.php +++ b/plugins/SitesManager/tests/Integration/SitesManagerTest.php @@ -12,7 +12,7 @@ use Piwik\Access; use Piwik\Plugins\SitesManager\API; use Piwik\Plugins\UsersManager\API as APIUsersManager; use Piwik\Site; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use FakeAccess; use Exception; use PHPUnit_Framework_Constraint_IsType; diff --git a/plugins/UserSettings/tests/Fixtures/LanguageFixture.php b/plugins/UserSettings/tests/Fixtures/LanguageFixture.php index 01c5d626a9..dc6b4fcb0b 100644 --- a/plugins/UserSettings/tests/Fixtures/LanguageFixture.php +++ b/plugins/UserSettings/tests/Fixtures/LanguageFixture.php @@ -10,7 +10,7 @@ namespace Piwik\Plugins\UserSettings\tests\Fixtures; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Piwik\Date; use Piwik\Common; diff --git a/plugins/UserSettings/tests/System/GetLanguageSystemTest.php b/plugins/UserSettings/tests/System/GetLanguageSystemTest.php index cb87f88d1f..70db55616b 100644 --- a/plugins/UserSettings/tests/System/GetLanguageSystemTest.php +++ b/plugins/UserSettings/tests/System/GetLanguageSystemTest.php @@ -10,7 +10,7 @@ namespace Piwik\Plugins\UserSettings\tests\System; use Piwik\Plugins\UserSettings\tests\Fixtures\LanguageFixture; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\SystemTestCase; /** * Class GetLanguageSystemTest diff --git a/plugins/UsersManager/tests/Integration/APITest.php b/plugins/UsersManager/tests/Integration/APITest.php index 3d77ee7a83..e84cd5b750 100644 --- a/plugins/UsersManager/tests/Integration/APITest.php +++ b/plugins/UsersManager/tests/Integration/APITest.php @@ -11,14 +11,15 @@ use Piwik\Access; use FakeAccess; use Piwik\Piwik; use Piwik\Plugins\UsersManager\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group UsersManager * @group APITest * @group Plugins */ -class APITest extends \IntegrationTestCase +class APITest extends IntegrationTestCase { /** * @var API diff --git a/plugins/UsersManager/tests/Integration/UserPreferencesTest.php b/plugins/UsersManager/tests/Integration/UserPreferencesTest.php index 50658e46e2..cd23e7baa3 100644 --- a/plugins/UsersManager/tests/Integration/UserPreferencesTest.php +++ b/plugins/UsersManager/tests/Integration/UserPreferencesTest.php @@ -13,7 +13,8 @@ use Piwik\Plugins\UsersManager\UserPreferences; use Piwik\Plugins\UsersManager\API as APIUsersManager; use FakeAccess; use Piwik\Access; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group UsersManager @@ -21,7 +22,7 @@ use Piwik\Tests\Fixture; * @group Plugins * @group Plugins */ -class UserPreferencesTest extends \IntegrationTestCase +class UserPreferencesTest extends IntegrationTestCase { /** * @var UserPreferences diff --git a/plugins/UsersManager/tests/Integration/UsersManagerTest.php b/plugins/UsersManager/tests/Integration/UsersManagerTest.php index 115df6c0bb..e813c2ac1b 100644 --- a/plugins/UsersManager/tests/Integration/UsersManagerTest.php +++ b/plugins/UsersManager/tests/Integration/UsersManagerTest.php @@ -13,7 +13,7 @@ use Piwik\Plugins\SitesManager\API as APISitesManager; use Piwik\Plugins\UsersManager\API; use Piwik\Plugins\UsersManager\Model; use Piwik\Translate; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use FakeAccess; use Exception; diff --git a/tests/PHPUnit/BenchmarkTestCase.php b/tests/PHPUnit/BenchmarkTestCase.php index e8ae09bded..40f5309527 100755 --- a/tests/PHPUnit/BenchmarkTestCase.php +++ b/tests/PHPUnit/BenchmarkTestCase.php @@ -8,9 +8,9 @@ use Piwik\Config; use Piwik\Db; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; -require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/SystemTestCase.php'; +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Impl/SystemTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php'; // require fixtures @@ -21,7 +21,7 @@ foreach (glob(PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Benchmarks/Fixtures/*.php') a /** * Base class for benchmarks. */ -abstract class BenchmarkTestCase extends \Piwik\Tests\SystemTestCase +abstract class BenchmarkTestCase extends \Piwik\Tests\Impl\SystemTestCase { protected static $fixture; diff --git a/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php b/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php index 38e89928bd..4fbbef1bb9 100644 --- a/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php +++ b/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php @@ -7,7 +7,7 @@ */ use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Reusable fixture. Adds 20,000 sites and tracks one pageview for each on one day. diff --git a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteThousandsOfDistinctUrlsOverMonth.php b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteThousandsOfDistinctUrlsOverMonth.php index 554b18a694..2a997554a3 100644 --- a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteThousandsOfDistinctUrlsOverMonth.php +++ b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteThousandsOfDistinctUrlsOverMonth.php @@ -7,7 +7,7 @@ */ use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and 1000 actions for every day of one month (January). Each diff --git a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php index 9b12e79e9f..aed08bb332 100755 --- a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php +++ b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php @@ -7,7 +7,7 @@ */ use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Reusable fixture. Tracks twelve thousand page views over a year for one site. diff --git a/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php b/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php index fad6fc311f..79dba76fe7 100755 --- a/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php +++ b/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php @@ -7,7 +7,7 @@ */ use Piwik\Date; use Piwik\Plugins\Goals\API as APIGoals; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Reusable fixture. Tracks twelve thousand page views for 1000 sites on one day. diff --git a/tests/PHPUnit/ConsoleCommandTestCase.php b/tests/PHPUnit/ConsoleCommandTestCase.php index 686cf26998..72b231f41f 100644 --- a/tests/PHPUnit/ConsoleCommandTestCase.php +++ b/tests/PHPUnit/ConsoleCommandTestCase.php @@ -10,6 +10,7 @@ namespace Piwik\Tests; use Piwik\Config; use Piwik\Console; +use Piwik\Tests\Impl\SystemTestCase; use Symfony\Component\Console\Tester\ApplicationTester; /** diff --git a/tests/PHPUnit/DatabaseTestCase.php b/tests/PHPUnit/DatabaseTestCase.php new file mode 100755 index 0000000000..d1d0e06cdc --- /dev/null +++ b/tests/PHPUnit/DatabaseTestCase.php @@ -0,0 +1,21 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * @deprecated since 2.8.0 use \Piwik\Tests\Impl\IntegrationTestCase instead + */ +class DatabaseTestCase extends \Piwik\Tests\Impl\IntegrationTestCase +{ + + public static function setUpBeforeClass() + { + \Piwik\Log::debug('\DatabaseTestCase is deprecated since 2.8.0 extend \Piwik\Tests\Impl\IntegrationTestCase instead'); + + parent::setUpBeforeClass(); + } +} diff --git a/tests/PHPUnit/Fixture.php b/tests/PHPUnit/Fixture.php index c899ef2824..ad13e7eb3c 100644 --- a/tests/PHPUnit/Fixture.php +++ b/tests/PHPUnit/Fixture.php @@ -6,856 +6,26 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ namespace Piwik\Tests; - -use Piwik\Access; -use Piwik\Common; -use Piwik\Config; -use Piwik\DataAccess\ArchiveTableCreator; -use Piwik\DataTable\Manager as DataTableManager; -use Piwik\Date; -use Piwik\Db; -use Piwik\DbHelper; use Piwik\Log; -use Piwik\Option; -use Piwik\Piwik; -use Piwik\Plugins\LanguagesManager\API as APILanguageManager; -use Piwik\Plugins\MobileMessaging\MobileMessaging; -use Piwik\Plugins\ScheduledReports\API as APIScheduledReports; -use Piwik\Plugins\ScheduledReports\ScheduledReports; -use Piwik\Plugins\SitesManager\API as APISitesManager; -use Piwik\Plugins\UserCountry\LocationProvider; -use Piwik\Plugins\UsersManager\API as APIUsersManager; -use Piwik\Plugins\UsersManager\UsersManager; -use Piwik\ReportRenderer; -use Piwik\Site; -use Piwik\Tracker\Cache; -use Piwik\Translate; -use Piwik\Url; -use PHPUnit_Framework_Assert; -use Piwik_TestingEnvironment; -use FakeAccess; -use PiwikTracker; -use Piwik_LocalTracker; -use Piwik\Updater; -use Piwik\Plugins\CoreUpdater\CoreUpdater; -use Exception; /** - * Base type for all system test fixtures. System test fixtures - * add visit and related data to the database before a test is run. Different - * tests can use the same fixtures. - * - * This class defines a set of helper methods for fixture types. The helper - * methods are public, but ideally they should only be used by fixture types. - * - * NOTE: YOU SHOULD NOT CREATE A NEW FIXTURE UNLESS THERE IS NO WAY TO MODIFY - * AN EXISTING FIXTURE TO HANDLE YOUR USE CASE. - * - * Related TODO: we should try and reduce the amount of existing fixtures by - * merging some together. + * @deprecated since 2.8.0 use \Piwik\Tests\Impl\Fixture instead */ -class Fixture extends PHPUnit_Framework_Assert +class Fixture extends \Piwik\Tests\Impl\Fixture { - const IMAGES_GENERATED_ONLY_FOR_OS = 'linux'; - const IMAGES_GENERATED_FOR_PHP = '5.5'; - const IMAGES_GENERATED_FOR_GD = '2.1.1'; - const DEFAULT_SITE_NAME = 'Piwik test'; - - const ADMIN_USER_LOGIN = 'superUserLogin'; - const ADMIN_USER_PASSWORD = 'superUserPass'; - - public $dbName = false; - public $createConfig = true; - public $dropDatabaseInSetUp = true; - public $dropDatabaseInTearDown = true; - public $loadTranslations = true; - public $createSuperUser = true; - public $removeExistingSuperUser = true; - public $overwriteExisting = true; - public $configureComponents = true; - public $persistFixtureData = false; - public $resetPersistedFixture = false; - public $printToScreen = false; - - public $testCaseClass = false; - public $extraPluginsToLoad = array(); - - public $testEnvironment = null; - - /** - * @return string - */ - protected static function getPythonBinary() - { - if(\Piwik\SettingsServer::isWindows()) { - return "C:\Python27\python.exe"; - } - if(SystemTestCase::isTravisCI()) { - return 'python2.6'; - } - return 'python'; - } /** Adds data to Piwik. Creates sites, tracks visits, imports log files, etc. */ public function setUp() { - // empty - } - - /** Does any clean up. Most of the time there will be no need to clean up. */ - public function tearDown() - { - // empty - } - - public function getDbName() - { - if ($this->dbName !== false) { - return $this->dbName; - } - - if ($this->persistFixtureData) { - return str_replace("\\", "_", get_class($this)); - } - - return Config::getInstance()->database_tests['dbname']; - } - - public function performSetUp($setupEnvironmentOnly = false) - { - try { - if ($this->createConfig) { - Config::getInstance()->setTestEnvironment(); - } - - $this->dbName = $this->getDbName(); - - if ($this->persistFixtureData) { - $this->dropDatabaseInSetUp = false; - $this->dropDatabaseInTearDown = false; - $this->overwriteExisting = false; - $this->removeExistingSuperUser = false; - - Config::getInstance()->database_tests['dbname'] = Config::getInstance()->database['dbname'] = $this->dbName; - - $this->getTestEnvironment()->dbName = $this->dbName; - } - - if ($this->dbName === false) { // must be after test config is created - $this->dbName = Config::getInstance()->database['dbname']; - } - - static::connectWithoutDatabase(); - - if ($this->dropDatabaseInSetUp - || $this->resetPersistedFixture - ) { - $this->dropDatabase(); - } - - DbHelper::createDatabase($this->dbName); - DbHelper::disconnectDatabase(); - - // reconnect once we're sure the database exists - Config::getInstance()->database['dbname'] = $this->dbName; - Db::createDatabaseObject(); - - Db::get()->query("SET wait_timeout=28800;"); - - DbHelper::createTables(); - - \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); - - } catch (Exception $e) { - static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); - } - - include "DataFiles/SearchEngines.php"; - include "DataFiles/Socials.php"; - include "DataFiles/Languages.php"; - include "DataFiles/Countries.php"; - include "DataFiles/Currencies.php"; - include "DataFiles/LanguageToCountry.php"; - include "DataFiles/Providers.php"; - - if (!$this->isFixtureSetUp()) { - DbHelper::truncateAllTables(); - } - - static::createAccessInstance(); - - // We need to be SU to create websites for tests - Access::getInstance()->setSuperUserAccess(); - - Cache::deleteTrackerCache(); - - static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass, $this->extraPluginsToLoad); - - self::updateDatabase(); - - self::installAndActivatePlugins(); - - $_GET = $_REQUEST = array(); - $_SERVER['HTTP_REFERER'] = ''; - - // Make sure translations are loaded to check messages in English - if ($this->loadTranslations) { - Translate::reloadLanguage('en'); - APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en'); - } - - FakeAccess::$superUserLogin = 'superUserLogin'; - - \Piwik\SettingsPiwik::$cachedKnownSegmentsToArchive = null; - \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true; - - if ($this->configureComponents) { - \Piwik\Plugins\PrivacyManager\IPAnonymizer::deactivate(); - \Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker::deactivate(); - } - - if ($this->createSuperUser) { - self::createSuperUser($this->removeExistingSuperUser); - } - - if ($setupEnvironmentOnly) { - return; - } - - $this->getTestEnvironment()->save(); - $this->getTestEnvironment()->executeSetupTestEnvHook(); - Piwik_TestingEnvironment::addSendMailHook(); - - if ($this->overwriteExisting - || !$this->isFixtureSetUp() - ) { - $this->setUp(); + Log::warning('Piwik\Tests\Fixture is deprecated, use \Piwik\Tests\Impl\Fixture instead'); - $this->markFixtureSetUp(); - $this->log("Database {$this->dbName} marked as successfully set up."); - } else { - $this->log("Using existing database {$this->dbName}."); - } - } - - public function getTestEnvironment() - { - if ($this->testEnvironment === null) { - $this->testEnvironment = new Piwik_TestingEnvironment(); - $this->testEnvironment->delete(); - - if (getenv('PIWIK_USE_XHPROF') == 1) { - $this->testEnvironment->useXhprof = true; - } - } - return $this->testEnvironment; - } - - public function isFixtureSetUp() - { - $optionName = get_class($this) . '.setUpFlag'; - return Option::get($optionName) !== false; - } - - public function markFixtureSetUp() - { - $optionName = get_class($this) . '.setUpFlag'; - Option::set($optionName, 1); - } - - public function performTearDown() - { - // Note: avoid run SQL in the *tearDown() metohds because it randomly fails on Travis CI - // with error Error while sending QUERY packet. PID=XX - $this->tearDown(); - - self::unloadAllPlugins(); - - if ($this->dropDatabaseInTearDown) { - $this->dropDatabase(); - } - - $this->clearInMemoryCaches(); - } - - public function clearInMemoryCaches() - { - DataTableManager::getInstance()->deleteAll(); - Option::clearCache(); - Site::clearCache(); - Cache::deleteTrackerCache(); - Config::getInstance()->clear(); - ArchiveTableCreator::clear(); - \Piwik\Plugins\ScheduledReports\API::$cache = array(); - \Piwik\Registry::unsetInstance(); - \Piwik\EventDispatcher::getInstance()->clearAllObservers(); - - $_GET = $_REQUEST = array(); - Translate::unloadEnglishTranslation(); - - Config::unsetInstance(); - - \Piwik\Config::getInstance()->Plugins; // make sure Plugins exists in a config object for next tests that use Plugin\Manager - // since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object - } - - public static function loadAllPlugins($testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array()) - { - if (empty($testEnvironment)) { - $testEnvironment = new Piwik_TestingEnvironment(); - } - - DbHelper::createTables(); - $pluginsManager = \Piwik\Plugin\Manager::getInstance(); - - $plugins = $testEnvironment->getCoreAndSupportedPlugins(); - - // make sure the plugin that executed this method is included in the plugins to load - $extraPlugins = array_merge($extraPluginsToLoad, array( - \Piwik\Plugin::getPluginNameFromBacktrace(debug_backtrace()), - \Piwik\Plugin::getPluginNameFromNamespace($testCaseClass), - \Piwik\Plugin::getPluginNameFromNamespace(get_called_class()) - )); - foreach ($extraPlugins as $pluginName) { - if (empty($pluginName)) { - continue; - } - - if (in_array($pluginName, $plugins)) { - continue; - } - - $plugins[] = $pluginName; - if ($testEnvironment) { - $testEnvironment->pluginsToLoad = array_merge($testEnvironment->pluginsToLoad ?: array(), array($pluginName)); - } - } - - Log::debug("Plugins to load during tests: " . implode(', ', $plugins)); - - $pluginsManager->loadPlugins($plugins); - } - - public static function installAndActivatePlugins() - { - $pluginsManager = \Piwik\Plugin\Manager::getInstance(); - - // Install plugins - $messages = $pluginsManager->installLoadedPlugins(); - if(!empty($messages)) { - Log::info("Plugin loading messages: %s", implode(" --- ", $messages)); - } - - // Activate them - foreach($pluginsManager->getLoadedPlugins() as $plugin) { - $name = $plugin->getPluginName(); - if (!$pluginsManager->isPluginActivated($name)) { - $pluginsManager->activatePlugin($name); - } - } - } - - public static function unloadAllPlugins() - { - try { - $manager = \Piwik\Plugin\Manager::getInstance(); - $plugins = $manager->getLoadedPlugins(); - foreach ($plugins as $plugin) { - $plugin->uninstall(); - } - \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); - } catch (Exception $e) { - } - } - - /** - * Creates a website, then sets its creation date to a day earlier than specified dateTime - * Useful to create a website now, but force data to be archived back in the past. - * - * @param string $dateTime eg '2010-01-01 12:34:56' - * @param int $ecommerce - * @param string $siteName - * - * @param bool|string $siteUrl - * @param int $siteSearch - * @param null|string $searchKeywordParameters - * @param null|string $searchCategoryParameters - * @return int idSite of website created - */ - public static function createWebsite($dateTime, $ecommerce = 0, $siteName = false, $siteUrl = false, - $siteSearch = 1, $searchKeywordParameters = null, - $searchCategoryParameters = null, $timezone = null) - { - if($siteName === false) { - $siteName = self::DEFAULT_SITE_NAME; - } - $idSite = APISitesManager::getInstance()->addSite( - $siteName, - $siteUrl === false ? "http://piwik.net/" : $siteUrl, - $ecommerce, - $siteSearch, $searchKeywordParameters, $searchCategoryParameters, - $ips = null, - $excludedQueryParameters = null, - $timezone, - $currency = null - ); - - // Manually set the website creation date to a day earlier than the earliest day we record stats for - Db::get()->update(Common::prefixTable("site"), - array('ts_created' => Date::factory($dateTime)->subDay(1)->getDatetime()), - "idsite = $idSite" - ); - - // Clear the memory Website cache - Site::clearCache(); - - return $idSite; - } - - /** - * Returns URL to Piwik root. - * - * @return string - */ - public static function getRootUrl() - { - $piwikUrl = Url::getCurrentUrlWithoutFileName(); - - $pathBeforeRoot = 'tests'; - // Running from a plugin - if (strpos($piwikUrl, 'plugins/') !== false) { - $pathBeforeRoot = 'plugins'; - } - - $testsInPath = strpos($piwikUrl, $pathBeforeRoot . '/'); - if ($testsInPath !== false) { - $piwikUrl = substr($piwikUrl, 0, $testsInPath); - } - - // in case force_ssl=1, or assume_secure_protocol=1, is set in tests - // we don't want to require Travis CI or devs to setup HTTPS on their local machine - $piwikUrl = str_replace("https://", "http://", $piwikUrl); - - return $piwikUrl; - } - - /** - * Returns URL to the proxy script, used to ensure piwik.php - * uses the test environment, and allows variable overwriting - * - * @return string - */ - public static function getTrackerUrl() - { - return self::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php'; - } - - /** - * Returns a PiwikTracker object that you can then use to track pages or goals. - * - * @param int $idSite - * @param string $dateTime - * @param boolean $defaultInit If set to true, the tracker object will have default IP, user agent, time, resolution, etc. - * @param bool $useLocal - * - * @return PiwikTracker - */ - public static function getTracker($idSite, $dateTime, $defaultInit = true, $useLocal = false) - { - if ($useLocal) { - require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php'; - $t = new Piwik_LocalTracker($idSite, self::getTrackerUrl()); - } else { - $t = new PiwikTracker($idSite, self::getTrackerUrl()); - } - $t->setForceVisitDateTime($dateTime); - - if ($defaultInit) { - $t->setTokenAuth(self::getTokenAuth()); - $t->setIp('156.5.3.2'); - - // Optional tracking - $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)"); - $t->setBrowserLanguage('fr'); - $t->setLocalTime('12:34:06'); - $t->setResolution(1024, 768); - $t->setBrowserHasCookies(true); - $t->setPlugins($flash = true, $java = true, $director = false); - } - return $t; - } - - /** - * Checks that the response is a GIF image as expected. - * Will fail the test if the response is not the expected GIF - * - * @param $response - */ - public static function checkResponse($response) - { - $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; - $expectedResponse = base64_decode($trans_gif_64); - - $url = "\n =========================== \n URL was: " . PiwikTracker::$DEBUG_LAST_REQUESTED_URL; - self::assertEquals($expectedResponse, $response, "Expected GIF beacon, got: <br/>\n" - . var_export($response, true) - . "\n If you are stuck, you can enable [Tracker] debug=1; in config.ini.php to get more debug info." - . base64_encode($response) - . $url - ); - } - - /** - * Checks that the response from bulk tracking is a valid JSON - * string. Will fail the test if JSON status is not success. - * - * @param $response - */ - public static function checkBulkTrackingResponse($response) { - $data = json_decode($response, true); - if (!is_array($data) || empty($response)) { - throw new Exception("Bulk tracking response (".$response.") is not an array: " . var_export($data, true) . "\n"); - } - if(!isset($data['status'])) { - throw new Exception("Returned data didn't have a status: " . var_export($data,true)); - } - - self::assertArrayHasKey('status', $data); - self::assertEquals('success', $data['status'], "expected success, got: " . var_export($data, true)); - } - - public static function makeLocation($city, $region, $country, $lat = null, $long = null, $isp = null) - { - return array(LocationProvider::CITY_NAME_KEY => $city, - LocationProvider::REGION_CODE_KEY => $region, - LocationProvider::COUNTRY_CODE_KEY => $country, - LocationProvider::LATITUDE_KEY => $lat, - LocationProvider::LONGITUDE_KEY => $long, - LocationProvider::ISP_KEY => $isp); - } - - /** - * Returns the Super User token auth that can be used in tests. Can be used to - * do bulk tracking. - * - * @return string - */ - public static function getTokenAuth() - { - return APIUsersManager::getInstance()->getTokenAuth( - self::ADMIN_USER_LOGIN, - UsersManager::getPasswordHash(self::ADMIN_USER_PASSWORD) - ); - } - - public static function createSuperUser($removeExisting = true) - { - $login = self::ADMIN_USER_LOGIN; - $password = UsersManager::getPasswordHash(self::ADMIN_USER_PASSWORD); - $token = self::getTokenAuth(); - - $model = new \Piwik\Plugins\UsersManager\Model(); - if ($removeExisting) { - $model->deleteUserOnly($login); - } - - $user = $model->getUser($login); - - if (empty($user)) { - $model->addUser($login, $password, 'hello@example.org', $login, $token, Date::now()->getDatetime()); - } else { - $model->updateUser($login, $password, 'hello@example.org', $login, $token); - } - - if (empty($user['superuser_access'])) { - $model->setSuperUserAccess($login, true); - } - - return $model->getUserByTokenAuth($token); - } - - /** - * Create three MAIL and two MOBILE scheduled reports - * - * Reports sent by mail can contain PNG graphs when the user specifies it. - * Depending on the system under test, generated images differ slightly. - * Because of this discrepancy, PNG graphs are only tested if the system under test - * has the characteristics described in 'canImagesBeIncludedInScheduledReports'. - * See tests/README.md for more detail. - * - * @see canImagesBeIncludedInScheduledReports - * @param int $idSite id of website created - */ - public static function setUpScheduledReports($idSite) - { - // fake access is needed so API methods can call Piwik::getCurrentUserLogin(), e.g: 'ScheduledReports.addReport' - $pseudoMockAccess = new FakeAccess; - FakeAccess::$superUser = true; - Access::setSingletonInstance($pseudoMockAccess); - - // retrieve available reports - $availableReportMetadata = APIScheduledReports::getReportMetadata($idSite, ScheduledReports::EMAIL_TYPE); - - $availableReportIds = array(); - foreach ($availableReportMetadata as $reportMetadata) { - $availableReportIds[] = $reportMetadata['uniqueId']; - } - - //@review should we also test evolution graphs? - // set-up mail report - APIScheduledReports::getInstance()->addReport( - $idSite, - 'Mail Test report', - 'day', // overridden in getApiForTestingScheduledReports() - 0, - ScheduledReports::EMAIL_TYPE, - ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports() - $availableReportIds, - array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY) - ); - - // set-up sms report for one website - APIScheduledReports::getInstance()->addReport( - $idSite, - 'SMS Test report, one website', - 'day', // overridden in getApiForTestingScheduledReports() - 0, - MobileMessaging::MOBILE_TYPE, - MobileMessaging::SMS_FORMAT, - array("MultiSites_getOne"), - array("phoneNumbers" => array()) - ); - - // set-up sms report for all websites - APIScheduledReports::getInstance()->addReport( - $idSite, - 'SMS Test report, all websites', - 'day', // overridden in getApiForTestingScheduledReports() - 0, - MobileMessaging::MOBILE_TYPE, - MobileMessaging::SMS_FORMAT, - array("MultiSites_getAll"), - array("phoneNumbers" => array()) - ); - - if (self::canImagesBeIncludedInScheduledReports()) { - // set-up mail report with images - APIScheduledReports::getInstance()->addReport( - $idSite, - 'Mail Test report', - 'day', // overridden in getApiForTestingScheduledReports() - 0, - ScheduledReports::EMAIL_TYPE, - ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports() - $availableReportIds, - array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS) - ); - - // set-up mail report with one row evolution based png graph - APIScheduledReports::getInstance()->addReport( - $idSite, - 'Mail Test report', - 'day', - 0, - ScheduledReports::EMAIL_TYPE, - ReportRenderer::HTML_FORMAT, - array('Actions_getPageTitles'), - array( - ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, - ScheduledReports::EVOLUTION_GRAPH_PARAMETER => 'true', - ) - ); - } - } - - /** - * Return true if system under test has Piwik core team's most common configuration - */ - public static function canImagesBeIncludedInScheduledReports() - { - $gdInfo = gd_info(); - return - stristr(php_uname(), self::IMAGES_GENERATED_ONLY_FOR_OS) && - strpos( phpversion(), self::IMAGES_GENERATED_FOR_PHP) !== false && - strpos( $gdInfo['GD Version'], self::IMAGES_GENERATED_FOR_GD) !== false; - } - - public static $geoIpDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoIP.dat.gz'; - public static $geoLiteCityDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoLiteCity.dat.gz'; - - public static function downloadGeoIpDbs() - { - $geoIpOutputDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files'; - self::downloadAndUnzip(self::$geoIpDbUrl, $geoIpOutputDir, 'GeoIP.dat'); - self::downloadAndUnzip(self::$geoLiteCityDbUrl, $geoIpOutputDir, 'GeoIPCity.dat'); - } - - public static function downloadAndUnzip($url, $outputDir, $filename) - { - $bufferSize = 1024 * 1024; - - if (!is_dir($outputDir)) { - mkdir($outputDir); - } - - $deflatedOut = $outputDir . '/' . $filename; - $outfileName = $deflatedOut . '.gz'; - - if (file_exists($deflatedOut)) { - return; - } - - $dump = fopen($url, 'rb'); - $outfile = fopen($outfileName, 'wb'); - while (!feof($dump)) { - fwrite($outfile, fread($dump, $bufferSize), $bufferSize); - } - fclose($dump); - fclose($outfile); - - // unzip the dump - exec("gunzip -c \"" . $outfileName . "\" > \"$deflatedOut\"", $output, $return); - if ($return !== 0) { - Log::info("gunzip failed with file that has following contents:"); - Log::info(file_get_contents($outfile)); - - throw new Exception("gunzip failed($return): " . implode("\n", $output)); - } - } - - protected static function executeLogImporter($logFile, $options) - { - $python = self::getPythonBinary(); - - // create the command - $cmd = $python - . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc - . '-ddd ' // debug - . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files - ; - - foreach ($options as $name => $value) { - $cmd .= $name; - if ($value !== false) { - $cmd .= '="' . $value . '"'; - } - $cmd .= ' '; - } - - $cmd .= '"' . $logFile . '" 2>&1'; - - // run the command - exec($cmd, $output, $result); - if ($result !== 0) { - throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd"); - } - - return $output; - } - - public static function siteCreated($idSite) - { - return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('site') . " WHERE idsite = ?", array($idSite)) != 0; - } - - public static function goalExists($idSite, $idGoal) - { - return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('goal') . " WHERE idgoal = ? AND idsite = ?", array($idGoal, $idSite)) != 0; - } - - /** - * Connects to MySQL w/o specifying a database. - */ - public static function connectWithoutDatabase() - { - $dbConfig = Config::getInstance()->database; - $oldDbName = $dbConfig['dbname']; - $dbConfig['dbname'] = null; - - Db::createDatabaseObject($dbConfig); - - $dbConfig['dbname'] = $oldDbName; - } - - /** - * Sets up access instance. - */ - public static function createAccessInstance() - { - Access::setSingletonInstance(null); - Access::getInstance(); - Piwik::postEvent('Request.initAuthenticationObject'); - } - - public function dropDatabase($dbName = null) - { - $dbName = $dbName ?: $this->dbName ?: Config::getInstance()->database_tests['dbname']; - - $this->log("Dropping database '$dbName'..."); - - $config = _parse_ini_file(PIWIK_INCLUDE_PATH . '/config/config.ini.php', true); - $originalDbName = $config['database']['dbname']; - if ($dbName == $originalDbName - && $dbName != 'piwik_tests' - ) { // santity check - throw new \Exception("Trying to drop original database '$originalDbName'. Something's wrong w/ the tests."); - } - - DbHelper::dropDatabase($dbName); - } - - public function log($message) - { - if ($this->printToScreen) { - echo $message . "\n"; - } - } - - // NOTE: since API_Request does sanitization, API methods do not. when calling them, we must - // sometimes do sanitization ourselves. - public static function makeXssContent($type, $sanitize = false) - { - $result = "<script>$('body').html('$type XSS!');</script>"; - if ($sanitize) { - $result = Common::sanitizeInputValue($result); - } - return $result; - } - - public static function updateDatabase($force = false) - { - Cache::deleteTrackerCache(); - Option::clearCache(); - - if ($force) { - // remove version options to force update - Option::deleteLike('version%'); - Option::set('version_core', '0.0'); - } - - $updater = new Updater(); - $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); - if (empty($componentsWithUpdateFile)) { - return false; - } - - $result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile); - if (!empty($result['coreError']) - || !empty($result['warnings']) - || !empty($result['errors']) - ) { - throw new \Exception("Failed to update database (errors or warnings found): " . print_r($result, true)); - } - - return $result; + parent::setUp(); } } -// needed by tests that use stored segments w/ the proxy index.php -class OverrideLogin extends Access +/** + * @deprecated since 2.8.0 use \Piwik\Tests\Impl\OverrideLogin instead + */ +class OverrideLogin extends \Piwik\Tests\Impl\OverrideLogin { - public function getLogin() - { - return 'superUserLogin'; - } }
\ No newline at end of file diff --git a/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorIdAndUserId.php b/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorIdAndUserId.php index f039505460..7c4660f840 100644 --- a/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorIdAndUserId.php +++ b/tests/PHPUnit/Fixtures/FewVisitsWithSetVisitorIdAndUserId.php @@ -5,12 +5,12 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; use Piwik\Tracker\Visit; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use PiwikTracker; use Exception; diff --git a/tests/PHPUnit/Fixtures/InvalidVisits.php b/tests/PHPUnit/Fixtures/InvalidVisits.php index adf068d5d3..6fbeb05ebe 100644 --- a/tests/PHPUnit/Fixtures/InvalidVisits.php +++ b/tests/PHPUnit/Fixtures/InvalidVisits.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Http; use Piwik\Plugins\SitesManager\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Exception; /** diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php index 2ddc236f0c..949a750eb2 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php @@ -5,14 +5,14 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Access; use Piwik\Plugins\Goals\API as APIGoals; use Piwik\Plugins\SegmentEditor\API as APISegmentEditor; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Plugins\UserCountry\LocationProvider; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Piwik\Tests\OverrideLogin; /** diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php index 70f2d07ca5..97f8e4f8f8 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php @@ -5,13 +5,13 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Db; use Piwik\Plugins\Annotations\API as APIAnnotations; use Piwik\Plugins\Goals\API as APIGoals; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php'; diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php index 2d7620f4fe..2c4e989edc 100644 --- a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php +++ b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php @@ -5,13 +5,13 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Plugins\UserCountry\LocationProvider; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Exception; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php'; diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php b/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php index aee0adbba9..e251781bff 100644 --- a/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php +++ b/tests/PHPUnit/Fixtures/ManyVisitsWithMockLocationProvider.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\UserCountry\LocationProvider; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php'; diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php b/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php index 88f673831c..f64deeff61 100644 --- a/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php +++ b/tests/PHPUnit/Fixtures/ManyVisitsWithSubDirReferrersAndCustomVars.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks 13 visits all with custom variables and referrer URLs diff --git a/tests/PHPUnit/Fixtures/OmniFixture.php b/tests/PHPUnit/Fixtures/OmniFixture.php index a826e13e36..82e8f09ce7 100644 --- a/tests/PHPUnit/Fixtures/OmniFixture.php +++ b/tests/PHPUnit/Fixtures/OmniFixture.php @@ -5,14 +5,14 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Access; use Piwik\Option; use ReflectionClass; use Piwik\Plugins\VisitsSummary\API as VisitsSummaryAPI; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Piwik\Tests\OverrideLogin; /** diff --git a/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php b/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php index c4ed1564a0..e08c610800 100644 --- a/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php +++ b/tests/PHPUnit/Fixtures/OneVisitSeveralPageViews.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks one visit with several pageviews. diff --git a/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php b/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php index 7a316bcc78..213f663eba 100644 --- a/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php +++ b/tests/PHPUnit/Fixtures/OneVisitWithAbnormalPageviewUrls.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks one visit w/ pageview URLs that are not normalized. diff --git a/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php b/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php index 50f576b33f..60572afb27 100644 --- a/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php +++ b/tests/PHPUnit/Fixtures/OneVisitorTwoVisits.php @@ -5,12 +5,12 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API as APIGoals; use Piwik\Plugins\SitesManager\API as APISitesManager; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * This fixture adds one website and tracks two visits by one visitor. diff --git a/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php b/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php index 663b3e748a..2f7192b651 100644 --- a/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php +++ b/tests/PHPUnit/Fixtures/SomeVisitsAllConversions.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks a couple conversions. diff --git a/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php b/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php index 4896e6fe2a..2cb2010788 100644 --- a/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php +++ b/tests/PHPUnit/Fixtures/SomeVisitsCustomVariablesCampaignsNotHeuristics.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use PiwikTracker; /** diff --git a/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php b/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php index 52845bc0b8..f96529747c 100644 --- a/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php +++ b/tests/PHPUnit/Fixtures/SomeVisitsManyPageviewsWithTransitions.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks a couple visits with many pageviews. The diff --git a/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php b/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php index 6d5e2556b3..bc3304a337 100644 --- a/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php +++ b/tests/PHPUnit/Fixtures/SomeVisitsWithLongUrls.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks 7 visits w/ some long-ish urls (as page urls and diff --git a/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php b/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php index 08b4962a6f..512f807bae 100644 --- a/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php +++ b/tests/PHPUnit/Fixtures/SomeVisitsWithNonUnicodePageTitles.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\SitesManager\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one website and some visits with non unicode page titles. diff --git a/tests/PHPUnit/Fixtures/SqlDump.php b/tests/PHPUnit/Fixtures/SqlDump.php index 06c094de03..07a867784a 100644 --- a/tests/PHPUnit/Fixtures/SqlDump.php +++ b/tests/PHPUnit/Fixtures/SqlDump.php @@ -5,14 +5,14 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Access; use Piwik\ArchiveProcessor\Rules; use Piwik\Config; use Piwik\Db; use Piwik\Piwik; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use Exception; /** diff --git a/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php b/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php index ac7abb6a4f..c992072611 100644 --- a/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php +++ b/tests/PHPUnit/Fixtures/ThreeGoalsOnePageview.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Fixture that adds one site with three goals and tracks one pageview & one manual diff --git a/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php b/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php index 1c12adc3f3..bc1825e5ec 100644 --- a/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php +++ b/tests/PHPUnit/Fixtures/ThreeSitesWithManyVisitsWithSiteSearch.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\SitesManager\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds three websites with different site search configurations and adds diff --git a/tests/PHPUnit/Fixtures/ThreeSitesWithSharedVisitors.php b/tests/PHPUnit/Fixtures/ThreeSitesWithSharedVisitors.php index 267e848fde..3c11c29a96 100644 --- a/tests/PHPUnit/Fixtures/ThreeSitesWithSharedVisitors.php +++ b/tests/PHPUnit/Fixtures/ThreeSitesWithSharedVisitors.php @@ -5,12 +5,12 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Common; use Piwik\Date; use Piwik\Db; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds three sites and tracks some visits w/ visitors that visit each site. diff --git a/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php b/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php index 938fe28c86..4eb6919230 100644 --- a/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php +++ b/tests/PHPUnit/Fixtures/TwoSitesEcommerceOrderWithItems.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds two sites and tracks some visits with ecommerce orders. diff --git a/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php b/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php index 3ff7b56fa4..87c92d64a5 100644 --- a/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php +++ b/tests/PHPUnit/Fixtures/TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one website and tracks visits on different days over a month diff --git a/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php b/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php index 6e913930fd..5d2ccaca15 100644 --- a/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php +++ b/tests/PHPUnit/Fixtures/TwoSitesTwoVisitorsDifferentDays.php @@ -5,12 +5,12 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API as APIGoals; use Piwik\Plugins\SitesManager\API as APISitesManager; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds two websites and tracks visits from two visitors on different days. diff --git a/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php b/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php index 0d47c97815..59e7cd0070 100644 --- a/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php +++ b/tests/PHPUnit/Fixtures/TwoSitesVisitsInPast.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds two sites and tracks several visits all in the past. diff --git a/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php b/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php index 370c5a864e..5f822282c2 100644 --- a/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php +++ b/tests/PHPUnit/Fixtures/TwoSitesWithAnnotations.php @@ -5,12 +5,12 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Access; use Piwik\Date; use Piwik\Plugins\Annotations\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use FakeAccess; /** diff --git a/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php b/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php index fcbb864bfb..a657c837c7 100644 --- a/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php +++ b/tests/PHPUnit/Fixtures/TwoVisitsNoKeywordWithBot.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site and tracks two visits. One visit is a bot and one has no keyword diff --git a/tests/PHPUnit/Fixtures/TwoVisitsWithCustomEvents.php b/tests/PHPUnit/Fixtures/TwoVisitsWithCustomEvents.php index b2777b408f..e0a02f915d 100644 --- a/tests/PHPUnit/Fixtures/TwoVisitsWithCustomEvents.php +++ b/tests/PHPUnit/Fixtures/TwoVisitsWithCustomEvents.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API as APIGoals; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; use PiwikTracker; /** diff --git a/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php b/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php index 5ed8c06b85..ac7d4170cf 100644 --- a/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php +++ b/tests/PHPUnit/Fixtures/TwoVisitsWithCustomVariables.php @@ -5,11 +5,11 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; use Piwik\Plugins\Goals\API; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site with two goals and tracks two visits with custom variables. diff --git a/tests/PHPUnit/Fixtures/UITestFixture.php b/tests/PHPUnit/Fixtures/UITestFixture.php index 6f404adefd..b2c9c85f18 100644 --- a/tests/PHPUnit/Fixtures/UITestFixture.php +++ b/tests/PHPUnit/Fixtures/UITestFixture.php @@ -5,7 +5,7 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Exception; use Piwik\AssetManager; diff --git a/tests/PHPUnit/Fixtures/VisitOverSeveralDaysImportedLogs.php b/tests/PHPUnit/Fixtures/VisitOverSeveralDaysImportedLogs.php index 98cc3b50aa..c07548d160 100644 --- a/tests/PHPUnit/Fixtures/VisitOverSeveralDaysImportedLogs.php +++ b/tests/PHPUnit/Fixtures/VisitOverSeveralDaysImportedLogs.php @@ -5,9 +5,9 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Import a same visitor, over three different days, in reverse chronological order diff --git a/tests/PHPUnit/Fixtures/VisitsInDifferentTimezones.php b/tests/PHPUnit/Fixtures/VisitsInDifferentTimezones.php index 19c7fcc062..201c7a1353 100644 --- a/tests/PHPUnit/Fixtures/VisitsInDifferentTimezones.php +++ b/tests/PHPUnit/Fixtures/VisitsInDifferentTimezones.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one site with a non UTC timezone and tracks a couple visits near the end of the day. diff --git a/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php b/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php index caf67e00aa..01dfd2a4de 100644 --- a/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php +++ b/tests/PHPUnit/Fixtures/VisitsOverSeveralDays.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds one website and tracks several visits from one visitor on diff --git a/tests/PHPUnit/Fixtures/VisitsTwoWebsitesWithAdditionalVisits.php b/tests/PHPUnit/Fixtures/VisitsTwoWebsitesWithAdditionalVisits.php index 01963cb8ee..93ac8b7c59 100644 --- a/tests/PHPUnit/Fixtures/VisitsTwoWebsitesWithAdditionalVisits.php +++ b/tests/PHPUnit/Fixtures/VisitsTwoWebsitesWithAdditionalVisits.php @@ -5,10 +5,10 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests\Fixtures; +namespace Piwik\Tests\Impl\Fixtures; use Piwik\Date; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Adds two sites and tracks several visits with possibility to add new visits to the same days diff --git a/tests/PHPUnit/Impl/Fixture.php b/tests/PHPUnit/Impl/Fixture.php new file mode 100644 index 0000000000..bfb212107f --- /dev/null +++ b/tests/PHPUnit/Impl/Fixture.php @@ -0,0 +1,861 @@ +<?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\Impl; + +use Piwik\Access; +use Piwik\Common; +use Piwik\Config; +use Piwik\DataAccess\ArchiveTableCreator; +use Piwik\DataTable\Manager as DataTableManager; +use Piwik\Date; +use Piwik\Db; +use Piwik\DbHelper; +use Piwik\Log; +use Piwik\Option; +use Piwik\Piwik; +use Piwik\Plugins\LanguagesManager\API as APILanguageManager; +use Piwik\Plugins\MobileMessaging\MobileMessaging; +use Piwik\Plugins\ScheduledReports\API as APIScheduledReports; +use Piwik\Plugins\ScheduledReports\ScheduledReports; +use Piwik\Plugins\SitesManager\API as APISitesManager; +use Piwik\Plugins\UserCountry\LocationProvider; +use Piwik\Plugins\UsersManager\API as APIUsersManager; +use Piwik\Plugins\UsersManager\UsersManager; +use Piwik\ReportRenderer; +use Piwik\Site; +use Piwik\Tracker\Cache; +use Piwik\Translate; +use Piwik\Url; +use PHPUnit_Framework_Assert; +use Piwik_TestingEnvironment; +use FakeAccess; +use PiwikTracker; +use Piwik_LocalTracker; +use Piwik\Updater; +use Piwik\Plugins\CoreUpdater\CoreUpdater; +use Exception; + +/** + * Base type for all system test fixtures. System test fixtures + * add visit and related data to the database before a test is run. Different + * tests can use the same fixtures. + * + * This class defines a set of helper methods for fixture types. The helper + * methods are public, but ideally they should only be used by fixture types. + * + * NOTE: YOU SHOULD NOT CREATE A NEW FIXTURE UNLESS THERE IS NO WAY TO MODIFY + * AN EXISTING FIXTURE TO HANDLE YOUR USE CASE. + * + * Related TODO: we should try and reduce the amount of existing fixtures by + * merging some together. + */ +class Fixture extends PHPUnit_Framework_Assert +{ + const IMAGES_GENERATED_ONLY_FOR_OS = 'linux'; + const IMAGES_GENERATED_FOR_PHP = '5.5'; + const IMAGES_GENERATED_FOR_GD = '2.1.1'; + const DEFAULT_SITE_NAME = 'Piwik test'; + + const ADMIN_USER_LOGIN = 'superUserLogin'; + const ADMIN_USER_PASSWORD = 'superUserPass'; + + public $dbName = false; + public $createConfig = true; + public $dropDatabaseInSetUp = true; + public $dropDatabaseInTearDown = true; + public $loadTranslations = true; + public $createSuperUser = true; + public $removeExistingSuperUser = true; + public $overwriteExisting = true; + public $configureComponents = true; + public $persistFixtureData = false; + public $resetPersistedFixture = false; + public $printToScreen = false; + + public $testCaseClass = false; + public $extraPluginsToLoad = array(); + + public $testEnvironment = null; + + /** + * @return string + */ + protected static function getPythonBinary() + { + if(\Piwik\SettingsServer::isWindows()) { + return "C:\Python27\python.exe"; + } + if(SystemTestCase::isTravisCI()) { + return 'python2.6'; + } + return 'python'; + } + + /** Adds data to Piwik. Creates sites, tracks visits, imports log files, etc. */ + public function setUp() + { + // empty + } + + /** Does any clean up. Most of the time there will be no need to clean up. */ + public function tearDown() + { + // empty + } + + public function getDbName() + { + if ($this->dbName !== false) { + return $this->dbName; + } + + if ($this->persistFixtureData) { + return str_replace("\\", "_", get_class($this)); + } + + return Config::getInstance()->database_tests['dbname']; + } + + public function performSetUp($setupEnvironmentOnly = false) + { + try { + if ($this->createConfig) { + Config::getInstance()->setTestEnvironment(); + } + + $this->dbName = $this->getDbName(); + + if ($this->persistFixtureData) { + $this->dropDatabaseInSetUp = false; + $this->dropDatabaseInTearDown = false; + $this->overwriteExisting = false; + $this->removeExistingSuperUser = false; + + Config::getInstance()->database_tests['dbname'] = Config::getInstance()->database['dbname'] = $this->dbName; + + $this->getTestEnvironment()->dbName = $this->dbName; + } + + if ($this->dbName === false) { // must be after test config is created + $this->dbName = Config::getInstance()->database['dbname']; + } + + static::connectWithoutDatabase(); + + if ($this->dropDatabaseInSetUp + || $this->resetPersistedFixture + ) { + $this->dropDatabase(); + } + + DbHelper::createDatabase($this->dbName); + DbHelper::disconnectDatabase(); + + // reconnect once we're sure the database exists + Config::getInstance()->database['dbname'] = $this->dbName; + Db::createDatabaseObject(); + + Db::get()->query("SET wait_timeout=28800;"); + + DbHelper::createTables(); + + \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); + + } catch (Exception $e) { + static::fail("TEST INITIALIZATION FAILED: " . $e->getMessage() . "\n" . $e->getTraceAsString()); + } + + include "DataFiles/SearchEngines.php"; + include "DataFiles/Socials.php"; + include "DataFiles/Languages.php"; + include "DataFiles/Countries.php"; + include "DataFiles/Currencies.php"; + include "DataFiles/LanguageToCountry.php"; + include "DataFiles/Providers.php"; + + if (!$this->isFixtureSetUp()) { + DbHelper::truncateAllTables(); + } + + static::createAccessInstance(); + + // We need to be SU to create websites for tests + Access::getInstance()->setSuperUserAccess(); + + Cache::deleteTrackerCache(); + + static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass, $this->extraPluginsToLoad); + + self::updateDatabase(); + + self::installAndActivatePlugins(); + + $_GET = $_REQUEST = array(); + $_SERVER['HTTP_REFERER'] = ''; + + // Make sure translations are loaded to check messages in English + if ($this->loadTranslations) { + Translate::reloadLanguage('en'); + APILanguageManager::getInstance()->setLanguageForUser('superUserLogin', 'en'); + } + + FakeAccess::$superUserLogin = 'superUserLogin'; + + \Piwik\SettingsPiwik::$cachedKnownSegmentsToArchive = null; + \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true; + + if ($this->configureComponents) { + \Piwik\Plugins\PrivacyManager\IPAnonymizer::deactivate(); + \Piwik\Plugins\PrivacyManager\DoNotTrackHeaderChecker::deactivate(); + } + + if ($this->createSuperUser) { + self::createSuperUser($this->removeExistingSuperUser); + } + + if ($setupEnvironmentOnly) { + return; + } + + $this->getTestEnvironment()->save(); + $this->getTestEnvironment()->executeSetupTestEnvHook(); + Piwik_TestingEnvironment::addSendMailHook(); + + if ($this->overwriteExisting + || !$this->isFixtureSetUp() + ) { + $this->setUp(); + + $this->markFixtureSetUp(); + $this->log("Database {$this->dbName} marked as successfully set up."); + } else { + $this->log("Using existing database {$this->dbName}."); + } + } + + public function getTestEnvironment() + { + if ($this->testEnvironment === null) { + $this->testEnvironment = new Piwik_TestingEnvironment(); + $this->testEnvironment->delete(); + + if (getenv('PIWIK_USE_XHPROF') == 1) { + $this->testEnvironment->useXhprof = true; + } + } + return $this->testEnvironment; + } + + public function isFixtureSetUp() + { + $optionName = get_class($this) . '.setUpFlag'; + return Option::get($optionName) !== false; + } + + public function markFixtureSetUp() + { + $optionName = get_class($this) . '.setUpFlag'; + Option::set($optionName, 1); + } + + public function performTearDown() + { + // Note: avoid run SQL in the *tearDown() metohds because it randomly fails on Travis CI + // with error Error while sending QUERY packet. PID=XX + $this->tearDown(); + + self::unloadAllPlugins(); + + if ($this->dropDatabaseInTearDown) { + $this->dropDatabase(); + } + + $this->clearInMemoryCaches(); + } + + public function clearInMemoryCaches() + { + DataTableManager::getInstance()->deleteAll(); + Option::clearCache(); + Site::clearCache(); + Cache::deleteTrackerCache(); + Config::getInstance()->clear(); + ArchiveTableCreator::clear(); + \Piwik\Plugins\ScheduledReports\API::$cache = array(); + \Piwik\Registry::unsetInstance(); + \Piwik\EventDispatcher::getInstance()->clearAllObservers(); + + $_GET = $_REQUEST = array(); + Translate::unloadEnglishTranslation(); + + Config::unsetInstance(); + + \Piwik\Config::getInstance()->Plugins; // make sure Plugins exists in a config object for next tests that use Plugin\Manager + // since Plugin\Manager uses getFromGlobalConfig which doesn't init the config object + } + + public static function loadAllPlugins($testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array()) + { + if (empty($testEnvironment)) { + $testEnvironment = new Piwik_TestingEnvironment(); + } + + DbHelper::createTables(); + $pluginsManager = \Piwik\Plugin\Manager::getInstance(); + + $plugins = $testEnvironment->getCoreAndSupportedPlugins(); + + // make sure the plugin that executed this method is included in the plugins to load + $extraPlugins = array_merge($extraPluginsToLoad, array( + \Piwik\Plugin::getPluginNameFromBacktrace(debug_backtrace()), + \Piwik\Plugin::getPluginNameFromNamespace($testCaseClass), + \Piwik\Plugin::getPluginNameFromNamespace(get_called_class()) + )); + foreach ($extraPlugins as $pluginName) { + if (empty($pluginName)) { + continue; + } + + if (in_array($pluginName, $plugins)) { + continue; + } + + $plugins[] = $pluginName; + if ($testEnvironment) { + $testEnvironment->pluginsToLoad = array_merge($testEnvironment->pluginsToLoad ?: array(), array($pluginName)); + } + } + + Log::debug("Plugins to load during tests: " . implode(', ', $plugins)); + + $pluginsManager->loadPlugins($plugins); + } + + public static function installAndActivatePlugins() + { + $pluginsManager = \Piwik\Plugin\Manager::getInstance(); + + // Install plugins + $messages = $pluginsManager->installLoadedPlugins(); + if(!empty($messages)) { + Log::info("Plugin loading messages: %s", implode(" --- ", $messages)); + } + + // Activate them + foreach($pluginsManager->getLoadedPlugins() as $plugin) { + $name = $plugin->getPluginName(); + if (!$pluginsManager->isPluginActivated($name)) { + $pluginsManager->activatePlugin($name); + } + } + } + + public static function unloadAllPlugins() + { + try { + $manager = \Piwik\Plugin\Manager::getInstance(); + $plugins = $manager->getLoadedPlugins(); + foreach ($plugins as $plugin) { + $plugin->uninstall(); + } + \Piwik\Plugin\Manager::getInstance()->unloadPlugins(); + } catch (Exception $e) { + } + } + + /** + * Creates a website, then sets its creation date to a day earlier than specified dateTime + * Useful to create a website now, but force data to be archived back in the past. + * + * @param string $dateTime eg '2010-01-01 12:34:56' + * @param int $ecommerce + * @param string $siteName + * + * @param bool|string $siteUrl + * @param int $siteSearch + * @param null|string $searchKeywordParameters + * @param null|string $searchCategoryParameters + * @return int idSite of website created + */ + public static function createWebsite($dateTime, $ecommerce = 0, $siteName = false, $siteUrl = false, + $siteSearch = 1, $searchKeywordParameters = null, + $searchCategoryParameters = null, $timezone = null) + { + if($siteName === false) { + $siteName = self::DEFAULT_SITE_NAME; + } + $idSite = APISitesManager::getInstance()->addSite( + $siteName, + $siteUrl === false ? "http://piwik.net/" : $siteUrl, + $ecommerce, + $siteSearch, $searchKeywordParameters, $searchCategoryParameters, + $ips = null, + $excludedQueryParameters = null, + $timezone, + $currency = null + ); + + // Manually set the website creation date to a day earlier than the earliest day we record stats for + Db::get()->update(Common::prefixTable("site"), + array('ts_created' => Date::factory($dateTime)->subDay(1)->getDatetime()), + "idsite = $idSite" + ); + + // Clear the memory Website cache + Site::clearCache(); + + return $idSite; + } + + /** + * Returns URL to Piwik root. + * + * @return string + */ + public static function getRootUrl() + { + $piwikUrl = Url::getCurrentUrlWithoutFileName(); + + $pathBeforeRoot = 'tests'; + // Running from a plugin + if (strpos($piwikUrl, 'plugins/') !== false) { + $pathBeforeRoot = 'plugins'; + } + + $testsInPath = strpos($piwikUrl, $pathBeforeRoot . '/'); + if ($testsInPath !== false) { + $piwikUrl = substr($piwikUrl, 0, $testsInPath); + } + + // in case force_ssl=1, or assume_secure_protocol=1, is set in tests + // we don't want to require Travis CI or devs to setup HTTPS on their local machine + $piwikUrl = str_replace("https://", "http://", $piwikUrl); + + return $piwikUrl; + } + + /** + * Returns URL to the proxy script, used to ensure piwik.php + * uses the test environment, and allows variable overwriting + * + * @return string + */ + public static function getTrackerUrl() + { + return self::getRootUrl() . 'tests/PHPUnit/proxy/piwik.php'; + } + + /** + * Returns a PiwikTracker object that you can then use to track pages or goals. + * + * @param int $idSite + * @param string $dateTime + * @param boolean $defaultInit If set to true, the tracker object will have default IP, user agent, time, resolution, etc. + * @param bool $useLocal + * + * @return PiwikTracker + */ + public static function getTracker($idSite, $dateTime, $defaultInit = true, $useLocal = false) + { + if ($useLocal) { + require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php'; + $t = new Piwik_LocalTracker($idSite, self::getTrackerUrl()); + } else { + $t = new PiwikTracker($idSite, self::getTrackerUrl()); + } + $t->setForceVisitDateTime($dateTime); + + if ($defaultInit) { + $t->setTokenAuth(self::getTokenAuth()); + $t->setIp('156.5.3.2'); + + // Optional tracking + $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)"); + $t->setBrowserLanguage('fr'); + $t->setLocalTime('12:34:06'); + $t->setResolution(1024, 768); + $t->setBrowserHasCookies(true); + $t->setPlugins($flash = true, $java = true, $director = false); + } + return $t; + } + + /** + * Checks that the response is a GIF image as expected. + * Will fail the test if the response is not the expected GIF + * + * @param $response + */ + public static function checkResponse($response) + { + $trans_gif_64 = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="; + $expectedResponse = base64_decode($trans_gif_64); + + $url = "\n =========================== \n URL was: " . PiwikTracker::$DEBUG_LAST_REQUESTED_URL; + self::assertEquals($expectedResponse, $response, "Expected GIF beacon, got: <br/>\n" + . var_export($response, true) + . "\n If you are stuck, you can enable [Tracker] debug=1; in config.ini.php to get more debug info." + . base64_encode($response) + . $url + ); + } + + /** + * Checks that the response from bulk tracking is a valid JSON + * string. Will fail the test if JSON status is not success. + * + * @param $response + */ + public static function checkBulkTrackingResponse($response) { + $data = json_decode($response, true); + if (!is_array($data) || empty($response)) { + throw new Exception("Bulk tracking response (".$response.") is not an array: " . var_export($data, true) . "\n"); + } + if(!isset($data['status'])) { + throw new Exception("Returned data didn't have a status: " . var_export($data,true)); + } + + self::assertArrayHasKey('status', $data); + self::assertEquals('success', $data['status'], "expected success, got: " . var_export($data, true)); + } + + public static function makeLocation($city, $region, $country, $lat = null, $long = null, $isp = null) + { + return array(LocationProvider::CITY_NAME_KEY => $city, + LocationProvider::REGION_CODE_KEY => $region, + LocationProvider::COUNTRY_CODE_KEY => $country, + LocationProvider::LATITUDE_KEY => $lat, + LocationProvider::LONGITUDE_KEY => $long, + LocationProvider::ISP_KEY => $isp); + } + + /** + * Returns the Super User token auth that can be used in tests. Can be used to + * do bulk tracking. + * + * @return string + */ + public static function getTokenAuth() + { + return APIUsersManager::getInstance()->getTokenAuth( + self::ADMIN_USER_LOGIN, + UsersManager::getPasswordHash(self::ADMIN_USER_PASSWORD) + ); + } + + public static function createSuperUser($removeExisting = true) + { + $login = self::ADMIN_USER_LOGIN; + $password = UsersManager::getPasswordHash(self::ADMIN_USER_PASSWORD); + $token = self::getTokenAuth(); + + $model = new \Piwik\Plugins\UsersManager\Model(); + if ($removeExisting) { + $model->deleteUserOnly($login); + } + + $user = $model->getUser($login); + + if (empty($user)) { + $model->addUser($login, $password, 'hello@example.org', $login, $token, Date::now()->getDatetime()); + } else { + $model->updateUser($login, $password, 'hello@example.org', $login, $token); + } + + if (empty($user['superuser_access'])) { + $model->setSuperUserAccess($login, true); + } + + return $model->getUserByTokenAuth($token); + } + + /** + * Create three MAIL and two MOBILE scheduled reports + * + * Reports sent by mail can contain PNG graphs when the user specifies it. + * Depending on the system under test, generated images differ slightly. + * Because of this discrepancy, PNG graphs are only tested if the system under test + * has the characteristics described in 'canImagesBeIncludedInScheduledReports'. + * See tests/README.md for more detail. + * + * @see canImagesBeIncludedInScheduledReports + * @param int $idSite id of website created + */ + public static function setUpScheduledReports($idSite) + { + // fake access is needed so API methods can call Piwik::getCurrentUserLogin(), e.g: 'ScheduledReports.addReport' + $pseudoMockAccess = new FakeAccess; + FakeAccess::$superUser = true; + Access::setSingletonInstance($pseudoMockAccess); + + // retrieve available reports + $availableReportMetadata = APIScheduledReports::getReportMetadata($idSite, ScheduledReports::EMAIL_TYPE); + + $availableReportIds = array(); + foreach ($availableReportMetadata as $reportMetadata) { + $availableReportIds[] = $reportMetadata['uniqueId']; + } + + //@review should we also test evolution graphs? + // set-up mail report + APIScheduledReports::getInstance()->addReport( + $idSite, + 'Mail Test report', + 'day', // overridden in getApiForTestingScheduledReports() + 0, + ScheduledReports::EMAIL_TYPE, + ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports() + $availableReportIds, + array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_ONLY) + ); + + // set-up sms report for one website + APIScheduledReports::getInstance()->addReport( + $idSite, + 'SMS Test report, one website', + 'day', // overridden in getApiForTestingScheduledReports() + 0, + MobileMessaging::MOBILE_TYPE, + MobileMessaging::SMS_FORMAT, + array("MultiSites_getOne"), + array("phoneNumbers" => array()) + ); + + // set-up sms report for all websites + APIScheduledReports::getInstance()->addReport( + $idSite, + 'SMS Test report, all websites', + 'day', // overridden in getApiForTestingScheduledReports() + 0, + MobileMessaging::MOBILE_TYPE, + MobileMessaging::SMS_FORMAT, + array("MultiSites_getAll"), + array("phoneNumbers" => array()) + ); + + if (self::canImagesBeIncludedInScheduledReports()) { + // set-up mail report with images + APIScheduledReports::getInstance()->addReport( + $idSite, + 'Mail Test report', + 'day', // overridden in getApiForTestingScheduledReports() + 0, + ScheduledReports::EMAIL_TYPE, + ReportRenderer::HTML_FORMAT, // overridden in getApiForTestingScheduledReports() + $availableReportIds, + array(ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS) + ); + + // set-up mail report with one row evolution based png graph + APIScheduledReports::getInstance()->addReport( + $idSite, + 'Mail Test report', + 'day', + 0, + ScheduledReports::EMAIL_TYPE, + ReportRenderer::HTML_FORMAT, + array('Actions_getPageTitles'), + array( + ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, + ScheduledReports::EVOLUTION_GRAPH_PARAMETER => 'true', + ) + ); + } + } + + /** + * Return true if system under test has Piwik core team's most common configuration + */ + public static function canImagesBeIncludedInScheduledReports() + { + $gdInfo = gd_info(); + return + stristr(php_uname(), self::IMAGES_GENERATED_ONLY_FOR_OS) && + strpos( phpversion(), self::IMAGES_GENERATED_FOR_PHP) !== false && + strpos( $gdInfo['GD Version'], self::IMAGES_GENERATED_FOR_GD) !== false; + } + + public static $geoIpDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoIP.dat.gz'; + public static $geoLiteCityDbUrl = 'http://piwik-team.s3.amazonaws.com/GeoLiteCity.dat.gz'; + + public static function downloadGeoIpDbs() + { + $geoIpOutputDir = PIWIK_INCLUDE_PATH . '/tests/lib/geoip-files'; + self::downloadAndUnzip(self::$geoIpDbUrl, $geoIpOutputDir, 'GeoIP.dat'); + self::downloadAndUnzip(self::$geoLiteCityDbUrl, $geoIpOutputDir, 'GeoIPCity.dat'); + } + + public static function downloadAndUnzip($url, $outputDir, $filename) + { + $bufferSize = 1024 * 1024; + + if (!is_dir($outputDir)) { + mkdir($outputDir); + } + + $deflatedOut = $outputDir . '/' . $filename; + $outfileName = $deflatedOut . '.gz'; + + if (file_exists($deflatedOut)) { + return; + } + + $dump = fopen($url, 'rb'); + $outfile = fopen($outfileName, 'wb'); + while (!feof($dump)) { + fwrite($outfile, fread($dump, $bufferSize), $bufferSize); + } + fclose($dump); + fclose($outfile); + + // unzip the dump + exec("gunzip -c \"" . $outfileName . "\" > \"$deflatedOut\"", $output, $return); + if ($return !== 0) { + Log::info("gunzip failed with file that has following contents:"); + Log::info(file_get_contents($outfile)); + + throw new Exception("gunzip failed($return): " . implode("\n", $output)); + } + } + + protected static function executeLogImporter($logFile, $options) + { + $python = self::getPythonBinary(); + + // create the command + $cmd = $python + . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc + . '-ddd ' // debug + . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files + ; + + foreach ($options as $name => $value) { + $cmd .= $name; + if ($value !== false) { + $cmd .= '="' . $value . '"'; + } + $cmd .= ' '; + } + + $cmd .= '"' . $logFile . '" 2>&1'; + + // run the command + exec($cmd, $output, $result); + if ($result !== 0) { + throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd"); + } + + return $output; + } + + public static function siteCreated($idSite) + { + return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('site') . " WHERE idsite = ?", array($idSite)) != 0; + } + + public static function goalExists($idSite, $idGoal) + { + return Db::fetchOne("SELECT COUNT(*) FROM " . Common::prefixTable('goal') . " WHERE idgoal = ? AND idsite = ?", array($idGoal, $idSite)) != 0; + } + + /** + * Connects to MySQL w/o specifying a database. + */ + public static function connectWithoutDatabase() + { + $dbConfig = Config::getInstance()->database; + $oldDbName = $dbConfig['dbname']; + $dbConfig['dbname'] = null; + + Db::createDatabaseObject($dbConfig); + + $dbConfig['dbname'] = $oldDbName; + } + + /** + * Sets up access instance. + */ + public static function createAccessInstance() + { + Access::setSingletonInstance(null); + Access::getInstance(); + Piwik::postEvent('Request.initAuthenticationObject'); + } + + public function dropDatabase($dbName = null) + { + $dbName = $dbName ?: $this->dbName ?: Config::getInstance()->database_tests['dbname']; + + $this->log("Dropping database '$dbName'..."); + + $config = _parse_ini_file(PIWIK_INCLUDE_PATH . '/config/config.ini.php', true); + $originalDbName = $config['database']['dbname']; + if ($dbName == $originalDbName + && $dbName != 'piwik_tests' + ) { // santity check + throw new \Exception("Trying to drop original database '$originalDbName'. Something's wrong w/ the tests."); + } + + DbHelper::dropDatabase($dbName); + } + + public function log($message) + { + if ($this->printToScreen) { + echo $message . "\n"; + } + } + + // NOTE: since API_Request does sanitization, API methods do not. when calling them, we must + // sometimes do sanitization ourselves. + public static function makeXssContent($type, $sanitize = false) + { + $result = "<script>$('body').html('$type XSS!');</script>"; + if ($sanitize) { + $result = Common::sanitizeInputValue($result); + } + return $result; + } + + public static function updateDatabase($force = false) + { + Cache::deleteTrackerCache(); + Option::clearCache(); + + if ($force) { + // remove version options to force update + Option::deleteLike('version%'); + Option::set('version_core', '0.0'); + } + + $updater = new Updater(); + $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); + if (empty($componentsWithUpdateFile)) { + return false; + } + + $result = CoreUpdater::updateComponents($updater, $componentsWithUpdateFile); + if (!empty($result['coreError']) + || !empty($result['warnings']) + || !empty($result['errors']) + ) { + throw new \Exception("Failed to update database (errors or warnings found): " . print_r($result, true)); + } + + return $result; + } +} + +// needed by tests that use stored segments w/ the proxy index.php +class OverrideLogin extends Access +{ + public function getLogin() + { + return 'superUserLogin'; + } +}
\ No newline at end of file diff --git a/tests/PHPUnit/Impl/IntegrationTestCase.php b/tests/PHPUnit/Impl/IntegrationTestCase.php new file mode 100644 index 0000000000..7036993eb0 --- /dev/null +++ b/tests/PHPUnit/Impl/IntegrationTestCase.php @@ -0,0 +1,97 @@ +<?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\Impl; + +use Piwik\Config; +use Piwik\Db; + +/** + * Tests extending IntegrationTestCase are much slower to run: the setUp will + * create all Piwik tables in a freshly empty test database. + * + * This allows each test method to start from a clean DB and setup initial state to + * then test it. + * + */ +class IntegrationTestCase extends SystemTestCase +{ + /** + * @var Fixture + */ + public static $fixture; + public static $tableData; + + /** + * Implementation details: + * + * To increase speed of tests, database setup is done once in setUpBeforeClass. + * Afterwards, the content of the tables is stored in a static class variable, + * self::$tableData. Before each individual test, the database tables are + * truncated and the data in self::$tableData is restored. + * + * If your test modifies table columns, you will need to recreate the database + * completely. This can be accomplished by: + * + * public function setUp() + * { + * self::$fixture->performSetUp(); + * } + * + * public function tearDown() + * { + * parent::tearDown(); + * self::$fixture->performTearDown(); + * } + */ + public static function setUpBeforeClass() + { + static::configureFixture(static::$fixture); + parent::setUpBeforeClass(); + + self::$tableData = self::getDbTablesWithData(); + } + + public static function tearDownAfterClass() + { + self::$tableData = array(); + } + + /** + * Setup the database and create the base tables for all tests + */ + public function setUp() + { + parent::setUp(); + + Config::getInstance()->setTestEnvironment(); + + if (!empty(self::$tableData)) { + self::restoreDbTables(self::$tableData); + } + } + + /** + * Resets all caches and drops the database + */ + public function tearDown() + { + self::$fixture->clearInMemoryCaches(); + + parent::tearDown(); + } + + protected static function configureFixture($fixture) + { + $fixture->loadTranslations = false; + $fixture->createSuperUser = false; + $fixture->configureComponents = false; + } +} + +IntegrationTestCase::$fixture = new Fixture();
\ No newline at end of file diff --git a/tests/PHPUnit/SystemTestCase.php b/tests/PHPUnit/Impl/SystemTestCase.php index 90e7da4725..ad7845efd4 100755 --- a/tests/PHPUnit/SystemTestCase.php +++ b/tests/PHPUnit/Impl/SystemTestCase.php @@ -5,7 +5,8 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Tests; + +namespace Piwik\Tests\Impl; use Exception; use Piwik\ArchiveProcessor\Rules; @@ -16,9 +17,7 @@ use Piwik\Db; use Piwik\DbHelper; use Piwik\ReportRenderer; use Piwik\Translate; -use Piwik\Tests\Impl\TestRequestCollection; -use Piwik\Tests\Impl\TestRequestResponse; -use Piwik\Tests\Impl\ApiTestConfig; +use Piwik\Tests\Impl\Fixture; use Piwik\Log; use PHPUnit_Framework_TestCase; @@ -42,6 +41,8 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase protected $missingExpectedFiles = array(); protected $comparisonFailures = array(); + public static $fixture; + public static function setUpBeforeClass() { Log::debug("Setting up " . get_called_class()); @@ -489,7 +490,7 @@ abstract class SystemTestCase extends PHPUnit_Framework_TestCase */ public static function getPathToTestDirectory() { - return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'System'; + return dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'System'; } /** diff --git a/tests/PHPUnit/Impl/TestRequestCollection.php b/tests/PHPUnit/Impl/TestRequestCollection.php index 20208765e3..556ab1bb24 100644 --- a/tests/PHPUnit/Impl/TestRequestCollection.php +++ b/tests/PHPUnit/Impl/TestRequestCollection.php @@ -12,7 +12,6 @@ use Piwik\API\DocumentationGenerator; use Piwik\API\Proxy; use Piwik\API\Request; use Piwik\UrlHelper; -use Piwik\Tests\SystemTestCase; use \Exception; use \PHPUnit_Framework_Assert; diff --git a/tests/PHPUnit/Impl/TestRequestResponse.php b/tests/PHPUnit/Impl/TestRequestResponse.php index 6ceeb564f2..f71a430aa6 100644 --- a/tests/PHPUnit/Impl/TestRequestResponse.php +++ b/tests/PHPUnit/Impl/TestRequestResponse.php @@ -9,7 +9,6 @@ namespace Piwik\Tests\Impl; use Piwik\API\Request; -use Piwik\Tests\SystemTestCase; use PHPUnit_Framework_Assert as Asserts; use Exception; diff --git a/tests/PHPUnit/Integration/AccessTest.php b/tests/PHPUnit/Integration/AccessTest.php index 12cd119d8c..aad0e22766 100644 --- a/tests/PHPUnit/Integration/AccessTest.php +++ b/tests/PHPUnit/Integration/AccessTest.php @@ -7,6 +7,7 @@ */ use Piwik\Access; use Piwik\AuthResult; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_AccessTest diff --git a/tests/PHPUnit/Integration/ArchiveProcessingTest.php b/tests/PHPUnit/Integration/ArchiveProcessingTest.php index 65f1dd0c7f..88ec83bea6 100644 --- a/tests/PHPUnit/Integration/ArchiveProcessingTest.php +++ b/tests/PHPUnit/Integration/ArchiveProcessingTest.php @@ -20,6 +20,7 @@ use Piwik\Plugins\SitesManager\API; use Piwik\Segment; use Piwik\SettingsServer; use Piwik\Site; +use Piwik\Tests\Impl\IntegrationTestCase; class Core_ArchiveProcessorTest extends ArchiveProcessor\Loader { diff --git a/tests/PHPUnit/Unit/AssetManager/UIAssetMinifierTest.php b/tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php index df62e5c86b..1ece0ca556 100644 --- a/tests/PHPUnit/Unit/AssetManager/UIAssetMinifierTest.php +++ b/tests/PHPUnit/Integration/AssetManager/UIAssetMinifierTest.php @@ -10,7 +10,7 @@ use Piwik\AssetManager\UIAsset\OnDiskUIAsset; use Piwik\AssetManager\UIAssetMinifier; -class UIAssetMinifierTest extends PHPUnit_Framework_TestCase +class Piwik_Test_UIAssetMinifierTest extends PHPUnit_Framework_TestCase { /** diff --git a/tests/PHPUnit/Integration/CliMultiTest.php b/tests/PHPUnit/Integration/CliMultiTest.php index 6ae07f2318..89555d4d01 100644 --- a/tests/PHPUnit/Integration/CliMultiTest.php +++ b/tests/PHPUnit/Integration/CliMultiTest.php @@ -8,8 +8,8 @@ use Piwik\CliMulti; use Piwik\Version; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixture; /** * Class Core_CliMultiTest diff --git a/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php b/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php index b9826dc676..4fcba84352 100644 --- a/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php +++ b/tests/PHPUnit/Integration/CronArchive/SharedSiteIdsTest.php @@ -7,6 +7,7 @@ */ use Piwik\CronArchive\SharedSiteIds; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group Core diff --git a/tests/PHPUnit/Integration/DbTest.php b/tests/PHPUnit/Integration/DbTest.php index aacef131e9..562e8f9a35 100644 --- a/tests/PHPUnit/Integration/DbTest.php +++ b/tests/PHPUnit/Integration/DbTest.php @@ -7,6 +7,7 @@ */ use Piwik\Common; use Piwik\Db; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_DbTest diff --git a/tests/PHPUnit/Unit/HttpTest.php b/tests/PHPUnit/Integration/HttpTest.php index 71f03aa528..9d197a61a5 100644 --- a/tests/PHPUnit/Unit/HttpTest.php +++ b/tests/PHPUnit/Integration/HttpTest.php @@ -6,12 +6,12 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ use Piwik\Http; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * @group HttpTest */ -class HttpTest extends PHPUnit_Framework_TestCase +class Piwik_Test_HttpTest extends PHPUnit_Framework_TestCase { /** * Dataprovider for testFetchRemoteFile diff --git a/tests/PHPUnit/Integration/JsProxyTest.php b/tests/PHPUnit/Integration/JsProxyTest.php index cd4c84a763..d3991fb6a9 100644 --- a/tests/PHPUnit/Integration/JsProxyTest.php +++ b/tests/PHPUnit/Integration/JsProxyTest.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; class Test_Piwik_JsProxy extends PHPUnit_Framework_TestCase { diff --git a/tests/PHPUnit/Integration/LogTest.php b/tests/PHPUnit/Integration/LogTest.php index b7271dc866..6e453fa858 100644 --- a/tests/PHPUnit/Integration/LogTest.php +++ b/tests/PHPUnit/Integration/LogTest.php @@ -12,6 +12,7 @@ use Piwik\Error; use Piwik\ExceptionHandler; use Piwik\Log; use Piwik\Plugins\TestPlugin\TestLoggingUtility; +use Piwik\Tests\Impl\IntegrationTestCase; require_once PIWIK_INCLUDE_PATH . '/tests/resources/TestPluginLogClass.php'; @@ -31,9 +32,9 @@ class Core_LogTest extends IntegrationTestCase 'screen' => 'dummy error message<br /> <br /> --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php', - 'file' => '[Core_LogTest] LogTest.php(165): dummy error message + 'file' => '[Core_LogTest] LogTest.php(166): dummy error message dummy backtrace', - 'database' => '[Core_LogTest] LogTest.php(165): dummy error message + 'database' => '[Core_LogTest] LogTest.php(166): dummy error message dummy backtrace' ); diff --git a/tests/PHPUnit/Integration/OptionTest.php b/tests/PHPUnit/Integration/OptionTest.php index 6bab1cf65b..42c8418e12 100644 --- a/tests/PHPUnit/Integration/OptionTest.php +++ b/tests/PHPUnit/Integration/OptionTest.php @@ -8,6 +8,7 @@ use Piwik\Common; use Piwik\Db; use Piwik\Option; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_OptionTest diff --git a/tests/PHPUnit/Integration/PiwikTest.php b/tests/PHPUnit/Integration/PiwikTest.php index fc04c81398..99262e56ba 100644 --- a/tests/PHPUnit/Integration/PiwikTest.php +++ b/tests/PHPUnit/Integration/PiwikTest.php @@ -11,6 +11,7 @@ use Piwik\MetricsFormatter; use Piwik\Piwik; use Piwik\Plugins\SitesManager\API; use Piwik\Translate; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_PiwikTest diff --git a/tests/PHPUnit/Integration/Plugin/SettingsTest.php b/tests/PHPUnit/Integration/Plugin/SettingsTest.php index 3846f4cd15..5c9b16909b 100644 --- a/tests/PHPUnit/Integration/Plugin/SettingsTest.php +++ b/tests/PHPUnit/Integration/Plugin/SettingsTest.php @@ -9,6 +9,7 @@ use Piwik\Access; use Piwik\Plugin\Settings as PluginSettings; use Piwik\Settings\Setting; +use Piwik\Tests\Impl\IntegrationTestCase; class CorePluginSettingsTest extends \Piwik\Plugins\ExampleSettingsPlugin\Settings { @@ -416,7 +417,7 @@ class Core_Plugin_SettingsTest extends IntegrationTestCase public function test_getSettingsForCurrentUser_shouldReturnAllSettingsIfEnoughPermissionsAndSortThemBySettingOrder() { - if(\Piwik\Tests\SystemTestCase::isPhpVersion53()) { + if(\Piwik\Tests\Impl\SystemTestCase::isPhpVersion53()) { $this->markTestSkipped('does not pass on PHP 5.3.3'); } $this->setSuperUser(); diff --git a/tests/PHPUnit/Unit/ReleaseCheckListTest.php b/tests/PHPUnit/Integration/ReleaseCheckListTest.php index 255c03fb79..947b06a537 100644 --- a/tests/PHPUnit/Unit/ReleaseCheckListTest.php +++ b/tests/PHPUnit/Integration/ReleaseCheckListTest.php @@ -6,13 +6,11 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ use Piwik\Filesystem; -use Piwik\Plugin\Manager; -use Piwik\SettingsServer; /** * @group ReleaseCheckListTest */ -class ReleaseCheckListTest extends PHPUnit_Framework_TestCase +class Test_Piwik_ReleaseCheckListTest extends PHPUnit_Framework_TestCase { public function setUp() { diff --git a/tests/PHPUnit/Integration/ReportTest.php b/tests/PHPUnit/Integration/ReportTest.php index a7dc7509c4..ce3d87d38f 100644 --- a/tests/PHPUnit/Integration/ReportTest.php +++ b/tests/PHPUnit/Integration/ReportTest.php @@ -18,7 +18,8 @@ use Piwik\WidgetsList; use Piwik\Translate; use Piwik\Menu\MenuReporting; use Piwik\Plugin\Manager as PluginManager; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; class GetBasicReport extends Report { diff --git a/tests/PHPUnit/Integration/SegmentTest.php b/tests/PHPUnit/Integration/SegmentTest.php index 00312063c0..15277e379d 100644 --- a/tests/PHPUnit/Integration/SegmentTest.php +++ b/tests/PHPUnit/Integration/SegmentTest.php @@ -8,6 +8,7 @@ use Piwik\Access; use Piwik\Common; use Piwik\Segment; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group SegmentTest diff --git a/tests/PHPUnit/Unit/ServeStaticFileTest.php b/tests/PHPUnit/Integration/ServeStaticFileTest.php index a3ec57a7af..c8ff7f9c69 100644 --- a/tests/PHPUnit/Unit/ServeStaticFileTest.php +++ b/tests/PHPUnit/Integration/ServeStaticFileTest.php @@ -17,7 +17,7 @@ use Piwik\ProxyHttp; use Piwik\SettingsServer; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; define("TEST_FILE_LOCATION", realpath(dirname(__FILE__) . "/../../resources/lipsum.txt")); define("TEST_FILE_CONTENT_TYPE", "text/plain"); diff --git a/tests/PHPUnit/Integration/SqlTest.php b/tests/PHPUnit/Integration/SqlTest.php index 843e4e950a..3d6fbac9e3 100755 --- a/tests/PHPUnit/Integration/SqlTest.php +++ b/tests/PHPUnit/Integration/SqlTest.php @@ -1,5 +1,6 @@ <?php use Piwik\Db; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Piwik - free/libre analytics platform diff --git a/tests/PHPUnit/Integration/Tracker/ActionTest.php b/tests/PHPUnit/Integration/Tracker/ActionTest.php index 2b7ea04ac0..1246fb15f6 100644 --- a/tests/PHPUnit/Integration/Tracker/ActionTest.php +++ b/tests/PHPUnit/Integration/Tracker/ActionTest.php @@ -13,6 +13,8 @@ use Piwik\Tracker\PageUrl; use Piwik\Tracker\Request; use Piwik\Translate; use Piwik\Plugin\Manager as PluginManager; +use Piwik\Tests\Impl\IntegrationTestCase; + /** * Piwik - free/libre analytics platform * diff --git a/tests/PHPUnit/Integration/Tracker/DbTest.php b/tests/PHPUnit/Integration/Tracker/DbTest.php index 71fd3a97fd..91d01d0cfe 100644 --- a/tests/PHPUnit/Integration/Tracker/DbTest.php +++ b/tests/PHPUnit/Integration/Tracker/DbTest.php @@ -7,6 +7,7 @@ */ use Piwik\Common; use Piwik\Db; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Tracker DB test diff --git a/tests/PHPUnit/Integration/Tracker/Visit2Test.php b/tests/PHPUnit/Integration/Tracker/Visit2Test.php index 9910d7f51d..e28c3ba410 100644 --- a/tests/PHPUnit/Integration/Tracker/Visit2Test.php +++ b/tests/PHPUnit/Integration/Tracker/Visit2Test.php @@ -14,7 +14,8 @@ use Piwik\Tracker\Request; use Piwik\Tracker\Visitor; use Piwik\Piwik; use Piwik\EventDispatcher; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; class FakeTrackerVisitDimension1 extends VisitDimension { diff --git a/tests/PHPUnit/Integration/Tracker/VisitTest.php b/tests/PHPUnit/Integration/Tracker/VisitTest.php index 69c1569251..cdc69110d4 100644 --- a/tests/PHPUnit/Integration/Tracker/VisitTest.php +++ b/tests/PHPUnit/Integration/Tracker/VisitTest.php @@ -10,6 +10,7 @@ use Piwik\IP; use Piwik\Plugins\SitesManager\API; use Piwik\Tracker\Request; use Piwik\Tracker\VisitExcluded; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_Tracker_VisitTest diff --git a/tests/PHPUnit/Integration/TrackerTest.php b/tests/PHPUnit/Integration/TrackerTest.php index c8176a1a89..53865b0993 100644 --- a/tests/PHPUnit/Integration/TrackerTest.php +++ b/tests/PHPUnit/Integration/TrackerTest.php @@ -6,7 +6,8 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * @group Core diff --git a/tests/PHPUnit/Integration/TravisEnvironmentTest.php b/tests/PHPUnit/Integration/TravisEnvironmentTest.php index a8b6dfc27a..c8fce30ba2 100644 --- a/tests/PHPUnit/Integration/TravisEnvironmentTest.php +++ b/tests/PHPUnit/Integration/TravisEnvironmentTest.php @@ -1,6 +1,7 @@ <?php use Piwik\Translate; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class TravisEnvironmentTest diff --git a/tests/PHPUnit/Integration/UpdaterTest.php b/tests/PHPUnit/Integration/UpdaterTest.php index a3070a6950..a0b7662b63 100644 --- a/tests/PHPUnit/Integration/UpdaterTest.php +++ b/tests/PHPUnit/Integration/UpdaterTest.php @@ -7,9 +7,9 @@ */ namespace Piwik\Tests\Integration\Core; -use IntegrationTestCase; +use Piwik\Tests\Impl\IntegrationTestCase; use Piwik\Updater; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; /** * Class Core_UpdaterTest diff --git a/tests/PHPUnit/Integration/ViewDataTable/ManagerTest.php b/tests/PHPUnit/Integration/ViewDataTable/ManagerTest.php index 394bfe4039..6f73818801 100644 --- a/tests/PHPUnit/Integration/ViewDataTable/ManagerTest.php +++ b/tests/PHPUnit/Integration/ViewDataTable/ManagerTest.php @@ -8,6 +8,7 @@ use Piwik\Access; use Piwik\ViewDataTable\Manager as ViewDataTableManager; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_Plugin_SettingsTest diff --git a/tests/PHPUnit/Integration/WidgetsListTest.php b/tests/PHPUnit/Integration/WidgetsListTest.php index a616bdd5bf..865dd5a72a 100644 --- a/tests/PHPUnit/Integration/WidgetsListTest.php +++ b/tests/PHPUnit/Integration/WidgetsListTest.php @@ -9,7 +9,8 @@ use Piwik\Access; use Piwik\Plugins\Goals\API; use Piwik\WidgetsList; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\IntegrationTestCase; /** * Class Core_WidgetsListTest diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index 6d63779e9c..8cd33978dc 100644 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -5,92 +5,19 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\Config; -use Piwik\Db; -use Piwik\Tests\Fixture; -use Piwik\Tests\SystemTestCase; /** - * Tests extending IntegrationTestCase are much slower to run: the setUp will - * create all Piwik tables in a freshly empty test database. - * - * This allows each test method to start from a clean DB and setup initial state to - * then test it. - * + * @deprecated since 2.8.0 extend \Piwik\Tests\Impl\SystemTestCase instead */ -class IntegrationTestCase extends SystemTestCase +class IntegrationTestCase extends \Piwik\Tests\Impl\SystemTestCase { - /** - * @var Fixture - */ - public static $fixture; - public static $tableData; - /** - * Implementation details: - * - * To increase speed of tests, database setup is done once in setUpBeforeClass. - * Afterwards, the content of the tables is stored in a static class variable, - * self::$tableData. Before each individual test, the database tables are - * truncated and the data in self::$tableData is restored. - * - * If your test modifies table columns, you will need to recreate the database - * completely. This can be accomplished by: - * - * public function setUp() - * { - * self::$fixture->performSetUp(); - * } - * - * public function tearDown() - * { - * parent::tearDown(); - * self::$fixture->performTearDown(); - * } - */ public static function setUpBeforeClass() { - static::configureFixture(static::$fixture); - parent::setUpBeforeClass(); - - self::$tableData = self::getDbTablesWithData(); - } - - public static function tearDownAfterClass() - { - self::$tableData = array(); - } - - /** - * Setup the database and create the base tables for all tests - */ - public function setUp() - { - parent::setUp(); + \Piwik\Log::debug('\IntegrationTestCase is deprecated since 2.8.0 extend \Piwik\Tests\Impl\SystemTestCase instead'); - Config::getInstance()->setTestEnvironment(); - - if (!empty(self::$tableData)) { - self::restoreDbTables(self::$tableData); - } - } - - /** - * Resets all caches and drops the database - */ - public function tearDown() - { - self::$fixture->clearInMemoryCaches(); - - parent::tearDown(); - } - - protected static function configureFixture($fixture) - { - $fixture->loadTranslations = false; - $fixture->createSuperUser = false; - $fixture->configureComponents = false; + parent::setUpBeforeClass(); } } -IntegrationTestCase::$fixture = new Fixture();
\ No newline at end of file +IntegrationTestCase::$fixture = new \Piwik\Tests\Impl\Fixture();
\ No newline at end of file diff --git a/tests/PHPUnit/System/AnnotationsTest.php b/tests/PHPUnit/System/AnnotationsTest.php index 9acf8c7e27..f73587f3ce 100755 --- a/tests/PHPUnit/System/AnnotationsTest.php +++ b/tests/PHPUnit/System/AnnotationsTest.php @@ -10,8 +10,8 @@ namespace Piwik\Tests\System; use Piwik\Access; use Piwik\API\Request; use Piwik\Plugins\Annotations\API; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesWithAnnotations; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesWithAnnotations; use FakeAccess; use Exception; diff --git a/tests/PHPUnit/System/ApiGetReportMetadataTest.php b/tests/PHPUnit/System/ApiGetReportMetadataTest.php index be86b7f3ab..fd9b2b308c 100755 --- a/tests/PHPUnit/System/ApiGetReportMetadataTest.php +++ b/tests/PHPUnit/System/ApiGetReportMetadataTest.php @@ -8,8 +8,8 @@ namespace Piwik\Tests\System; use Piwik\API\Proxy; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ThreeGoalsOnePageview; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ThreeGoalsOnePageview; /** * This tests the output of the API plugin API diff --git a/tests/PHPUnit/System/ApiGetReportMetadataYearTest.php b/tests/PHPUnit/System/ApiGetReportMetadataYearTest.php index d3df009834..988419f717 100755 --- a/tests/PHPUnit/System/ApiGetReportMetadataYearTest.php +++ b/tests/PHPUnit/System/ApiGetReportMetadataYearTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\InvalidVisits; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\InvalidVisits; /** * test the Yearly metadata API response, diff --git a/tests/PHPUnit/System/ArchiveCronTest.php b/tests/PHPUnit/System/ArchiveCronTest.php index 75b7fcb2af..768ded9892 100644 --- a/tests/PHPUnit/System/ArchiveCronTest.php +++ b/tests/PHPUnit/System/ArchiveCronTest.php @@ -9,9 +9,9 @@ namespace Piwik\Tests\System; use Piwik\Date; use Piwik\Plugins\SitesManager\API; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManySitesImportedLogs; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManySitesImportedLogs; +use Piwik\Tests\Impl\Fixture; use Exception; /** diff --git a/tests/PHPUnit/System/ArchiveInvalidationTest.php b/tests/PHPUnit/System/ArchiveInvalidationTest.php index 6d8d22a2c3..3715014525 100644 --- a/tests/PHPUnit/System/ArchiveInvalidationTest.php +++ b/tests/PHPUnit/System/ArchiveInvalidationTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\API\Request; use Piwik\Config; -use Piwik\Tests\Fixtures\VisitsTwoWebsitesWithAdditionalVisits; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\VisitsTwoWebsitesWithAdditionalVisits; +use Piwik\Tests\Impl\SystemTestCase; /** * Track visits before website creation date and test that Piwik handles them correctly. diff --git a/tests/PHPUnit/System/ArchiveWebTest.php b/tests/PHPUnit/System/ArchiveWebTest.php index 53f262df1a..8d47fb7204 100644 --- a/tests/PHPUnit/System/ArchiveWebTest.php +++ b/tests/PHPUnit/System/ArchiveWebTest.php @@ -9,9 +9,9 @@ namespace Piwik\Tests\System; use Piwik\Option; use Piwik\Http; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManySitesImportedLogs; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManySitesImportedLogs; +use Piwik\Tests\Impl\Fixture; use Exception; /** diff --git a/tests/PHPUnit/System/AutoSuggestAPITest.php b/tests/PHPUnit/System/AutoSuggestAPITest.php index 535e1d4250..d35a273da8 100644 --- a/tests/PHPUnit/System/AutoSuggestAPITest.php +++ b/tests/PHPUnit/System/AutoSuggestAPITest.php @@ -9,9 +9,9 @@ namespace Piwik\Tests\System; use Piwik\API\Request; use Piwik\Date; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManyVisitsWithGeoIP; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManyVisitsWithGeoIP; +use Piwik\Tests\Impl\Fixture; /** * testing a the auto suggest API for all known segments diff --git a/tests/PHPUnit/System/BackwardsCompatibility1XTest.php b/tests/PHPUnit/System/BackwardsCompatibility1XTest.php index 5d20fa81a9..2b2a616ada 100644 --- a/tests/PHPUnit/System/BackwardsCompatibility1XTest.php +++ b/tests/PHPUnit/System/BackwardsCompatibility1XTest.php @@ -10,9 +10,9 @@ 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; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\SqlDump; +use Piwik\Tests\Impl\Fixture; /** * Tests that Piwik 2.0 works w/ data from Piwik 1.12. diff --git a/tests/PHPUnit/System/BlobReportLimitingTest.php b/tests/PHPUnit/System/BlobReportLimitingTest.php index 431709d3cf..56a3a0126d 100755 --- a/tests/PHPUnit/System/BlobReportLimitingTest.php +++ b/tests/PHPUnit/System/BlobReportLimitingTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\Config; use Piwik\Plugins\Actions\ArchivingHelper; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManyVisitsWithMockLocationProvider; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManyVisitsWithMockLocationProvider; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php'; diff --git a/tests/PHPUnit/System/CsvExportTest.php b/tests/PHPUnit/System/CsvExportTest.php index 48c9342f8e..4533afc943 100755 --- a/tests/PHPUnit/System/CsvExportTest.php +++ b/tests/PHPUnit/System/CsvExportTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; /** * Test CSV export with Expanded rows, Translated labels, Different languages diff --git a/tests/PHPUnit/System/CustomEventsTest.php b/tests/PHPUnit/System/CustomEventsTest.php index b2e92b30a9..6df0f5a642 100644 --- a/tests/PHPUnit/System/CustomEventsTest.php +++ b/tests/PHPUnit/System/CustomEventsTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomEvents; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomEvents; /** * Testing Custom Events diff --git a/tests/PHPUnit/System/EcommerceOrderWithItemsTest.php b/tests/PHPUnit/System/EcommerceOrderWithItemsTest.php index e2ab0ffd44..1dbf092166 100755 --- a/tests/PHPUnit/System/EcommerceOrderWithItemsTest.php +++ b/tests/PHPUnit/System/EcommerceOrderWithItemsTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\Date; use Piwik\Piwik; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesEcommerceOrderWithItems; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesEcommerceOrderWithItems; /** * Tests API methods after ecommerce orders are tracked. diff --git a/tests/PHPUnit/System/FlattenReportsTest.php b/tests/PHPUnit/System/FlattenReportsTest.php index e38e10cf7f..46787d1da9 100644 --- a/tests/PHPUnit/System/FlattenReportsTest.php +++ b/tests/PHPUnit/System/FlattenReportsTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManyVisitsWithSubDirReferrersAndCustomVars; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManyVisitsWithSubDirReferrersAndCustomVars; /** * Tests the flattening of reports. diff --git a/tests/PHPUnit/System/ImportLogsTest.php b/tests/PHPUnit/System/ImportLogsTest.php index abf7d6a42a..9d52c6a112 100755 --- a/tests/PHPUnit/System/ImportLogsTest.php +++ b/tests/PHPUnit/System/ImportLogsTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\Access; use Piwik\Plugins\SitesManager\API; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManySitesImportedLogs; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManySitesImportedLogs; /** * Tests the log importer. diff --git a/tests/PHPUnit/System/LabelFilterTest.php b/tests/PHPUnit/System/LabelFilterTest.php index 487e09c07f..5493a05e29 100644 --- a/tests/PHPUnit/System/LabelFilterTest.php +++ b/tests/PHPUnit/System/LabelFilterTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\OneVisitSeveralPageViews; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\OneVisitSeveralPageViews; /** * Tests the class LabelFilter. diff --git a/tests/PHPUnit/System/ManyVisitorsOneWebsiteTest.php b/tests/PHPUnit/System/ManyVisitorsOneWebsiteTest.php index ec1a0f4f16..2cf094b92f 100755 --- a/tests/PHPUnit/System/ManyVisitorsOneWebsiteTest.php +++ b/tests/PHPUnit/System/ManyVisitorsOneWebsiteTest.php @@ -10,8 +10,8 @@ namespace Piwik\Tests\System; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php'; use Piwik\Date; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ManyVisitsWithGeoIP; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManyVisitsWithGeoIP; /** * Tests w/ 14 visitors w/ 2 visits each. diff --git a/tests/PHPUnit/System/MultipleSitesArchivingTest.php b/tests/PHPUnit/System/MultipleSitesArchivingTest.php index 6d447abb2f..436ceaa50e 100644 --- a/tests/PHPUnit/System/MultipleSitesArchivingTest.php +++ b/tests/PHPUnit/System/MultipleSitesArchivingTest.php @@ -9,9 +9,9 @@ namespace Piwik\Tests\System; use Piwik\Config; use Piwik\Piwik; -use Piwik\Tests\Fixture; -use Piwik\Tests\Fixtures\ThreeSitesWithSharedVisitors; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\Fixture; +use Piwik\Tests\Impl\Fixtures\ThreeSitesWithSharedVisitors; +use Piwik\Tests\Impl\SystemTestCase; /** * @group Core diff --git a/tests/PHPUnit/System/NoVisitTest.php b/tests/PHPUnit/System/NoVisitTest.php index 4a81736073..45f2b6ed06 100755 --- a/tests/PHPUnit/System/NoVisitTest.php +++ b/tests/PHPUnit/System/NoVisitTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\InvalidVisits; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\InvalidVisits; /** * testing various wrong Tracker requests and check that they behave as expected: diff --git a/tests/PHPUnit/System/NonUnicodeTest.php b/tests/PHPUnit/System/NonUnicodeTest.php index 370c4acf16..943940ac43 100755 --- a/tests/PHPUnit/System/NonUnicodeTest.php +++ b/tests/PHPUnit/System/NonUnicodeTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\SomeVisitsWithNonUnicodePageTitles; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\SomeVisitsWithNonUnicodePageTitles; /** * Tests that visits track & reports display correctly when non-unicode text is diff --git a/tests/PHPUnit/System/OneVisitorLongUrlsTruncatedTest.php b/tests/PHPUnit/System/OneVisitorLongUrlsTruncatedTest.php index 83a17e0f11..4d72a31c8a 100644 --- a/tests/PHPUnit/System/OneVisitorLongUrlsTruncatedTest.php +++ b/tests/PHPUnit/System/OneVisitorLongUrlsTruncatedTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\SomeVisitsWithLongUrls; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\SomeVisitsWithLongUrls; /** * Tests that filter_truncate works recursively in Page URLs report AND in the case there are 2 different data Keywords -> search engine diff --git a/tests/PHPUnit/System/OneVisitorNoKeywordSpecifiedTest.php b/tests/PHPUnit/System/OneVisitorNoKeywordSpecifiedTest.php index 4bd244f663..eb5bec6de3 100755 --- a/tests/PHPUnit/System/OneVisitorNoKeywordSpecifiedTest.php +++ b/tests/PHPUnit/System/OneVisitorNoKeywordSpecifiedTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsNoKeywordWithBot; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsNoKeywordWithBot; /** * 1) Tests empty google kwd works nicely in Live! output and Top keywords diff --git a/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTestsTest.php b/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTestsTest.php index 9441f39318..7cd7b9f632 100755 --- a/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTestsTest.php +++ b/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeArchivingTestsTest.php @@ -10,8 +10,8 @@ namespace Piwik\Tests\System; use Piwik\Common; use Piwik\Db; use Piwik\Piwik; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\VisitsOverSeveralDays; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\VisitsOverSeveralDays; /** * Tests some API using range periods & makes sure the correct amount of blob/numeric diff --git a/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeTest.php b/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeTest.php index e744859b70..f7ea478466 100755 --- a/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeTest.php +++ b/tests/PHPUnit/System/OneVisitorOneWebsiteSeveralDaysDateRangeTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\VisitsOverSeveralDays; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\VisitsOverSeveralDays; /** * Use case testing various important features: diff --git a/tests/PHPUnit/System/OneVisitorSeveralDaysImportedInRandomOrderTest.php b/tests/PHPUnit/System/OneVisitorSeveralDaysImportedInRandomOrderTest.php index 9ad8791c4c..0d13a6a246 100644 --- a/tests/PHPUnit/System/OneVisitorSeveralDaysImportedInRandomOrderTest.php +++ b/tests/PHPUnit/System/OneVisitorSeveralDaysImportedInRandomOrderTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\VisitOverSeveralDaysImportedLogs; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\VisitOverSeveralDaysImportedLogs; /** * @group Core diff --git a/tests/PHPUnit/System/OneVisitorTwoVisitsTest.php b/tests/PHPUnit/System/OneVisitorTwoVisitsTest.php index 6c1b3d69ca..94a7a3e307 100755 --- a/tests/PHPUnit/System/OneVisitorTwoVisitsTest.php +++ b/tests/PHPUnit/System/OneVisitorTwoVisitsTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\API\Proxy; use Piwik\Archive; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\OneVisitorTwoVisits; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\OneVisitorTwoVisits; use Exception; /** diff --git a/tests/PHPUnit/System/OneVisitorTwoVisitsWithCookieSupportTest.php b/tests/PHPUnit/System/OneVisitorTwoVisitsWithCookieSupportTest.php index 856e10efad..206ee08276 100755 --- a/tests/PHPUnit/System/OneVisitorTwoVisitsWithCookieSupportTest.php +++ b/tests/PHPUnit/System/OneVisitorTwoVisitsWithCookieSupportTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\OneVisitorTwoVisits; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\OneVisitorTwoVisits; /** * Same as OneVisitorTwoVisits.test.php, but with cookie support, which incurs some slight changes diff --git a/tests/PHPUnit/System/PeriodIsRangeDateIsLastNMetadataAndNormalAPITest.php b/tests/PHPUnit/System/PeriodIsRangeDateIsLastNMetadataAndNormalAPITest.php index 52739d310b..92da5acaa6 100755 --- a/tests/PHPUnit/System/PeriodIsRangeDateIsLastNMetadataAndNormalAPITest.php +++ b/tests/PHPUnit/System/PeriodIsRangeDateIsLastNMetadataAndNormalAPITest.php @@ -8,8 +8,8 @@ namespace Piwik\Tests\System; use Piwik\Date; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; /** * test Metadata API + period=range&date=lastN diff --git a/tests/PHPUnit/System/PivotByQueryParamTest.php b/tests/PHPUnit/System/PivotByQueryParamTest.php index 358b9b03c0..88829fec0a 100644 --- a/tests/PHPUnit/System/PivotByQueryParamTest.php +++ b/tests/PHPUnit/System/PivotByQueryParamTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\Config; use Piwik\Date; -use Piwik\Tests\Fixtures\ManyVisitsWithMockLocationProvider; -use Piwik\Tests\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ManyVisitsWithMockLocationProvider; +use Piwik\Tests\Impl\SystemTestCase; /** * @group Core diff --git a/tests/PHPUnit/System/PrivacyManagerTest.php b/tests/PHPUnit/System/PrivacyManagerTest.php index 7ba93e7cd2..79fcd1bccd 100644 --- a/tests/PHPUnit/System/PrivacyManagerTest.php +++ b/tests/PHPUnit/System/PrivacyManagerTest.php @@ -25,10 +25,10 @@ use Piwik\Plugins\VisitorInterest\API as APIVisitorInterest; use Piwik\Site; use Piwik\Tracker\Cache; use Piwik\Tracker\GoalManager; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixture; -require_once 'PrivacyManager/PrivacyManager.php'; +require_once PIWIK_INCLUDE_PATH . '/plugins/PrivacyManager/PrivacyManager.php'; /** * @group PrivacyManagerTest diff --git a/tests/PHPUnit/System/PurgeDataTest.php b/tests/PHPUnit/System/PurgeDataTest.php index 30bf2244ff..c8715cd93e 100755 --- a/tests/PHPUnit/System/PurgeDataTest.php +++ b/tests/PHPUnit/System/PurgeDataTest.php @@ -12,8 +12,8 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockLocationProvider.php'; use Piwik\API\Request; use Piwik\Plugins\PrivacyManager\PrivacyManager; use Piwik\Plugins\PrivacyManager\ReportsPurger; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\OneVisitorTwoVisits; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\OneVisitorTwoVisits; /** * TODO: shouldn't this be merged w/ PrivacyManagerTest? the original data purging tests are there diff --git a/tests/PHPUnit/System/RowEvolutionTest.php b/tests/PHPUnit/System/RowEvolutionTest.php index 9eb55e282b..3fa1d9596b 100755 --- a/tests/PHPUnit/System/RowEvolutionTest.php +++ b/tests/PHPUnit/System/RowEvolutionTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesManyVisitsOverSeveralDaysWithSearchEngineReferrers; /** * Tests the method API.getRowEvolution diff --git a/tests/PHPUnit/System/SiteSearchTest.php b/tests/PHPUnit/System/SiteSearchTest.php index bb5b5c3bb0..4d6867ed53 100755 --- a/tests/PHPUnit/System/SiteSearchTest.php +++ b/tests/PHPUnit/System/SiteSearchTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\ThreeSitesWithManyVisitsWithSiteSearch; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\ThreeSitesWithManyVisitsWithSiteSearch; /** * Testing the various use cases w/ internal Site Search tracking diff --git a/tests/PHPUnit/System/TimezonesTest.php b/tests/PHPUnit/System/TimezonesTest.php index d9b11c9ae2..a071ded41b 100644 --- a/tests/PHPUnit/System/TimezonesTest.php +++ b/tests/PHPUnit/System/TimezonesTest.php @@ -8,8 +8,8 @@ namespace Piwik\Tests\System; use Piwik\Date; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\VisitsInDifferentTimezones; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\VisitsInDifferentTimezones; /** * Test reports using visits for a site with a non-UTC timezone. diff --git a/tests/PHPUnit/System/TrackCustomVariablesAndCampaignsForceUsingVisitIdNotHeuristicsTest.php b/tests/PHPUnit/System/TrackCustomVariablesAndCampaignsForceUsingVisitIdNotHeuristicsTest.php index efb4cf4554..30b205d9eb 100755 --- a/tests/PHPUnit/System/TrackCustomVariablesAndCampaignsForceUsingVisitIdNotHeuristicsTest.php +++ b/tests/PHPUnit/System/TrackCustomVariablesAndCampaignsForceUsingVisitIdNotHeuristicsTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\SomeVisitsCustomVariablesCampaignsNotHeuristics; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\SomeVisitsCustomVariablesCampaignsNotHeuristics; /** * Test tracker & API when forcing the use of visit ID instead of heuristics. Also diff --git a/tests/PHPUnit/System/TrackGoalsAllowMultipleConversionsPerVisitTest.php b/tests/PHPUnit/System/TrackGoalsAllowMultipleConversionsPerVisitTest.php index af2469670b..151db2bfa2 100755 --- a/tests/PHPUnit/System/TrackGoalsAllowMultipleConversionsPerVisitTest.php +++ b/tests/PHPUnit/System/TrackGoalsAllowMultipleConversionsPerVisitTest.php @@ -8,8 +8,8 @@ namespace Piwik\Tests\System; use Piwik\Plugins\Goals\API; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\SomeVisitsAllConversions; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\SomeVisitsAllConversions; /** * Tests API methods with goals that do and don't allow multiple diff --git a/tests/PHPUnit/System/TrackerWindowLookBackTest.php b/tests/PHPUnit/System/TrackerWindowLookBackTest.php index 433e6baf43..7e84f1c30a 100644 --- a/tests/PHPUnit/System/TrackerWindowLookBackTest.php +++ b/tests/PHPUnit/System/TrackerWindowLookBackTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\VisitsOverSeveralDays; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\VisitsOverSeveralDays; /** * Testing that, when using window_look_back_for_visitor with a high value, diff --git a/tests/PHPUnit/System/TransitionsTest.php b/tests/PHPUnit/System/TransitionsTest.php index e3ca1c4863..d3c456f478 100644 --- a/tests/PHPUnit/System/TransitionsTest.php +++ b/tests/PHPUnit/System/TransitionsTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\SomeVisitsManyPageviewsWithTransitions; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\SomeVisitsManyPageviewsWithTransitions; /** * Tests the transitions plugin. diff --git a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysArchivingDisabledTest.php b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysArchivingDisabledTest.php index 3eb2d2456c..4797cf15fe 100755 --- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysArchivingDisabledTest.php +++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysArchivingDisabledTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesTwoVisitorsDifferentDays; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesTwoVisitorsDifferentDays; /** * Tests IndexedBySite optimizations when archiving is disabled. diff --git a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php index 243e9761c5..c65ca94c7d 100755 --- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php +++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysConversionsTest.php @@ -8,10 +8,10 @@ namespace Piwik\Tests\System; use Piwik\Plugins\Goals\Archiver; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesTwoVisitorsDifferentDays; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesTwoVisitorsDifferentDays; -require_once 'Goals/Goals.php'; +require_once PIWIK_INCLUDE_PATH . '/plugins/Goals/Goals.php'; /** * Same as TwoVisitors_twoWebsites_differentDays but with goals that convert diff --git a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php index 668924b4d8..cbde5332e8 100755 --- a/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php +++ b/tests/PHPUnit/System/TwoVisitorsTwoWebsitesDifferentDaysTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesTwoVisitorsDifferentDays; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesTwoVisitorsDifferentDays; /** * tests Tracker several websites, different days. diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentContainsTest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentContainsTest.php index a8bbdcc092..1fc3f60e6d 100755 --- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentContainsTest.php +++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentContainsTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; /** * Tests use of custom variable segments. diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchALLNoGoalDataTest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchALLNoGoalDataTest.php index 1a16bc627f..f273d84fa7 100755 --- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchALLNoGoalDataTest.php +++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchALLNoGoalDataTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; /** * @group Plugins diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php index 27fdbd8167..42eba9b348 100755 --- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php +++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchNONETest.php @@ -8,9 +8,9 @@ namespace Piwik\Tests\System; use Piwik\Plugins\API\API; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; -use Piwik\Tests\Fixture; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\Fixture; /** * testing a segment containing all supported fields diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php index 5f1db60602..7a2e98a320 100755 --- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php +++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesSegmentMatchVisitorTypeTest.php @@ -9,8 +9,8 @@ namespace Piwik\Tests\System; use Piwik\Common; use Piwik\Db; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; /** * Tests use of custom variable segments. diff --git a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesTest.php b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesTest.php index a7b65b18fb..77b7f97caf 100755 --- a/tests/PHPUnit/System/TwoVisitsWithCustomVariablesTest.php +++ b/tests/PHPUnit/System/TwoVisitsWithCustomVariablesTest.php @@ -7,8 +7,8 @@ */ namespace Piwik\Tests\System; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoVisitsWithCustomVariables; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoVisitsWithCustomVariables; /** * Tests w/ two visits & custom variables. diff --git a/tests/PHPUnit/System/UrlNormalizationTest.php b/tests/PHPUnit/System/UrlNormalizationTest.php index 07011200ee..f8b3a71ce3 100644 --- a/tests/PHPUnit/System/UrlNormalizationTest.php +++ b/tests/PHPUnit/System/UrlNormalizationTest.php @@ -10,8 +10,8 @@ namespace Piwik\Tests\System; use Piwik\Common; use Piwik\Db; use Piwik\Tracker\Action; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\OneVisitWithAbnormalPageviewUrls; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\OneVisitWithAbnormalPageviewUrls; /** * Tests the URL normalization. diff --git a/tests/PHPUnit/System/UserIdAndVisitorIdTest.php b/tests/PHPUnit/System/UserIdAndVisitorIdTest.php index ca5b2475a9..64979af52c 100644 --- a/tests/PHPUnit/System/UserIdAndVisitorIdTest.php +++ b/tests/PHPUnit/System/UserIdAndVisitorIdTest.php @@ -8,8 +8,8 @@ namespace Piwik\Tests\System; use Piwik\API\Proxy; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\FewVisitsWithSetVisitorId; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\FewVisitsWithSetVisitorId; /** * This test tests that when using &cid=, the visitor ID is enforced diff --git a/tests/PHPUnit/System/VisitsInPastInvalidateOldReportsTest.php b/tests/PHPUnit/System/VisitsInPastInvalidateOldReportsTest.php index 35f9b8ab57..bb609d6bee 100644 --- a/tests/PHPUnit/System/VisitsInPastInvalidateOldReportsTest.php +++ b/tests/PHPUnit/System/VisitsInPastInvalidateOldReportsTest.php @@ -8,8 +8,8 @@ namespace Piwik\Tests\System; use Piwik\API\Request; -use Piwik\Tests\SystemTestCase; -use Piwik\Tests\Fixtures\TwoSitesVisitsInPast; +use Piwik\Tests\Impl\SystemTestCase; +use Piwik\Tests\Impl\Fixtures\TwoSitesVisitsInPast; use Exception; /** diff --git a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php index 6bbcc64110..2516dca051 100644 --- a/tests/PHPUnit/Unit/DeprecatedMethodsTest.php +++ b/tests/PHPUnit/Unit/DeprecatedMethodsTest.php @@ -30,6 +30,12 @@ class DeprecatedMethodsTest extends PHPUnit_Framework_TestCase $validTill = '2014-10-20'; $this->assertDeprecatedMethodIsRemoved('\Piwik\SettingsPiwik', 'rewriteTmpPathWithHostname', $validTill); + $validTill = '2014-12-06'; + $this->assertDeprecatedClassIsRemoved('\IntegrationTestCase', $validTill); + $this->assertDeprecatedClassIsRemoved('\DatabaseTestCase', $validTill); + $this->assertDeprecatedClassIsRemoved('\Piwik\Tests\Fixture', $validTill); + $this->assertDeprecatedClassIsRemoved('\Piwik\Tests\OverrideLogin', $validTill); + $this->assertDeprecatedMethodIsRemovedInPiwik3('\Piwik\Menu\MenuAbstract', 'add'); } @@ -52,6 +58,25 @@ class DeprecatedMethodsTest extends PHPUnit_Framework_TestCase $this->assertFalse($methodExists, $errorMessage); } + + private function assertDeprecatedClassIsRemoved($className, $removalDate) + { + $now = \Piwik\Date::now(); + $removalDate = \Piwik\Date::factory($removalDate); + + $classExists = class_exists($className); + + if (!$now->isLater($removalDate)) { + + $errorMessage = $className . 'should still exists until ' . $removalDate . ' although it is deprecated.'; + $this->assertTrue($classExists, $errorMessage); + return; + } + + $errorMessage = $className . ' should be removed as the method is deprecated but it is not.'; + $this->assertFalse($classExists, $errorMessage); + } + private function assertDeprecatedMethodIsRemovedInPiwik3($className, $method) { $version = \Piwik\Version::VERSION; diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index ac81f691c8..8335346c6b 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -34,8 +34,11 @@ require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php') require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php'; require_once PIWIK_INCLUDE_PATH . '/core/FrontController.php'; +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Impl/Fixture.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixture.php'; -require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/SystemTestCase.php'; +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Impl/SystemTestCase.php'; +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Impl/IntegrationTestCase.php'; +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/DatabaseTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/ConsoleCommandTestCase.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php'; @@ -81,7 +84,7 @@ Try again. -> If you still get this message, you can work around it by specifying Host + Request_Uri at the top of this file tests/PHPUnit/bootstrap.php. <-"; exit(1); } - $baseUrl = \Piwik\Tests\Fixture::getRootUrl(); + $baseUrl = \Piwik\Tests\Impl\Fixture::getRootUrl(); \Piwik\SettingsPiwik::checkPiwikServerWorking($baseUrl, $acceptInvalidSSLCertificates = true); } diff --git a/tests/README.md b/tests/README.md index bce6f554ea..2cc2c3180c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -82,6 +82,32 @@ To execute the tests: 5. Write more tests :) See ["Writing Unit tests with PHPUnit"](http://www.phpunit.de/manual/current/en/writing-tests-for-phpunit.html) +## How to differentiate between unit, integration or system tests? +This can be sometimes hard to decide and often leads to discussions. We consider a test as a unit test when +it tests only a single method or class. Sometimes two or three classes can still be considered as a Unit for instance if + you have to pass a dummy class or something similar but it should actually only test one class or method. + If it has a dependency to the filesystem, web, config, database or to other plugins it is not a unit test but an + integration test. If the test is slow it is most likely not a unit test but an integration test as well. + "Slow" is of course very objective and also depends on the server but if your test does not have any dependencies +your test will be really fast. + +It is an integration test if you have a dependency to a loaded plugin, to the filesystem, web, config, database or something +similar. It is an integration test if you test multiple classes in one test. + +It is a system test if you - for instance - make a call to your Piwik via HTTP and the whole system is being tested. + +### Why do we split tests in unit, integration, system and ui folders? +Because they fail for different reasons and the duration of the test execution is different. This allows us to execute +all unit tests and get a result very quick. Unit tests should not fail on different systems and just run everywhere for + example no matter whether you are using NFS or not. Once the unit tests are green one would usually execute all integration + tests to see whether the next stage works. They take a bit longer as they have depenencies to the database and filesystem. + The system and ui tests take the most time to run as they always run through the whole code. + +Another advantage of running the tests separately is that we are getting a more accurate code coverage. For instance when +running the unit tests we will get the true code coverage as they always only test one class or method. Integration tests +usually run through a lot of code but often actually only one method is supposed to be tested. Although many methods are +not tested they would be still marked as tested when running integration tests. + ## System Tests System tests files are in `tests/PHPUnit/System/*Test.php` |