Inheritance: extends lithium\core\Object
Beispiel #1
0
 /**
  * Tests that user information is automatically retrieved via the closure in the `'user'`
  * config.
  */
 public function testAutoUser()
 {
     $request = new Request();
     $user = array('username' => 'Tom');
     $adapter = new Rules(array('rules' => array('user' => function ($user, $request, $options) {
         return isset($user['username']) && $user['username'] == 'Tom';
     }), 'default' => array('user'), 'user' => function () use($user) {
         return $user;
     }));
     $result = $adapter->check($user, compact('request'));
     $this->assertEqual(array(), $result);
     $result = $adapter->check(null, compact('request'));
     $this->assertEqual(array(), $result);
     $result = $adapter->check(array('username' => 'Bob'), compact('request'));
     $this->assertEqual(array('rule' => 'user'), $result);
 }
Beispiel #2
0
 public function testAutoUser()
 {
     $user = ['username' => 'Mehlah'];
     $adapter = new Rules(['rules' => ['isMehlah' => function ($user, $request, $options) {
         return isset($user['username']) && $user['username'] == 'Mehlah';
     }], 'defaults' => ['isMehlah'], 'user' => function () use($user) {
         return $user;
     }]);
     $result = $adapter->check($user, null);
     $this->assertTrue($result);
     $result = $adapter->check(null, null);
     $this->assertTrue($result);
     $result = $adapter->check(['username' => 'Bob'], null);
     $this->assertFalse($result);
     $expected = ['isMehlah' => 'You are not permitted to access this area.'];
     $result = $adapter->error();
     $this->assertEqual($expected, $result);
 }