Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhang <peter@innocraft.com>2021-12-08 02:28:29 +0300
committerGitHub <noreply@github.com>2021-12-08 02:28:29 +0300
commit2da215c65d77fb273c7899fd23e65c67bc50c4f8 (patch)
treebea956ea33765459a7a610744953879a5c5a784e /tests/PHPUnit
parent4f5cda954a6b64677f9b48223a91e0ec8785e055 (diff)
add disable archiving segment for plugins (#18279)
* add disable archiving segment for plugins add disable archiving segment for plugins * Update Rules.php add isset check * Update global.ini.php update disable_archiving_segment_for_plugins to right place * update tests update tests * Update global.ini.php update wording * update wording and test update wording and test * update tests update tests * Update UIIntegrationTest_admin_diagnostics_configfile.png update config * Update global.ini.php update wording * Update UIIntegrationTest_admin_diagnostics_configfile.png update screen shot * move general config to a file move general config to a file * update screenshot update screenshot * Update Rules.php update rule * Update global.ini.php update global * Update config/global.ini.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * Update core/ArchiveProcessor/Rules.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * update tests and case and special-characters update tests and case and special-characters * update tests update tests * Update UIIntegrationTest_admin_diagnostics_configfile.png update config screenshot * Update core/ArchiveProcessor/Rules.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * Update tests/PHPUnit/System/ArchiveInvalidationTest.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * add footer message for disable plugin add footer message for disable plugin * Update core/Plugin/Visualization.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * core/Plugin/Visualization.php update en and check unsegmented reports * Update en.json update lang * Update core/Config/GeneralConfig.php Co-authored-by: Stefan Giehl <stefan@matomo.org> * Update plugins/CoreHome/lang/en.json Co-authored-by: Stefan Giehl <stefan@matomo.org> * add screenshot tests add screenshot tests * Update DisablePluginArchive.php set up site * Update DisablePluginArchive.php update config * Update DisablePluginArchive.php update to overwrite * Create DisablePluginArchive_DisablePluginArchive.png update screen shot * update config update config * update screen update screen * update screenshots update screenshots * update unrelated screenshots and update tests update unrelated screenshots and update tests Co-authored-by: Stefan Giehl <stefan@matomo.org>
Diffstat (limited to 'tests/PHPUnit')
-rw-r--r--tests/PHPUnit/Fixtures/DisablePluginArchive.php186
-rw-r--r--tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php50
-rw-r--r--tests/PHPUnit/System/ArchiveInvalidationTest.php126
-rw-r--r--tests/PHPUnit/Unit/ConfigTest.php310
4 files changed, 550 insertions, 122 deletions
diff --git a/tests/PHPUnit/Fixtures/DisablePluginArchive.php b/tests/PHPUnit/Fixtures/DisablePluginArchive.php
new file mode 100644
index 0000000000..ff7e720ca6
--- /dev/null
+++ b/tests/PHPUnit/Fixtures/DisablePluginArchive.php
@@ -0,0 +1,186 @@
+<?php
+/**
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+namespace Piwik\Tests\Fixtures;
+
+use MatomoTracker;
+use Piwik\Date;
+use Piwik\Plugins\Goals\API as APIGoals;
+use Piwik\Plugins\SitesManager\API as APISitesManager;
+use Piwik\Tests\Framework\Fixture;
+use Exception;
+use Piwik\Tracker\Cache;
+
+/**
+ * Add config disable archiving
+ */
+class DisablePluginArchive extends Fixture
+{
+ public $idSite = 1;
+ public $dateTime = '2009-01-04 00:11:42';
+
+ public $trackInvalidRequests = true;
+
+ public function setUp(): void
+ {
+ $this->setUpWebsitesAndGoals();
+ $this->setUpConfig();
+ $this->trackVisits();
+ }
+
+ public function tearDown(): void
+ {
+ $this->removeConfig();
+ }
+
+
+ private function setUpWebsitesAndGoals()
+ {
+ if (!self::siteCreated($idSite = 1)) {
+ self::createWebsite($this->dateTime);
+ }
+ }
+
+ private function trackVisits()
+ {
+ $dateTime = $this->dateTime;
+ $idSite = $this->idSite;
+
+ self::createSuperUser();
+ $t = self::getTracker($idSite, $dateTime, $defaultInit = true);
+
+ Cache::clearCacheGeneral();
+ Cache::regenerateCacheWebsiteAttributes(array($idSite));
+
+ if ($this->useThirdPartyCookies) {
+ $t->DEBUG_APPEND_URL = '&forceUseThirdPartyCookie=1';
+ }
+
+ $t->disableCookieSupport();
+
+ $t->setUrlReferrer('http://referrer.com/page.htm?param=valuewith some spaces');
+
+ // testing URL excluded parameters
+ $parameterToExclude = 'excluded_parameter';
+ APISitesManager::getInstance()->updateSite(
+ $idSite,
+ 'new name',
+ $url = array('http://site.com'),
+ $ecommerce = 0,
+ $siteSearch = $this->useSiteSearch ? 1 : 0,
+ $searchKeywordParameters = $this->useSiteSearch ? '' : null,
+ $searchCategoryParameters = $this->useSiteSearch ? 'notparam' : null,
+ $excludedIps = null,
+ $parameterToExclude . ',anotherParameter',
+ $timezone = null,
+ $currency = null,
+ $group = null,
+ $startDate = null
+ );
+
+ // Record 1st page view
+ $urlPage1 = 'http://example.org/index.htm?excluded_Parameter=SHOULD_NOT_DISPLAY&parameter=Should display';
+ $t->setUrl($urlPage1);
+ $t->setPerformanceTimings(33, 105, 205, 1325, 390, 222);
+ self::checkResponse($t->doTrackPageView('incredible title!'));
+
+ // testing that / and index.htm above record with different URLs
+ // Recording the 2nd page after 3 minutes
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.05)->getDatetime());
+ $t->setUrl('http://example.org/');
+ $t->setPerformanceTimings(62, 198, 253, 1559, 222, 152);
+ self::checkResponse($t->doTrackPageView('Second page view - should be registered as URL /'));
+
+ // Click on external link after 6 minutes (3rd action)
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.1)->getDatetime());
+
+ // Testing Outlink that contains a URL Fragment
+ self::checkResponse($t->doTrackAction('https://outlinks.org/#!outlink-with-fragment-<script>', 'link'));
+
+ // Click on file download after 12 minutes (4th action)
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.2)->getDatetime());
+ self::checkResponse($t->doTrackAction('http://piwik.org/path/again/latest.zip', 'download'));
+
+ // Click on two more external links, one the same as before (5th & 6th actions)
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.22)->getDateTime());
+ self::checkResponse($t->doTrackAction('http://outlinks.org/other_outlink#fragment&pk_campaign=Open%20partnership', 'link'));
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.25)->getDateTime());
+ self::checkResponse($t->doTrackAction('http://dev.piwik.org/svn', 'link'));
+
+ // Create Goal 1: Triggered by JS, after 18 minutes
+ $idGoal = 1;
+ if (!self::goalExists($idSite, $idGoal)) {
+ $idGoal = APIGoals::getInstance()->addGoal($idSite, 'triggered js', 'manually', '', '');
+ }
+
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.3)->getDatetime());
+
+ // Change to Thai browser to ensure the conversion is credited to FR instead (the visitor initial country)
+ $t->setBrowserLanguage('th');
+ self::checkResponse($t->doTrackGoal($idGoal, $revenue = 42));
+
+ // Track same Goal twice (after 24 minutes), should only be tracked once
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.4)->getDatetime());
+ self::checkResponse($t->doTrackGoal($idGoal, $revenue = 42));
+
+ $t->setBrowserLanguage('fr');
+
+ if ($this->useSiteSearch) {
+ // Site Search request
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.42)->getDatetime());
+ $t->setUrl('http://example.org/index.htm?q=Banks Own The World');
+ $t->setPerformanceTimings(17, 236, 385, 1025, 199, 266);
+ self::checkResponse($t->doTrackPageView('Site Search request'));
+
+ // Final page view (after 27 min)
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.45)->getDatetime());
+ $t->setUrl('http://example.org/index.htm');
+ $t->setPerformanceTimings(42, 96, 200, 955, 566, 200);
+ self::checkResponse($t->doTrackPageView('Looking at homepage after site search...'));
+ } else {
+ // Final page view (after 27 min)
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(0.45)->getDatetime());
+ $t->setUrl('http://example.org/index.htm#ignoredFragment#');
+ $t->setPerformanceTimings(0, 222, 333, 1111, 666, 333);
+ self::checkResponse($t->doTrackPageView('Looking at homepage (again)...'));
+ }
+
+ // -
+ // End of first visit: 24min
+
+ // Create Goal 2: Matching on URL
+ if (!self::goalExists($idSite, $idGoal = 2)) {
+ APIGoals::getInstance()->addGoal($idSite, 'matching purchase.htm', 'url', '(.*)store\/purchase\.(.*)', 'regex', false, $revenue = 1);
+ }
+
+ // -
+ // Start of returning visit, 1 hour after first page view
+ $t->setForceVisitDateTime(Date::factory($dateTime)->addHour(1)->getDatetime());
+ $t->setUrl('http://example.org/store/purchase.htm');
+ $t->setUrlReferrer('http://search.yahoo.com/search?p=purchase');
+
+ // Goal Tracking URL matching, testing custom referrer including keyword
+ $t->setPerformanceTimings(22, 157, 266, 2000, 1002, 666);
+ self::checkResponse($t->doTrackPageView('Checkout/Purchasing...'));
+ // -
+ // End of second visit
+ }
+
+ private function setUpConfig()
+ {
+ $testEnvironment = $this->getTestEnvironment();
+ $testEnvironment->overrideConfig('General','disable_archiving_segment_for_plugins','Referrers');
+ $testEnvironment->save();
+ }
+
+ private function removeConfig()
+ {
+ $testEnvironment = $this->getTestEnvironment();
+ $testEnvironment->overrideConfig('General','disable_archiving_segment_for_plugins','');
+ $testEnvironment->save();
+ }
+} \ No newline at end of file
diff --git a/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php b/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
index 7465261d28..95ea94833e 100644
--- a/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
+++ b/tests/PHPUnit/Integration/ArchiveProcessor/LoaderTest.php
@@ -1463,6 +1463,56 @@ class LoaderTest extends IntegrationTestCase
$this->assertTrue($loader->canSkipArchiveForSegment());
}
+ public function test_canSkipArchiveForSegment_returnTrueIfPluginIsDisabled()
+ {
+ Rules::setBrowserTriggerArchiving(false);
+ $config = Config::getInstance();
+ $config->General['disable_archiving_segment_for_plugins'] = 'testPlugin';
+ $date = '2010-04-23';
+ $definition = 'browserCode==ch';
+ $segment = new Segment($definition, [1]);
+ $doneFlag = Rules::getDoneStringFlagFor([1], $segment, 'day', null);
+
+ $this->insertInvalidations([
+ ['date1' => $date, 'date2' => $date, 'period' => 1, 'name' => $doneFlag, 'report' => 'myReport'],
+ ]);
+
+ SegmentApi::getInstance()->add('segment', $definition, 1, true, true);
+ $params = new Parameters(new Site(1), Factory::build('day', $date), $segment);
+ $params->setRequestedPlugin('testPlugin');
+ $params->setArchiveOnlyReport('myReport');
+ $loader = new Loader($params);
+ $this->assertTrue($loader->canSkipArchiveForSegment());
+ }
+
+ public function test_canSkipArchiveForSegment_returnTrueIfPluginIsDisabledBySiteId()
+ {
+ Rules::setBrowserTriggerArchiving(false);
+ Config::setSetting('General_1','disable_archiving_segment_for_plugins','testPlugin');
+ $date = '2010-04-23';
+ $definition = 'browserCode==ch';
+ $segment = new Segment($definition, [1]);
+ $doneFlag = Rules::getDoneStringFlagFor([1], $segment, 'day', null);
+
+ $this->insertInvalidations([
+ ['date1' => $date, 'date2' => $date, 'period' => 1, 'name' => $doneFlag, 'report' => 'myReport'],
+ ]);
+
+ SegmentApi::getInstance()->add('segment', $definition, 1, true, true);
+ $params = new Parameters(new Site(1), Factory::build('day', $date), $segment);
+ $params->setRequestedPlugin('testPlugin');
+ $params->setArchiveOnlyReport('myReport');
+ $loader = new Loader($params);
+ $this->assertTrue($loader->canSkipArchiveForSegment());
+
+ $params = new Parameters(new Site(2), Factory::build('day', $date), $segment);
+ $params->setRequestedPlugin('testPlugin');
+ $params->setArchiveOnlyReport('myReport');
+ $loader = new Loader($params);
+ $this->assertFalse($loader->canSkipArchiveForSegment());
+ }
+
+
public function test_forcePluginArchiving_createsPluginSpecificArchive()
{
$_GET['trigger'] = 'archivephp';
diff --git a/tests/PHPUnit/System/ArchiveInvalidationTest.php b/tests/PHPUnit/System/ArchiveInvalidationTest.php
index 4e537f9562..63c23b47a5 100644
--- a/tests/PHPUnit/System/ArchiveInvalidationTest.php
+++ b/tests/PHPUnit/System/ArchiveInvalidationTest.php
@@ -71,30 +71,42 @@ class ArchiveInvalidationTest extends SystemTestCase
// Build tests for the 2 websites
return array(
- array($apiToCall, array('idSite' => self::$fixture->idSite2,
- 'testSuffix' => 'Website' . self::$fixture->idSite2 . $this->suffix,
- 'date' => self::$fixture->dateTimeFirstDateWebsite2,
- 'periods' => 'day',
- 'segment' => self::TEST_SEGMENT,
- 'setDateLastN' => 4, // 4months ahead
- 'otherRequestParameters' => array('expanded' => 1))
- ),
- array($apiToCall, array('idSite' => self::$fixture->idSite1,
- 'testSuffix' => 'Website' . self::$fixture->idSite1 . $this->suffix,
- 'date' => self::$fixture->dateTimeFirstDateWebsite1,
- 'periods' => 'month',
- 'setDateLastN' => 4, // 4months ahead
- 'otherRequestParameters' => array('expanded' => 1))
- ),
-
- array($apiToCall, array('idSite' => self::$fixture->idSite2,
- 'testSuffix' => 'Website' . self::$fixture->idSite2 . $this->suffix,
- 'date' => self::$fixture->dateTimeFirstDateWebsite2,
- 'periods' => 'month',
- 'segment' => self::TEST_SEGMENT,
- 'setDateLastN' => 4, // 4months ahead
- 'otherRequestParameters' => array('expanded' => 1))
+ array(
+ $apiToCall,
+ array(
+ 'idSite' => self::$fixture->idSite2,
+ 'testSuffix' => 'Website' . self::$fixture->idSite2 . $this->suffix,
+ 'date' => self::$fixture->dateTimeFirstDateWebsite2,
+ 'periods' => 'day',
+ 'segment' => self::TEST_SEGMENT,
+ 'setDateLastN' => 4, // 4months ahead
+ 'otherRequestParameters' => array('expanded' => 1)
)
+ ),
+ array(
+ $apiToCall,
+ array(
+ 'idSite' => self::$fixture->idSite1,
+ 'testSuffix' => 'Website' . self::$fixture->idSite1 . $this->suffix,
+ 'date' => self::$fixture->dateTimeFirstDateWebsite1,
+ 'periods' => 'month',
+ 'setDateLastN' => 4, // 4months ahead
+ 'otherRequestParameters' => array('expanded' => 1)
+ )
+ ),
+
+ array(
+ $apiToCall,
+ array(
+ 'idSite' => self::$fixture->idSite2,
+ 'testSuffix' => 'Website' . self::$fixture->idSite2 . $this->suffix,
+ 'date' => self::$fixture->dateTimeFirstDateWebsite2,
+ 'periods' => 'month',
+ 'segment' => self::TEST_SEGMENT,
+ 'setDateLastN' => 4, // 4months ahead
+ 'otherRequestParameters' => array('expanded' => 1)
+ )
+ )
);
}
@@ -128,6 +140,72 @@ class ArchiveInvalidationTest extends SystemTestCase
}
}
+ public function testDisablePluginArchive()
+ {
+ $config = Config::getInstance();
+ $config->General['disable_archiving_segment_for_plugins'] = 'testPlugin';
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin'));
+
+ $config->General['disable_archiving_segment_for_plugins'] = ['testPlugin', 'testPlugin2'];
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin'));
+
+ $config->General['disable_archiving_segment_for_plugins'] = 'testPlugin,testPlugin2';
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin2'));
+
+ $config->General['disable_archiving_segment_for_plugins'] = '';
+ $this->assertFalse(Rules::isSegmentPluginArchivingDisabled('testPlugin'));
+
+ }
+
+ public function testDisablePluginArchiveCaseInsensitive()
+ {
+ $config = Config::getInstance();
+ $config->General['disable_archiving_segment_for_plugins'] = 'testplugin,testplugin2';
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin'));
+ }
+
+ public function testDisablePluginArchiveSpecialCharacters()
+ {
+ //special characters will not work
+ $config = Config::getInstance();
+ $config->General['disable_archiving_segment_for_plugins'] = '!@##$%^^&&**(()_+';
+ $this->assertFalse(Rules::isSegmentPluginArchivingDisabled('!@##$%^^&&**(()_+'));
+ }
+
+ public function testDisablePluginArchiveBySiteId()
+ {
+ //test siteId 1 by string
+ Config::setSetting('General_1', 'disable_archiving_segment_for_plugins', 'testPlugin');
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin',1));
+
+ //test siteId 1 by array
+ Config::setSetting('General_1', 'disable_archiving_segment_for_plugins',['testPlugin', 'testPlugin2'] );
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin',1));
+
+ //test siteId 1 by string with comma
+ Config::setSetting('General_1', 'disable_archiving_segment_for_plugins','testPlugin,testPlugin2' );
+ $this->assertTrue(Rules::isSegmentPluginArchivingDisabled('testPlugin',1));
+
+ //test empty
+ Config::setSetting('General_1', 'disable_archiving_segment_for_plugins','' );
+ $this->assertFalse(Rules::isSegmentPluginArchivingDisabled('testPlugin',1));
+
+ //test siteId 2 not affect siteId1
+ Config::setSetting('General_2', 'disable_archiving_segment_for_plugins','testPlugin' );
+ $this->assertFalse(Rules::isSegmentPluginArchivingDisabled('testPlugin',1));
+
+
+ //test general setting not affect siteId1
+ Config::setSetting('General', 'disable_archiving_segment_for_plugins','myPlugin' );
+ Config::setSetting('General_1', 'disable_archiving_segment_for_plugins','testPlugin' );
+ $this->assertFalse(Rules::isSegmentPluginArchivingDisabled('myPlugin',1));
+
+ Config::setSetting('General_1', 'disable_archiving_segment_for_plugins', 'testPlugin2');
+ $this->assertFalse(Rules::isSegmentPluginArchivingDisabled('testPlugin', 1));
+ }
+
+
+
/**
* This is called after getApiToTest()
* We invalidate old reports and check that data is now returned for old dates
@@ -164,4 +242,4 @@ class ArchiveInvalidationTest extends SystemTestCase
}
}
-ArchiveInvalidationTest::$fixture = new VisitsTwoWebsitesWithAdditionalVisits(); \ No newline at end of file
+ArchiveInvalidationTest::$fixture = new VisitsTwoWebsitesWithAdditionalVisits();
diff --git a/tests/PHPUnit/Unit/ConfigTest.php b/tests/PHPUnit/Unit/ConfigTest.php
index 9a4dac2ffe..1627fcc9df 100644
--- a/tests/PHPUnit/Unit/ConfigTest.php
+++ b/tests/PHPUnit/Unit/ConfigTest.php
@@ -30,12 +30,12 @@ class MockIniSettingsProvider extends GlobalSettingsProvider
parent::__construct();
$this->iniFileChain = new DumpConfigTestMockIniFileChain(
- array(
- $this->pathGlobal => $configGlobal,
- $this->pathCommon => $configCommon,
- $this->pathLocal => $configLocal,
- ),
- $configCache
+ array(
+ $this->pathGlobal => $configGlobal,
+ $this->pathCommon => $configCommon,
+ $this->pathLocal => $configLocal,
+ ),
+ $configCache
);
}
}
@@ -112,8 +112,8 @@ class ConfigTest extends TestCase
$this->assertEquals($stringWritten, $config->Category['test']);
$config->Category = array(
- 'test' => $config->Category['test'],
- 'test2' => $stringWritten,
+ 'test' => $config->Category['test'],
+ 'test2' => $stringWritten,
);
$this->assertEquals($stringWritten, $config->Category['test']);
$this->assertEquals($stringWritten, $config->Category['test2']);
@@ -147,7 +147,7 @@ class ConfigTest extends TestCase
public function getDumpConfigData()
{
$header = "; <?php exit; ?> DO NOT REMOVE THIS LINE\n" .
- "; file automatically generated or modified by Matomo; you can manually override the default values in global.ini.php by redefining them in this file.\n";
+ "; file automatically generated or modified by Matomo; you can manually override the default values in global.ini.php by redefining them in this file.\n";
return array(
// Test name, array(
@@ -156,194 +156,308 @@ class ConfigTest extends TestCase
// COMMON
// CACHE
// --> EXPECTED <--
- array('global only, not cached', array(
+ array(
+ 'global only, not cached',
+ array(
array(), // local
array('General' => array('debug' => 1)), // global
array(), // common
array(),
false,
- )),
+ )
+ ),
- array('global only, cached get', array(
+ array(
+ 'global only, cached get',
+ array(
array(), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 1)),
false,
- )),
+ )
+ ),
- array('global only, cached set', array(
+ array(
+ 'global only, cached set',
+ array(
array(), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 2)),
$header . "[General]\ndebug = 2\n\n",
- )),
+ )
+ ),
- array('local copy (same), not cached', array(
+ array(
+ 'local copy (same), not cached',
+ array(
array('General' => array('debug' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array(),
false,
- )),
+ )
+ ),
- array('local copy (same), cached get', array(
+ array(
+ 'local copy (same), cached get',
+ array(
array('General' => array('debug' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 1)),
false,
- )),
+ )
+ ),
- array('local copy (same), cached set', array(
+ array(
+ 'local copy (same), cached set',
+ array(
array('General' => array('debug' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 2)),
$header . "[General]\ndebug = 2\n\n",
- )),
+ )
+ ),
- array('local copy (different), not cached', array(
+ array(
+ 'local copy (different), not cached',
+ array(
array('General' => array('debug' => 2)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array(),
false,
- )),
+ )
+ ),
- array('local copy (different), cached get', array(
+ array(
+ 'local copy (different), cached get',
+ array(
array('General' => array('debug' => 2)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 2)),
false,
- )),
+ )
+ ),
- array('local copy (different), cached set', array(
+ array(
+ 'local copy (different), cached set',
+ array(
array('General' => array('debug' => 2)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 3)),
$header . "[General]\ndebug = 3\n\n",
- )),
+ )
+ ),
- array('local copy, not cached, new section', array(
+ array(
+ 'local copy, not cached, new section',
+ array(
array('Tracker' => array('anonymize' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array(),
false,
- )),
+ )
+ ),
- array('local copy, cached get, new section', array(
+ array(
+ 'local copy, cached get, new section',
+ array(
array('Tracker' => array('anonymize' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('Tracker' => array('anonymize' => 1)),
false,
- )),
+ )
+ ),
- array('local copy, cached set local, new section', array(
+ array(
+ 'local copy, cached set local, new section',
+ array(
array('Tracker' => array('anonymize' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('Tracker' => array('anonymize' => 2)),
$header . "[Tracker]\nanonymize = 2\n\n",
- )),
+ )
+ ),
- array('local copy, cached set global, new section', array(
+ array(
+ 'local copy, cached set global, new section',
+ array(
array('Tracker' => array('anonymize' => 1)), // local
array('General' => array('debug' => 1)), // global
array(), // common
array('General' => array('debug' => 2), 'Tracker' => array('anonymize' => 1)),
$header . "[General]\ndebug = 2\n\n[Tracker]\nanonymize = 1\n\n",
- )),
+ )
+ ),
- array('sort, common sections', array(
- array('Tracker' => array('anonymize' => 1), // local
- 'General' => array('debug' => 1)),
- array('General' => array('debug' => 0), // global
- 'Tracker' => array('anonymize' => 0)),
+ array(
+ 'sort, common sections',
+ array(
+ array(
+ 'Tracker' => array('anonymize' => 1), // local
+ 'General' => array('debug' => 1)
+ ),
+ array(
+ 'General' => array('debug' => 0), // global
+ 'Tracker' => array('anonymize' => 0)
+ ),
array(), // common
- array('Tracker' => array('anonymize' => 2),
- 'General' => array('debug' => 1)),
+ array(
+ 'Tracker' => array('anonymize' => 2),
+ 'General' => array('debug' => 1)
+ ),
$header . "[General]\ndebug = 1\n\n[Tracker]\nanonymize = 2\n\n",
- )),
+ )
+ ),
- array('sort, common sections before new section', array(
- array('Tracker' => array('anonymize' => 1), // local
- 'General' => array('debug' => 1)),
- array('General' => array('debug' => 0), // global
- 'Tracker' => array('anonymize' => 0)),
+ array(
+ 'sort, common sections before new section',
+ array(
+ array(
+ 'Tracker' => array('anonymize' => 1), // local
+ 'General' => array('debug' => 1)
+ ),
+ array(
+ 'General' => array('debug' => 0), // global
+ 'Tracker' => array('anonymize' => 0)
+ ),
array(), // common
- array('Segment' => array('dimension' => 'foo'),
- 'Tracker' => array('anonymize' => 1), // local
- 'General' => array('debug' => 1)),
+ array(
+ 'Segment' => array('dimension' => 'foo'),
+ 'Tracker' => array('anonymize' => 1), // local
+ 'General' => array('debug' => 1)
+ ),
$header . "[General]\ndebug = 1\n\n[Tracker]\nanonymize = 1\n\n[Segment]\ndimension = \"foo\"\n\n",
- )),
+ )
+ ),
- array('change back to default', array(
+ array(
+ 'change back to default',
+ array(
array('Tracker' => array('anonymize' => 1)), // local
- array('Tracker' => array('anonymize' => 0), // global
- 'General' => array('debug' => 1)),
+ array(
+ 'Tracker' => array('anonymize' => 0), // global
+ 'General' => array('debug' => 1)
+ ),
array(), // common
array('Tracker' => array('anonymize' => 0)),
$header
- )),
+ )
+ ),
- array('[General] trusted_hosts has been updated and only this one is written', array(
+ array(
+ '[General] trusted_hosts has been updated and only this one is written',
+ array(
array('General' => array('trusted_hosts' => 'someRandomHostToOverwrite')), // local
- array('General' => array('settingGlobal' => 'global', // global
- 'settingCommon' => 'global',
- 'trusted_hosts' => 'none')),
- array('General' => array('settingCommon' => 'common', // common
- 'settingCommon2' => 'common')),
+ array(
+ 'General' => array(
+ 'settingGlobal' => 'global', // global
+ 'settingCommon' => 'global',
+ 'trusted_hosts' => 'none'
+ )
+ ),
+ array(
+ 'General' => array(
+ 'settingCommon' => 'common', // common
+ 'settingCommon2' => 'common'
+ )
+ ),
array('General' => array('trusted_hosts' => 'works')),
$header . "[General]\ntrusted_hosts = \"works\"\n\n",
- )),
+ )
+ ),
// Same as above but without trusted_hosts default value in global.ini.php
// Also, settingCommon3 is the same in the local file as in common, so it is not written out
- array('trusted_hosts and settingCommon3 changed ', array(
+ array(
+ 'trusted_hosts and settingCommon3 changed ',
+ array(
array('General' => array('trusted_hosts' => 'someRandomHostToOverwrite')), // local
- array('General' => array('settingGlobal' => 'global', // global
- 'settingCommon' => 'global')),
- array('General' => array('settingCommon' => 'common', // common
- 'settingCommon2' => 'common',
- 'settingCommon3' => 'common3')),
- array('General' => array('trusted_hosts' => 'works', // common
- 'settingCommon2' => 'common', // will be cleared since it's same as in common
- 'settingCommon3' => 'commonOverridenByLocal')),
+ array(
+ 'General' => array(
+ 'settingGlobal' => 'global', // global
+ 'settingCommon' => 'global'
+ )
+ ),
+ array(
+ 'General' => array(
+ 'settingCommon' => 'common', // common
+ 'settingCommon2' => 'common',
+ 'settingCommon3' => 'common3'
+ )
+ ),
+ array(
+ 'General' => array(
+ 'trusted_hosts' => 'works', // common
+ 'settingCommon2' => 'common', // will be cleared since it's same as in common
+ 'settingCommon3' => 'commonOverridenByLocal'
+ )
+ ),
$header . "[General]\ntrusted_hosts = \"works\"\nsettingCommon3 = \"commonOverridenByLocal\"\n\n",
- )),
+ )
+ ),
// the value in [General]->key has changed
// the value in [CommonCategory]->newSetting has changed,
// but [CommonCategory]->settingCommon2 hasn't so it is not written
- array('Common tests file', array(
+ array(
+ 'Common tests file',
+ array(
array('General' => array('key' => 'value')), // local
- array('General' => array('key' => 'global'), // global
- 'CommonCategory' => array('settingGlobal' => 'valueGlobal')),
- array('CommonCategory' => array('settingCommon' => 'common', // common
- 'settingCommon2' => 'common2')),
- array('CommonCategory' => array('settingCommon2' => 'common2',
- 'newSetting' => 'newValue'),
- 'General' => array('key' => 'value')),
+ array(
+ 'General' => array('key' => 'global'), // global
+ 'CommonCategory' => array('settingGlobal' => 'valueGlobal')
+ ),
+ array(
+ 'CommonCategory' => array(
+ 'settingCommon' => 'common', // common
+ 'settingCommon2' => 'common2'
+ )
+ ),
+ array(
+ 'CommonCategory' => array(
+ 'settingCommon2' => 'common2',
+ 'newSetting' => 'newValue'
+ ),
+ 'General' => array('key' => 'value')
+ ),
$header . "[General]\nkey = \"value\"\n\n[CommonCategory]\nnewSetting = \"newValue\"\n\n",
- )),
+ )
+ ),
- array('Converts Dollar Sign To Dollar Entity', array(
+ array(
+ 'Converts Dollar Sign To Dollar Entity',
+ array(
array('General' => array('key' => '$value', 'key2' => '${value}')), // local
- array('General' => array('key' => '$global'), // global
- 'CommonCategory' => array('settingGlobal' => 'valueGlobal')),
- array('CommonCategory' => array('settingCommon' => 'common', // common
- 'settingCommon2' => 'common2')),
- array('CommonCategory' => array('settingCommon2' => 'common2',
- 'newSetting' => 'newValue'),
- 'General' => array('key' => '$value', 'key2' => '${value}')),
+ array(
+ 'General' => array('key' => '$global'), // global
+ 'CommonCategory' => array('settingGlobal' => 'valueGlobal')
+ ),
+ array(
+ 'CommonCategory' => array(
+ 'settingCommon' => 'common', // common
+ 'settingCommon2' => 'common2'
+ )
+ ),
+ array(
+ 'CommonCategory' => array(
+ 'settingCommon2' => 'common2',
+ 'newSetting' => 'newValue'
+ ),
+ 'General' => array('key' => '$value', 'key2' => '${value}')
+ ),
$header . "[General]\nkey = \"&#36;value\"\nkey2 = \"&#36;{value}\"\n\n[CommonCategory]\nnewSetting = \"newValue\"\n\n",
- )),
+ )
+ ),
);
}
@@ -377,7 +491,7 @@ class ConfigTest extends TestCase
$sourceConfigFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
$configFile = PIWIK_INCLUDE_PATH . '/tmp/tmp.config.ini.php';
- if(file_exists($configFile)){
+ if (file_exists($configFile)) {
@unlink($configFile);
}
copy($sourceConfigFile, $configFile);
@@ -387,7 +501,7 @@ class ConfigTest extends TestCase
$this->assertEquals(file_get_contents($sourceConfigFile), file_get_contents($configFile));
- if(file_exists($configFile)){
+ if (file_exists($configFile)) {
@unlink($configFile);
}
}
@@ -397,7 +511,7 @@ class ConfigTest extends TestCase
$userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
$globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
$commonFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/common.config.ini.php';
-
+
$config = new Config(new GlobalSettingsProvider($globalFile, $userFile, $commonFile));
$configCategory = $config->getFromGlobalConfig('Category');
@@ -405,25 +519,25 @@ class ConfigTest extends TestCase
$this->assertEquals('value2', $configCategory['key2']);
$this->assertEquals(array('key1' => 'value1', 'key2' => 'value2'), $configCategory);
}
-
+
public function testFromCommonConfig()
{
$userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
$globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
$commonFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/common.config.ini.php';
-
+
$config = new Config(new GlobalSettingsProvider($globalFile, $userFile, $commonFile));
$configCategory = $config->getFromCommonConfig('Category');
$this->assertEquals(array('key2' => 'valueCommon', 'key3' => '${@piwik(crash))}'), $configCategory);
}
-
+
public function testFromLocalConfig()
{
$userFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/config.ini.php';
$globalFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/global.ini.php';
$commonFile = PIWIK_INCLUDE_PATH . '/tests/resources/Config/common.config.ini.php';
-
+
$config = new Config(new GlobalSettingsProvider($globalFile, $userFile, $commonFile));
$configCategory = $config->getFromLocalConfig('Category');