diff options
author | diosmosis <benaka@piwik.pro> | 2015-10-17 05:27:19 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-10-27 07:46:53 +0300 |
commit | 9d19c3807d02957023549f9e4584d2c37c8deebb (patch) | |
tree | 3ae6cf8907e0663cf09c3b43333d4d385608b51d | |
parent | a37c5c114405a1a795e68ef1e84e03a46f0f50cd (diff) |
Allow extra environments to be specified through testing environment variables, add a new one for UI tests call ui-test.php, use to remove port from localhost in UI tests, and fix a bug in ContainerFactory (config/config.php should be applied after environment files).
-rw-r--r-- | config/environment/ui-test.php | 14 | ||||
-rw-r--r-- | core/Container/ContainerFactory.php | 12 | ||||
-rw-r--r-- | plugins/TestRunner/Commands/TestsSetupFixture.php | 3 | ||||
-rw-r--r-- | tests/PHPUnit/Framework/Fixture.php | 2 | ||||
-rw-r--r-- | tests/PHPUnit/Framework/TestingEnvironmentManipulator.php | 7 | ||||
-rw-r--r-- | tests/UI/specs/EmptySite_spec.js | 9 | ||||
-rw-r--r-- | tests/UI/specs/Installation_spec.js | 9 | ||||
-rw-r--r-- | tests/UI/specs/UIIntegration_spec.js | 8 |
8 files changed, 31 insertions, 33 deletions
diff --git a/config/environment/ui-test.php b/config/environment/ui-test.php new file mode 100644 index 0000000000..738d1556db --- /dev/null +++ b/config/environment/ui-test.php @@ -0,0 +1,14 @@ +<?php + +return array( + + 'observers.global' => array( + + array('Request.dispatch.end', function (&$result) { + // remove the port from URLs if any so UI tests won't fail if the port isn't 80 + $result = preg_replace('/localhost:[0-9]+/', 'localhost', $result); + }), + + ), + +); diff --git a/core/Container/ContainerFactory.php b/core/Container/ContainerFactory.php index 75735036aa..9c5eed1276 100644 --- a/core/Container/ContainerFactory.php +++ b/core/Container/ContainerFactory.php @@ -79,12 +79,7 @@ class ContainerFactory // Development config if ($this->isDevelopmentModeEnabled()) { - $builder->addDefinitions(PIWIK_USER_PATH . '/config/environment/dev.php'); - } - - // User config - if (file_exists(PIWIK_USER_PATH . '/config/config.php')) { - $builder->addDefinitions(PIWIK_USER_PATH . '/config/config.php'); + $this->addEnvironmentConfig($builder, 'dev'); } // Environment config @@ -92,6 +87,11 @@ class ContainerFactory $this->addEnvironmentConfig($builder, $environment); } + // User config + if (file_exists(PIWIK_USER_PATH . '/config/config.php')) { + $builder->addDefinitions(PIWIK_USER_PATH . '/config/config.php'); + } + if (!empty($this->definitions)) { foreach ($this->definitions as $definitionArray) { $builder->addDefinitions($definitionArray); diff --git a/plugins/TestRunner/Commands/TestsSetupFixture.php b/plugins/TestRunner/Commands/TestsSetupFixture.php index 81dc619367..baea8f70ff 100644 --- a/plugins/TestRunner/Commands/TestsSetupFixture.php +++ b/plugins/TestRunner/Commands/TestsSetupFixture.php @@ -212,6 +212,7 @@ class TestsSetupFixture extends ConsoleCommand throw new \Exception("Cannot find fixture class '$fixtureClass'."); } + /** @var Fixture $fixture */ $fixture = new $fixtureClass(); $fixture->printToScreen = true; @@ -233,6 +234,8 @@ class TestsSetupFixture extends ConsoleCommand $fixture->extraPluginsToLoad = explode(',', $extraPluginsToLoad); } + $fixture->extraDiEnvironments = array('ui-test'); + return $fixture; } diff --git a/tests/PHPUnit/Framework/Fixture.php b/tests/PHPUnit/Framework/Fixture.php index f0a2f1978f..04c52371da 100644 --- a/tests/PHPUnit/Framework/Fixture.php +++ b/tests/PHPUnit/Framework/Fixture.php @@ -107,6 +107,7 @@ class Fixture extends \PHPUnit_Framework_Assert public $testCaseClass = false; public $extraPluginsToLoad = array(); + public $extraDiEnvironments = array(); public $testEnvironment = null; @@ -201,6 +202,7 @@ class Fixture extends \PHPUnit_Framework_Assert $testEnv->testCaseClass = $this->testCaseClass; $testEnv->fixtureClass = get_class($this); $testEnv->dbName = $this->dbName; + $testEnv->extraDiEnvironments = $this->extraDiEnvironments; foreach ($this->extraTestEnvVars as $name => $value) { $testEnv->$name = $value; diff --git a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php index 78369abfd9..df6a011af5 100644 --- a/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php +++ b/tests/PHPUnit/Framework/TestingEnvironmentManipulator.php @@ -190,7 +190,12 @@ class TestingEnvironmentManipulator implements EnvironmentManipulator public function getExtraEnvironments() { - return array('test'); + $result = array('test'); + + $extraEnvironments = $this->vars->extraDiEnvironments ?: array(); + $result = array_merge($result, $extraEnvironments); + + return $result; } private function getPluginsToLoadDuringTest() diff --git a/tests/UI/specs/EmptySite_spec.js b/tests/UI/specs/EmptySite_spec.js index 4613c7d604..31b8524d6f 100644 --- a/tests/UI/specs/EmptySite_spec.js +++ b/tests/UI/specs/EmptySite_spec.js @@ -17,15 +17,6 @@ describe("EmptySite", function () { expect.screenshot('emptySiteDashboard').to.be.captureSelector('.page', function (page) { page.load(urlToTest); - - // remove the port from URLs if any so UI tests won't fail if the port isn't 80 - // TODO: code redundancy w/ UIIntegrationTest. can be fixed w/ new UI test DI environment type. - page.evaluate(function () { - $('pre').each(function () { - var html = $(this).html().replace(/localhost\:[0-9]+/g, 'localhost'); - $(this).html(html); - }); - }); }, done); }); }); diff --git a/tests/UI/specs/Installation_spec.js b/tests/UI/specs/Installation_spec.js index 6119036238..6830091da6 100644 --- a/tests/UI/specs/Installation_spec.js +++ b/tests/UI/specs/Installation_spec.js @@ -121,15 +121,6 @@ describe("Installation", function () { }); page.click('.btn'); page.wait(3000); - - // remove the port from URLs if any so UI tests won't fail if the port isn't 80 - // TODO: code redundancy w/ UIIntegrationTest. can be fixed w/ new UI test DI environment type. - page.evaluate(function () { - $('pre').each(function () { - var html = $(this).html().replace(/localhost\:[0-9]+/g, 'localhost'); - $(this).html(html); - }); - }); }, done); }); diff --git a/tests/UI/specs/UIIntegration_spec.js b/tests/UI/specs/UIIntegration_spec.js index 0331bc514a..bc6d71dbad 100644 --- a/tests/UI/specs/UIIntegration_spec.js +++ b/tests/UI/specs/UIIntegration_spec.js @@ -436,14 +436,6 @@ describe("UIIntegrationTest", function () { // TODO: Rename to Piwik? it('should load the Manage > Tracking Code admin page correctly', function (done) { expect.screenshot('admin_manage_tracking_code').to.be.captureSelector('.pageWrap', function (page) { page.load("?" + generalParams + "&module=CoreAdminHome&action=trackingCodeGenerator"); - - // remove the port from URLs if any so UI tests won't fail if the port isn't 80 - page.evaluate(function () { - $('textarea').each(function () { - var val = $(this).val().replace(/localhost\:[0-9]+/g, 'localhost'); - $(this).val(val); - }); - }); }, done); }); |