PhpManagerTest.php 1.8 KB
Newer Older
tof06 committed
1 2 3 4 5 6 7 8
<?php

namespace yiiunit\framework\rbac;

use Yii;

/**
 * @group rbac
9
 * @property ExposedPhpManager $auth
tof06 committed
10
 */
11
class PhpManagerTest extends ManagerTestCase
tof06 committed
12
{
Alexander Makarov committed
13
    protected function getItemFile()
14 15 16 17
    {
        return Yii::$app->getRuntimePath() . '/rbac-items.php';
    }

Alexander Makarov committed
18
    protected function getAssignmentFile()
19 20 21 22
    {
        return Yii::$app->getRuntimePath() . '/rbac-assignments.php';
    }

Alexander Makarov committed
23
    protected function getRuleFile()
24 25 26 27 28 29
    {
        return Yii::$app->getRuntimePath() . '/rbac-rules.php';
    }

    protected function removeDataFiles()
    {
Alexander Makarov committed
30 31 32
        @unlink($this->getItemFile());
        @unlink($this->getAssignmentFile());
        @unlink($this->getRuleFile());
33 34 35 36 37
    }

    protected function createManager()
    {
        return new ExposedPhpManager([
Alexander Makarov committed
38 39 40
            'itemFile' => $this->getItemFile(),
            'assignmentFile' => $this->getAssignmentFile(),
            'ruleFile' => $this->getRuleFile(),
41 42 43
        ]);
    }

tof06 committed
44 45 46 47
    protected function setUp()
    {
        parent::setUp();
        $this->mockApplication();
48 49
        $this->removeDataFiles();
        $this->auth = $this->createManager();
tof06 committed
50 51 52 53
    }

    protected function tearDown()
    {
54
        $this->removeDataFiles();
tof06 committed
55 56 57 58 59 60
        parent::tearDown();
    }

    public function testSaveLoad()
    {
        $this->prepareData();
61 62 63 64 65

        $items = $this->auth->items;
        $children = $this->auth->children;
        $assignments = $this->auth->assignments;
        $rules = $this->auth->rules;
tof06 committed
66
        $this->auth->save();
67 68

        $this->auth = $this->createManager();
tof06 committed
69 70
        $this->auth->load();

71 72 73 74 75
        $this->assertEquals($items, $this->auth->items);
        $this->assertEquals($children, $this->auth->children);
        $this->assertEquals($assignments, $this->auth->assignments);
        $this->assertEquals($rules, $this->auth->rules);
    }
tof06 committed
76
}