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;
     }
 }
Beispiel #2
0
 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);
 }
Beispiel #4
0
 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);
 }
Beispiel #5
0
 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'));
 }
Beispiel #6
0
 /**
  * @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);
 }
Beispiel #7
0
 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;
 }
Beispiel #9
0
 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'));
 }
Beispiel #10
0
 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();
 }
Beispiel #12
0
 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();
 }
Beispiel #14
0
 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' => '*****@*****.**');
 }
Beispiel #15
0
 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)];
 }
Beispiel #16
0
 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));
 }
Beispiel #17
0
 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');
 }
Beispiel #18
0
 /**
  * check to modify as being another user => exception
  *
  * @expectedException \Exception
  */
 public function testUpdateUserIAmNotTheUser()
 {
     FakeAccess::$identity = 'login2';
     FakeAccess::$superUser = false;
     $this->testUpdateUserNoEmailNoAlias();
 }
 /**
  * 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()));
 }
Beispiel #20
0
 /**
  * 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', 0, ScheduledReports::EMAIL_TYPE, ReportRenderer::HTML_FORMAT, $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', 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', 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', 0, ScheduledReports::EMAIL_TYPE, ReportRenderer::HTML_FORMAT, $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'));
     }
 }
Beispiel #21
0
 /**
  * @dataProvider getPermissionsFailData
  * @group        Integration
  */
 public function testMethodPermissions($hasAdminAccess, $hasViewAccess, $request, $checkException, $failMessage)
 {
     // create fake access that denies user access
     $access = new FakeAccess();
     FakeAccess::$superUser = false;
     FakeAccess::$idSitesAdmin = $hasAdminAccess ? array(self::$fixture->idSite1) : array();
     FakeAccess::$idSitesView = $hasViewAccess ? array(self::$fixture->idSite1) : array();
     Access::setSingletonInstance($access);
     if ($checkException) {
         try {
             $request = new Request($request);
             $request->process();
             $this->fail($failMessage);
         } catch (Exception $ex) {
             // pass
         }
     } else {
         $request = new Request($request);
         $response = $request->process();
     }
 }
Beispiel #22
0
 /**
  * @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'));
 }
Beispiel #23
0
 /**
  * @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);
 }
Beispiel #24
0
 public static function setSuperUser($bool = true)
 {
     self::$superUser = $bool;
 }
Beispiel #25
0
 private function setSuperUser()
 {
     $pseudoMockAccess = new FakeAccess();
     FakeAccess::$superUser = true;
     Access::setSingletonInstance($pseudoMockAccess);
 }
 /**
  * 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');
 }
Beispiel #27
0
 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);
 }
Beispiel #28
0
 /**
  * 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.");
 }
Beispiel #29
0
 public static function setIdSitesView($ids)
 {
     self::$superUser = false;
     self::$idSitesView = $ids;
 }
Beispiel #30
0
 protected function setUpRootAccess()
 {
     $pseudoMockAccess = new FakeAccess();
     FakeAccess::$superUser = true;
     Zend_Registry::set('access', $pseudoMockAccess);
 }