Exemplo n.º 1
0
 public function test_getObject()
 {
     $o = new user($this->dbObj, 2);
     $p = new permission($this->dbObj);
     $o->create(__METHOD__ . "1", "123");
     $this->assertEquals($p->getObject(__METHOD__ . "1"), $o->getObject(__METHOD__ . "1"));
     $p->create(__METHOD__ . "2", 2, 0, "123");
     $this->assertEquals($p->getObject(__METHOD__ . "2"), $o->getObject(__METHOD__ . "2"));
 }
Exemplo n.º 2
0
 public function test_validPerms()
 {
     $o = new permission($this->dbObj);
     //NOTE: this seems overly manual...
     $i = 0;
     $total = 1;
     // start at one instead of zero, because we have to create the "000" permission first.
     $lastId = $o->create(__METHOD__ . '-' . $i, 1, 2, "{$i}");
     while ($i < 777) {
         $testPerm = $i;
         $this->assertTrue(is_numeric($testPerm));
         $this->assertEquals(intval($i), intval(permission::translate_perms("{$i}")));
         $this->assertEquals(strval($i), intval(permission::translate_perms("{$i}")));
         $permBits = str_split(permission::translate_perms("{$testPerm}"));
         if (intval($permBits[2]) < 7) {
             $permBits[2] = intval($permBits[2]) + 1;
         } else {
             $permBits[2] = 0;
             if (intval($permBits[1]) < 7) {
                 $permBits[1] = intval($permBits[1]) + 1;
             } else {
                 $permBits[1] = 0;
                 if (intval($permBits[0]) < 7) {
                     $permBits[0] = intval($permBits[0]) + 1;
                 } else {
                     throw new LogicException(__METHOD__ . " - the cuckoo flew the nest ({$testPerm})... " . print_r($permBits, true));
                 }
             }
         }
         foreach ($permBits as $k => $v) {
             $this->assertTrue(permission::is_valid_perm($v));
         }
         $i = intval(implode('', $permBits));
         $total++;
     }
     $this->assertEquals(512, $total, "wrong number of total permissions created, expected 512, got (" . $total . ")");
 }