public function testObjectMethod() { $this->Authenticators->append('FirstMockModularAuthenticator'); $this->assertTrue($this->Authenticators->exists('FirstMockModularAuthenticator')); $this->assertIsA($this->Authenticators->get('FirstMockModularAuthenticator'), 'FirstMockModularAuthenticatorComponent'); $this->Authenticators->append('FirstMockModularAuthenticator', array('disable' => true)); $this->assertTrue($this->Authenticators->get('FirstMockModularAuthenticator')->disabled()); $this->Authenticators->drop('FirstMockModularAuthenticator'); $this->assertFalse($this->Authenticators->exists('FirstMockModularAuthenticator')); $this->Authenticators->append(array('FirstMockModularAuthenticator', 'SecondMockModularAuthenticator')); $this->assertTrue($this->Authenticators->exists('FirstMockModularAuthenticator', 'SecondMockModularAuthenticatorComponent')); ModularAuthUtility::deleteObject('FirstMockModularAuthenticator', 'SecondMockModularAuthenticatorComponent'); $this->Authenticators->append('Hoge', new FirstMockModularAuthenticatorComponent()); $this->assertTrue($this->Authenticators->exists('Hoge')); try { $this->Authenticators->append('HogeModularAuthenticator'); $this->fail('Unavailable object'); } catch (Exception $e) { $this->assertIsA($e, 'ModularAuth_AuthenticatorNotFoundException'); } try { $this->Authenticators->append(null); $this->fail('empty name'); } catch (Exception $e) { $this->assertIsA($e, 'ModularAuth_IllegalAuthenticatorNameException'); $this->assertIdentical($e->getMessage(), 'NULL'); } $this->expectException('ModularAuth_IllegalAuthenticatorObjectException'); $this->Authenticators->append('Hoge', new Object()); }
function testSetup() { $this->Component->initialize($this->Controller); $this->assertIsA($this->Component->Controller, 'Controller'); $this->assertIsA($this->Component->Authenticators, 'ModularAuthenticators'); $this->assertIsA($this->Component->Authenticators->Controller, 'Controller'); $this->assertIsA($this->Component->Authenticators->Auth, 'AuthComponent'); $this->assertTrue(ModularAuthUtility::isRegistered('Auth', 'Controller', 'Authenticators')); $this->startTest(); $this->Component->initialize($this->Controller, array('collector' => 'MockModularAuthenticators')); $this->assertIsA($this->Component->Authenticators, 'MockModularAuthenticators'); $this->startTest(); $this->Component->initialize($this->Controller, array('authenticators' => 'MockModularAuthenticator')); $this->assertIsA($this->Component->MockModularAuthenticator, 'MockModularAuthenticatorComponent'); }
protected function _setup($Controller, $settings) { ModularAuthUtility::registerObject(compact('Controller') + array('Auth' => $this)); if (isset($settings['collector'])) { $this->collector = $settings['collector']; unset($settings['collector']); } $Authenticators = ModularAuthUtility::loadLibrary('Lib', $this->collector); ModularAuthUtility::registerObject(compact('Authenticators')); $Authenticators->configure($settings); if (isset($settings['authenticators'])) { $Authenticators->append($settings['authenticators']); unset($settings['authenticators']); } ModularAuthUtility::bindObject($this, 'Controller', 'Authenticators'); return $settings; }
public function __unset($name) { return ModularAuthUtility::deleteObject($name); }
public function endTest($method) { ModularAuthUtility::flushObjects(); parent::endTest($method); }
public function testObjectMethods() { $destination = new Object(); $registered = new Object(); ModularAuthUtility::registerObject('registered', $registered); ModularAuthUtility::bindObject($destination, 'registered'); $this->assertTrue($destination->Registered === $registered); $this->assertTrue(ModularAuthUtility::isRegistered($registered)); $Registered = new Object(); $Registered->testVar = 1; ModularAuthUtility::registerObject(compact('Registered')); $this->assertFalse(isset($destination->Registered->testVar)); ModularAuthUtility::bindObject($destination, 'Registered'); $this->assertIdentical($destination->Registered->testVar, 1); ModularAuthUtility::unbindObject($destination, 'Registered'); $this->assertFalse(isset($destination->Registered)); ModularAuthUtility::registerObject('one', new Object()); ModularAuthUtility::registerObject('two', new Object()); ModularAuthUtility::registerObject('three', new Object()); $this->assertTrue(ModularAuthUtility::isRegistered('One', 'Two', 'Three')); $this->assertIsA(ModularAuthUtility::getObject('one'), 'Object'); ModularAuthUtility::bindObject($destination, array('one', array('two')), array(array(array('three')))); $this->assertTrue(isset($destination->One)); $this->assertTrue(isset($destination->Two)); $this->assertTrue(isset($destination->Three)); ModularAuthUtility::bindObject('One', 'Two'); $this->assertTrue(isset($destination->One->Two)); ModularAuthUtility::unbindObject($destination, 'one', 'two', array(array('three', 'two', 'one'))); $this->assertFalse(isset($destination->One)); $this->assertFalse(isset($destination->Two)); $this->assertFalse(isset($destination->Three)); $this->assertTrue(ModularAuthUtility::isRegistered('Registered', 'One', 'Two', 'Three')); ModularAuthUtility::deleteObject('One'); $this->assertFalse(ModularAuthUtility::isRegistered('Registered', 'One', 'Two', 'Three')); $this->assertTrue(ModularAuthUtility::flushObjects()); $this->assertFalse(ModularAuthUtility::flushObjects()); $this->assertFalse(ModularAuthUtility::isRegistered($Registered)); $this->assertNull(ModularAuthUtility::isRegistered($fp = fopen(__FILE__, 'r'))); fclose($fp); ModularAuthUtility::registerObject('Auth', $this->Auth); ModularAuthUtility::registerObject('Controller', $this->Controller); ModularAuthUtility::loadAuthenticator('MockModularAuthenticator'); $this->assertTrue(ModularAuthUtility::flushObjects()); try { ModularAuthUtility::bindObject($destination, 'UnredisteredObject'); $this->fail('ModularAuthUtility::bindObject(UnredisteredObject) %s'); } catch (Exception $e) { $this->assertIsA($e, 'ModularAuth_UnregisteredObjectException'); } try { ModularAuthUtility::unbindObject($destination, 'UnredisteredObject'); $this->fail('ModularAuthUtility::unbindObject(UnredisteredObject) %s'); } catch (Exception $e) { $this->assertIsA($e, 'ModularAuth_UnregisteredObjectException'); } try { ModularAuthUtility::getObject('UnredisteredObject'); $this->fail('ModularAuthUtility::getObject(UnredisteredObject) %s'); } catch (Exception $e) { $this->assertIsA($e, 'ModularAuth_UnregisteredObjectException'); } try { ModularAuthUtility::deleteObject('UnredisteredObject'); $this->fail('ModularAuthUtility::deleteObject(UnredisteredObject) %s'); } catch (Exception $e) { $this->assertIsA($e, 'ModularAuth_UnregisteredObjectException'); } }
function testInterrupt() { $this->Auth->Authenticators = ModularAuthUtility::loadLibrary('Lib', 'ModularAuthenticators'); $this->assertIdentical($this->Authenticator->dispatchMethod('login', 'before', array(), 'boolean'), 'interrupted'); }