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

ManyUsers.php « Fixtures « tests « UsersManager « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b2be04550d7049c17f73ff615b2ba5e2bd55dd56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link    http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Plugins\UsersManager\tests\Fixtures;

use Piwik\Plugins\UsersManager\API;
use Piwik\Plugins\UsersManager\Model;
use Piwik\Tests\Framework\Fixture;

/**
 * Generates tracker testing data for our APITest
 *
 * This Simple fixture adds one website and tracks one visit with couple pageviews and an ecommerce conversion
 */
class ManyUsers extends Fixture
{
    public $dateTime = '2013-01-23 01:23:45';
    public $idSite = 1;

    public $users = array(
        'login1' => array(),
        'login2' => array('view' => array(1,3,5),   'admin' => array(2,6)),
        'login3' => array('view' => array(),        'admin' => array()), // no access to any site
        'login4' => array('view' => array(6),       'admin' => array()), // only access to one with view
        'login5' => array('view' => array(),        'admin' => array(3)), // only access to one with admin
        'login6' => array('view' => array(),        'admin' => array(6,3)), // access to a couple of sites with admin
        'login7' => array('view' => array(2,1,6,3), 'admin' => array()), // access to a couple of sites with view
        'login8' => array('view' => array(4,7),     'admin' => array(2,5)), // access to a couple of sites with admin and view
    );

    public function setUp()
    {
        $this->setUpWebsite();
        $this->setUpUsers();
    }

    public function tearDown()
    {
        // empty
    }

    private function setUpWebsite()
    {
        for ($i=0; $i < 7; $i++) {
            Fixture::createWebsite('2010-01-01 00:00:00');
        }
    }

    protected function setUpUsers()
    {
        $model = new Model();
        $api = API::getInstance();
        foreach ($this->users as $login => $permissions) {
            $api->addUser($login, 'password', $login . '@example.com');
            foreach ($permissions as $access => $idSites) {
                if (!empty($idSites)) {
                    $api->setUserAccess($login, $access, $idSites);
                }
            }

            $user = $model->getUser($login);
            $this->users[$login]['token'] = $user['token_auth'];
        }

        $api->setSuperUserAccess('login1', true);
    }

}