作者:ahdinosau
项目:analytics.dinosaur.i
private function assertAccessReloadedAndRestored($expectedTokenToBeReloaded)
{
$this->access->expects($this->exactly(2))->method('reloadAccess');
// verify access reloaded
$this->auth->expects($this->at(0))->method('setLogin')->with($this->equalTo(null));
$this->auth->expects($this->at(1))->method('setTokenAuth')->with($this->equalTo($expectedTokenToBeReloaded));
$this->auth->expects($this->at(2))->method('authenticate')->will($this->returnValue(new AuthResult(AuthResult::SUCCESS, 'login1', $expectedTokenToBeReloaded)));
// verify access restored
$this->auth->expects($this->at(3))->method('setLogin')->with($this->equalTo(null));
$this->auth->expects($this->at(4))->method('setTokenAuth')->with($this->equalTo($tokenRestored = $this->userAuthToken));
$this->auth->expects($this->at(5))->method('authenticate')->will($this->returnValue(new AuthResult(AuthResult::SUCCESS, 'login', $this->userAuthToken)));
}
作者:a4tunad
项目:piwi
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;
}
}
作者:FluentDevelopmen
项目:piwi
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->recreateContainerWithWebEnvironment();
$this->initHostAndQueryString($input);
if ($this->isTestModeEnabled()) {
$indexFile = '/tests/PHPUnit/proxy/';
$this->resetDatabase();
} else {
$indexFile = '/';
}
$indexFile .= 'index.php';
if (!empty($_GET['pid'])) {
$process = new Process($_GET['pid']);
if ($process->hasFinished()) {
return;
}
$process->startProcess();
}
if ($input->getOption('superuser')) {
StaticContainer::addDefinitions(array('observers.global' => \DI\add(array(array('Environment.bootstrapped', function () {
Access::getInstance()->setSuperUserAccess(true);
})))));
}
require_once PIWIK_INCLUDE_PATH . $indexFile;
if (!empty($process)) {
$process->finishProcess();
}
}
作者:a4tunad
项目:piwi
public function setUp()
{
parent::setUp();
// setup the access layer
$pseudoMockAccess = new FakeAccess();
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
}
作者:TensorWrenchOS
项目:piwi
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'));
}
作者:FluentDevelopmen
项目:piwi
private function makeSureTestRunsInContextOfAnonymousUser()
{
Piwik::postEvent('Request.initAuthenticationObject');
$access = Access::getInstance();
$this->hasSuperUserAccess = $access->hasSuperUserAccess();
$access->setSuperUserAccess(false);
$access->reloadAccess(StaticContainer::get('Piwik\\Auth'));
Request::reloadAuthUsingTokenAuth(array('token_auth' => 'anonymous'));
}
作者:piwi
项目:piwi
private function migratePluginEmailUpdateSetting()
{
$isEnabled = Option::get('enableUpdateCommunicationPlugins');
Access::doAsSuperUser(function () use($isEnabled) {
$settings = StaticContainer::get('Piwik\\Plugins\\CoreUpdater\\SystemSettings');
$settings->sendPluginUpdateEmail->setValue(!empty($isEnabled));
$settings->save();
});
}
作者:carriercom
项目:piwi
public function setUp()
{
parent::setUp();
$access = Access::getInstance();
$access->setSuperUserAccess(true);
$this->idSiteAccess = APISitesManager::getInstance()->addSite("test", "http://test");
\Piwik\Plugin\Manager::getInstance()->loadPlugins(array('MultiSites', 'VisitsSummary', 'Actions'));
\Piwik\Plugin\Manager::getInstance()->installLoadedPlugins();
}
作者:a4tunad
项目:piwi
/**
* @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);
}
作者:TensorWrenchOS
项目:piwi
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));
}
作者:JoeHor
项目:piwi
private function hasAccessToSameSite($login)
{
// users is allowed to see other users having view or admin access to these sites
if (!isset($this->idSitesWithAdmin)) {
$this->idSitesWithAdmin = $this->access->getSitesIdWithAdminAccess();
$this->usersWithAdminAccess = $this->model->getUsersSitesFromAccess('admin');
$this->usersWithViewAccess = $this->model->getUsersSitesFromAccess('view');
}
return isset($this->usersWithViewAccess[$login]) && array_intersect($this->idSitesWithAdmin, $this->usersWithViewAccess[$login]) || isset($this->usersWithAdminAccess[$login]) && array_intersect($this->idSitesWithAdmin, $this->usersWithAdminAccess[$login]);
}
作者:carriercom
项目:piwi
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();
}
作者:TensorWrenchOS
项目:piwi
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();
}
作者:a4tunad
项目:piwi
public function setUp()
{
parent::setUp();
$this->api = API::getInstance();
$pseudoMockAccess = new FakeAccess();
FakeAccess::$superUser = true;
Access::setSingletonInstance($pseudoMockAccess);
Fixture::createWebsite('2014-01-01 00:00:00');
Fixture::createWebsite('2014-01-01 00:00:00');
Fixture::createWebsite('2014-01-01 00:00:00');
$this->api->addUser('userLogin', 'password', 'userlogin@password.de');
}
作者:ahdinosau
项目:analytics.dinosaur.i
/**
* NOTE: This test must be last since the new sites that get added are added in
* random order.
*/
public function testDynamicResolverSitesCreated()
{
self::$fixture->logVisitsWithDynamicResolver();
// reload access so new sites are viewable
Access::getInstance()->setSuperUserAccess(true);
// make sure sites aren't created twice
$piwikDotNet = API::getInstance()->getSitesIdFromSiteUrl('http://piwik.net');
$this->assertEquals(1, count($piwikDotNet));
$anothersiteDotCom = API::getInstance()->getSitesIdFromSiteUrl('http://anothersite.com');
$this->assertEquals(1, count($anothersiteDotCom));
$whateverDotCom = API::getInstance()->getSitesIdFromSiteUrl('http://whatever.com');
$this->assertEquals(1, count($whateverDotCom));
}
作者:carriercom
项目:piwi
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)];
}
作者:TensorWrenchOS
项目:piwi
public function setUp()
{
// drop all tables
Db::dropAllTables();
// download data dump if url supplied
if (is_file($this->dumpUrl)) {
$dumpPath = $this->dumpUrl;
} else {
$dumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql.gz';
$bufferSize = 1024 * 1024;
$dump = fopen($this->dumpUrl, 'rb');
$outfile = fopen($dumpPath, 'wb');
$bytesRead = 0;
while (!feof($dump)) {
fwrite($outfile, fread($dump, $bufferSize), $bufferSize);
$bytesRead += $bufferSize;
}
fclose($dump);
fclose($outfile);
if ($bytesRead <= 40 * 1024 * 1024) {
// sanity check
throw new Exception("Could not download sql dump!");
}
}
// unzip the dump
if (substr($dumpPath, -3) === ".gz") {
$deflatedDumpPath = PIWIK_INCLUDE_PATH . '/tmp/logdump.sql';
// TODO: should depend on name of URL
exec("gunzip -c \"" . $dumpPath . "\" > \"{$deflatedDumpPath}\"", $output, $return);
if ($return !== 0) {
throw new Exception("gunzip failed: " . implode("\n", $output));
}
} else {
$deflatedDumpPath = $dumpPath;
}
// load the data into the correct database
$user = Config::getInstance()->database['username'];
$password = Config::getInstance()->database['password'];
Config::getInstance()->database['tables_prefix'] = $this->tablesPrefix;
$cmd = "mysql -u \"{$user}\" \"--password={$password}\" {$this->dbName} < \"" . $deflatedDumpPath . "\" 2>&1";
exec($cmd, $output, $return);
if ($return !== 0) {
throw new Exception("Failed to load sql dump: " . implode("\n", $output));
}
// make sure archiving will be called
Rules::setBrowserTriggerArchiving(true);
// reload access
Access::getInstance()->reloadAccess();
$this->getTestEnvironment()->configOverride = array('database' => array('tables_prefix' => $this->tablesPrefix));
$this->getTestEnvironment()->save();
}
作者:hichni
项目:piwi
function validateOwner()
{
try {
$timezone = $this->owner->getValue();
if (!empty($timezone)) {
Access::doAsSuperUser(function () use($timezone) {
API::getInstance()->setDefaultTimezone($timezone);
});
}
} catch (\Exception $e) {
return false;
}
return true;
}
作者:FluentDevelopmen
项目:piwi
public function setUserDefaultReportPreference()
{
// We initialize the default report user preference for each user (if it hasn't been inited before) for performance,
// doing this lets us avoid loading all siteIds (which can be 50k or more) when this preference is requested.
// getting the user preference can be called quite often when generating links etc (to get defaultWebsiteId).
$usersModel = $this->usersModel;
$usersManagerApi = $this->usersManagerApi;
Access::getInstance()->doAsSuperUser(function () use($usersModel, $usersManagerApi) {
$allUsers = $usersModel->getUsers(array());
foreach ($allUsers as $user) {
$usersManagerApi->initUserPreferenceWithDefault($user['login'], API::PREFERENCE_DEFAULT_REPORT);
}
});
}
作者:hichni
项目:piwi
/**
* Setup the database and create the base tables for all tests
*/
public function setUp()
{
parent::setUp();
static::$fixture->extraDefinitions = array_merge(static::provideContainerConfigBeforeClass(), $this->provideContainerConfig());
static::$fixture->createEnvironmentInstance();
Db::createDatabaseObject();
Fixture::loadAllPlugins(new TestingEnvironmentVariables(), get_class($this), self::$fixture->extraPluginsToLoad);
Access::getInstance()->setSuperUserAccess(true);
if (!empty(self::$tableData)) {
self::restoreDbTables(self::$tableData);
}
PiwikCache::getEagerCache()->flushAll();
PiwikCache::getTransientCache()->flushAll();
MenuAbstract::clearMenus();
}