private function addAnnotations() { // create fake access for fake username $access = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($access); // add two annotations per week for three months, starring every third annotation // first month in 2011, second two in 2012 $count = 0; $dateStart = Date::factory('2011-12-01'); $dateEnd = Date::factory('2012-03-01'); while ($dateStart->getTimestamp() < $dateEnd->getTimestamp()) { $starred = $count % 3 == 0 ? 1 : 0; $site1Text = "{$count}: Site 1 annotation for " . $dateStart->toString(); $site2Text = "{$count}: Site 2 annotation for " . $dateStart->toString(); API::getInstance()->add($this->idSite1, $dateStart->toString(), $site1Text, $starred); API::getInstance()->add($this->idSite2, $dateStart->toString(), $site2Text, $starred); $nextDay = $dateStart->addDay(1); ++$count; $starred = $count % 3 == 0 ? 1 : 0; $site1Text = "{$count}: Site 1 annotation for " . $nextDay->toString(); $site2Text = "{$count}: Site 2 annotation for " . $nextDay->toString(); API::getInstance()->add($this->idSite1, $nextDay->toString(), $site1Text, $starred); API::getInstance()->add($this->idSite2, $nextDay->toString(), $site2Text, $starred); $dateStart = $dateStart->addPeriod(1, 'WEEK'); ++$count; } }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); }
public function setUp() { parent::setUp(); // setup the access layer (required in Segment contrustor testing if anonymous is allowed to use segments) $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); }
public function setUp() { parent::setUp(); $pseudoMockAccess = new \FakeAccess(); \FakeAccess::setSuperUserAccess(true); Access::setSingletonInstance($pseudoMockAccess); $idSite = Fixture::createWebsite('2014-01-01 00:00:00'); $this->builder = $this->makeBuilder(array('method' => 'MultiSites_getAll', 'idSite' => $idSite)); }
public function setUp() { parent::setUp(); $GLOBALS['PIWIK_TRACKER_MODE'] = true; // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); ArchiveTableCreator::$tablesAlreadyInstalled = null; }
/** * @dataProvider getUnitColumns * @group Core */ public function testGetUnit($column, $expected) { \Piwik\Site::setSites(array(1 => array('name' => 'TestSite', 'currency' => 'EUR'))); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); $actual = Metrics::getUnit($column, 1); $this->assertEquals($expected, $actual); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); Piwik_PluginsManager::getInstance()->loadPlugins(array('SitesManager')); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); \Piwik\Plugin\Manager::getInstance()->loadPlugins(array('SitesManager')); }
public function setUp() { parent::setUp(); // setup the access layer (required in Segment contrustor testing if anonymous is allowed to use segments) $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); // Load and install plugins $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->loadPlugins(Piwik_Config::getInstance()->Plugins['Plugins']); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; //finally we set the user as a Super User by default Access::setSingletonInstance($pseudoMockAccess); $this->idSiteAccess = APISitesManager::getInstance()->addSite("test", "http://test"); \Piwik\Plugin\Manager::getInstance()->loadPlugins(array('ScheduledReports', 'MobileMessaging', 'MultiSites')); \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins(); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3, 4)); //finally we set the user as a Super User by default FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); $this->auth = new Auth(); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; //finally we set the user as a super user by default Zend_Registry::set('access', $pseudoMockAccess); $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("test", "http://test"); Piwik_PluginsManager::getInstance()->loadPlugins(array('PDFReports', 'MobileMessaging', 'MultiSites')); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); }
function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3, 4)); //finally we set the user as a super user by default FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); // we make sure the tests don't depend on the config file content Piwik_Config::getInstance()->superuser = array('login' => 'superusertest', 'password' => md5('passwordsuperusertest'), 'email' => '*****@*****.**'); }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3, 4)); //finally we set the user as a Super User by default FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); $user_agents = array('Mozilla/6.0 (Macintosh; I; Intel Mac OS X 11_7_9; de-LI; rv:1.9b4) Gecko/2012010317 Firefox/10.0a4', 'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0', 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/18.6.872.0 Safari/535.2 UNTRUSTED/1.0 3gpp-gba UNTRUSTED/1.0', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'); $_SERVER['HTTP_USER_AGENT'] = $user_agents[mt_rand(0, count($user_agents) - 1)]; }
public function setUp() { parent::setUp(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; //finally we set the user as a super user by default Zend_Registry::set('access', $pseudoMockAccess); Piwik_PluginsManager::getInstance()->loadPlugins(array('API', 'UserCountry', 'PDFReports')); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); $this->idSiteAccess = Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net")); $idSite = Piwik_SitesManager_API::getInstance()->addSite("Test", array("http://piwik.net")); FakeAccess::setIdSitesView(array($this->idSiteAccess, 2)); }
public function setUp() { parent::setUp(); \Piwik\Plugin\Manager::getInstance()->loadPlugin('SegmentEditor'); \Piwik\Plugin\Manager::getInstance()->installLoadedPlugins(); // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3, 4)); //finally we set the user as a Super User by default FakeAccess::$superUser = true; FakeAccess::$superUserLogin = '******'; Access::setSingletonInstance($pseudoMockAccess); APISitesManager::getInstance()->addSite('test', 'http://example.org'); }
protected function setUpRootAccess() { $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); }
/** * wrongId => exception */ function test_getSiteUrlsFromId_wrongId() { FakeAccess::setIdSitesView(array(3)); FakeAccess::setIdSitesAdmin(array()); try { Piwik_SitesManager_API::getSiteUrlsFromId(1); } catch (Exception $expected) { return; } $this->fail("Exception not raised."); }
/** * @group Plugins */ public function testGetSitesIdFromSiteUrlUser() { $idsite = API::getInstance()->addSite("site1", array("http://www.piwik.net", "http://piwik.com")); $idsite = API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net")); $idsite = API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org")); $saveAccess = Access::getInstance(); APIUsersManager::getInstance()->addUser("user1", "geqgegagae", "*****@*****.**", "alias"); APIUsersManager::getInstance()->setUserAccess("user1", "view", array(1)); APIUsersManager::getInstance()->addUser("user2", "geqgegagae", "*****@*****.**", "alias"); APIUsersManager::getInstance()->setUserAccess("user2", "view", array(1)); APIUsersManager::getInstance()->setUserAccess("user2", "admin", array(3)); APIUsersManager::getInstance()->addUser("user3", "geqgegagae", "*****@*****.**", "alias"); APIUsersManager::getInstance()->setUserAccess("user3", "view", array(1, 2)); APIUsersManager::getInstance()->setUserAccess("user3", "admin", array(3)); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = false; FakeAccess::$identity = 'user1'; FakeAccess::setIdSitesView(array(1)); FakeAccess::setIdSitesAdmin(array()); Access::setSingletonInstance($pseudoMockAccess); $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com'); $this->assertEquals(1, count($idsites)); // testing URL normalization $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.com'); $this->assertEquals(1, count($idsites)); $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net'); $this->assertEquals(1, count($idsites)); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = false; FakeAccess::$identity = 'user2'; FakeAccess::setIdSitesView(array(1)); FakeAccess::setIdSitesAdmin(array(3)); Access::setSingletonInstance($pseudoMockAccess); $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com'); $this->assertEquals(2, count($idsites)); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = false; FakeAccess::$identity = 'user3'; FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3)); Access::setSingletonInstance($pseudoMockAccess); $idsites = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com'); $this->assertEquals(3, count($idsites)); Access::setSingletonInstance($saveAccess); }
function test_getSitesIdFromSiteUrl_User() { $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array("http://www.piwik.net", "http://piwik.com")); $idsite = Piwik_SitesManager_API::getInstance()->addSite("site2", array("http://piwik.com", "http://piwik.net")); $idsite = Piwik_SitesManager_API::getInstance()->addSite("site3", array("http://piwik.com", "http://piwik.org")); $saveAccess = Zend_Registry::get('access'); Piwik_UsersManager_API::getInstance()->addUser("user1", "geqgegagae", "*****@*****.**", "alias"); Piwik_UsersManager_API::getInstance()->setUserAccess("user1", "view", array(1)); Piwik_UsersManager_API::getInstance()->addUser("user2", "geqgegagae", "*****@*****.**", "alias"); Piwik_UsersManager_API::getInstance()->setUserAccess("user2", "view", array(1)); Piwik_UsersManager_API::getInstance()->setUserAccess("user2", "admin", array(3)); Piwik_UsersManager_API::getInstance()->addUser("user3", "geqgegagae", "*****@*****.**", "alias"); Piwik_UsersManager_API::getInstance()->setUserAccess("user3", "view", array(1, 2)); Piwik_UsersManager_API::getInstance()->setUserAccess("user3", "admin", array(3)); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = false; FakeAccess::$identity = 'user1'; FakeAccess::setIdSitesView(array(1)); FakeAccess::setIdSitesAdmin(array()); Zend_Registry::set('access', $pseudoMockAccess); $idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com'); $this->assertTrue(count($idsites) == 1); // testing URL normalization $idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://www.piwik.com'); $this->assertTrue(count($idsites) == 1); $idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net'); $this->assertTrue(count($idsites) == 1); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = false; FakeAccess::$identity = 'user2'; FakeAccess::setIdSitesView(array(1)); FakeAccess::setIdSitesAdmin(array(3)); Zend_Registry::set('access', $pseudoMockAccess); $idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com'); $this->assertTrue(count($idsites) == 2); $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = false; FakeAccess::$identity = 'user3'; FakeAccess::setIdSitesView(array(1, 2)); FakeAccess::setIdSitesAdmin(array(3)); Zend_Registry::set('access', $pseudoMockAccess); $idsites = Piwik_SitesManager_API::getInstance()->getSitesIdFromSiteUrl('http://piwik.com'); $this->assertTrue(count($idsites) == 3); Zend_Registry::set('access', $saveAccess); }
/** * check to modify as being another user => exception * * @group Plugins * @group UsersManager */ public function testUpdateUserIAmNotTheUser() { try { FakeAccess::$identity = 'login2'; FakeAccess::$superUser = false; $this->testUpdateUserNoEmailNoAlias(); } catch (Exception $e) { return; } $this->fail('Expected exception not raised'); }
/** * @group Core */ public function testIsDefined() { // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); \Piwik\Translate::loadEnglishTranslation(); Fixture::createWebsite('2009-01-04 00:11:42', true); $_GET['idSite'] = 1; WidgetsList::_reset(); WidgetsList::add('Actions', 'Pages', 'Actions', 'getPageUrls'); $this->assertTrue(WidgetsList::isDefined('Actions', 'getPageUrls')); $this->assertFalse(WidgetsList::isDefined('Actions', 'inValiD')); }
/** * Create one 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 canImagesBeIncludedInScheduledReports * @param int $idSite id of website created */ protected static function setUpScheduledReports($idSite) { $includeImages = self::canImagesBeIncludedInScheduledReports(); // fake access is needed so API methods can call Piwik::getCurrentUserLogin(), e.g: 'PDFReports.addReport' $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Zend_Registry::set('access', $pseudoMockAccess); // retrieve available reports $availableReportMetadata = Piwik_PDFReports_API::getReportMetadata($idSite, Piwik_PDFReports::EMAIL_TYPE); $availableReportIds = array(); foreach ($availableReportMetadata as $reportMetadata) { $availableReportIds[] = $reportMetadata['uniqueId']; } //@review should we also test evolution graphs? // set-up mail report Piwik_PDFReports_API::getInstance()->addReport($idSite, 'Mail Test report', 'day', Piwik_PDFReports::EMAIL_TYPE, Piwik_ReportRenderer::HTML_FORMAT, $availableReportIds, array("displayFormat" => $includeImages ? Piwik_PDFReports::DISPLAY_FORMAT_TABLES_AND_GRAPHS : Piwik_PDFReports::DISPLAY_FORMAT_TABLES_ONLY)); // set-up sms report for one website Piwik_PDFReports_API::getInstance()->addReport($idSite, 'SMS Test report, one website', 'day', Piwik_MobileMessaging::MOBILE_TYPE, Piwik_MobileMessaging::SMS_FORMAT, array("MultiSites_getOne"), array("phoneNumbers" => array())); // set-up sms report for all websites Piwik_PDFReports_API::getInstance()->addReport($idSite, 'SMS Test report, all websites', 'day', Piwik_MobileMessaging::MOBILE_TYPE, Piwik_MobileMessaging::SMS_FORMAT, array("MultiSites_getAll"), array("phoneNumbers" => array())); }
private function setUser() { $pseudoMockAccess = new FakeAccess(); FakeAccess::$idSitesView = array(1); Access::setSingletonInstance($pseudoMockAccess); }
public static function setSuperUser($bool = true) { self::$superUser = $bool; }
public static function setIdSitesView($ids) { self::$superUser = false; self::$idSitesView = $ids; }
private static function setSuperUser() { $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); }
/** * check to modify as being another user => exception */ function test_updateUser_IAmNOTTheUser() { FakeAccess::$identity = 'login2'; FakeAccess::$superUser = false; try { $this->test_updateUser_noemailnoalias(); } catch (Exception $expected) { return; } $this->fail("Exception not raised."); }