示例#1
0
 /**
  * @param $ip
  * @param $username
  * @param $userid
  * @param $display
  * @param $exception
  * @param $corruptRequest
  *
  * @throws \Exception
  *
  * @dataProvider ipOptions
  */
 public function testRetrieve($ip, $username, $userid, $display, $exception = null, $corruptRequest = false)
 {
     if ($exception !== null) {
         $this->setExpectedException('\\Exception', $exception);
     }
     $cnf = [];
     $cnf['192.168.0.10'] = ['username' => 'bob', 'userid' => 3, 'display' => 'Bobby'];
     $cnf['192.168.0.11'] = ['userid' => 3, 'display' => 'Bobby'];
     $cnf['192.168.0.12'] = ['username' => 'bob', 'display' => 'Bobby'];
     $cnf['tester'] = ['username' => 'pet', 'userid' => 2, 'display' => 'Dog'];
     $cnf['192.168.0.20'] = ['alias' => 'tester'];
     $configProvider = new TestConfigProvider();
     $authSection = new ConfigSection('ipauth', $cnf);
     $configProvider->addSection($authSection);
     $cubex = new Cubex();
     $cubex->configure($configProvider);
     $request = new Request();
     $request->server->set('REMOTE_ADDR', $ip);
     if ($corruptRequest) {
         $cubex->instance('request', 'invalid');
     } else {
         $cubex->instance('request', $request);
     }
     $auth = new IPAuthProvider();
     $auth->setCubex($cubex);
     $user = $auth->login('test', 'test');
     if ($username === null) {
         $this->assertNull($user);
     } else {
         $this->assertEquals($username, $user->getUsername());
         $this->assertEquals($userid, $user->getUserId());
         $this->assertEquals($display, $user->getProperty('display'));
     }
 }
示例#2
0
 protected function getCubex()
 {
     $cubex = new Cubex();
     $cubex->prepareCubex();
     $cubex->processConfiguration($cubex->getConfiguration());
     return $cubex;
 }
示例#3
0
 public function testServiceAliases()
 {
     $cubex = new Cubex();
     $cubex->configure(new TestConfigProvider());
     $manager = new ServiceManager();
     $manager->setCubex($cubex);
     $manager->boot();
     $encrypter = $cubex->make('encrypter');
     $this->assertInstanceOf('\\Illuminate\\Encryption\\Encrypter', $encrypter);
 }
示例#4
0
 public function getKernel($defaultAction = 'abc')
 {
     $cubex = new Cubex();
     $cubex->prepareCubex();
     $cubex->processConfiguration($cubex->getConfiguration());
     $kernel = new SubDomainTester();
     $kernel->setDefaultResponse($defaultAction);
     $kernel->setCubex($cubex);
     return $kernel;
 }
示例#5
0
 public function testGet()
 {
     $cubex = new Cubex();
     $request = new Request([], [], [], ['ckey' => 'cookie']);
     $cubex->instance('request', $request);
     $app = Cookie::getFacadeApplication();
     Cookie::setFacadeApplication($cubex);
     $this->assertEquals('cookie', Cookie::get('ckey'));
     $this->assertEquals('default', Cookie::get('cs', 'default'));
     Cookie::setFacadeApplication($app);
 }
示例#6
0
 public function testRegisterCreatesEncrypter()
 {
     $cubex = new Cubex();
     $cubex->configure(new TestConfigProvider());
     $encryptionService = new EncryptionService();
     $this->assertInstanceOf('\\Cubex\\ServiceManager\\IServiceProvider', $encryptionService);
     $encryptionService->boot($cubex, new ConfigSection());
     $encryptionService->register();
     $encrypter = $cubex->make('encrypter');
     $this->assertInstanceOf('\\Illuminate\\Encryption\\Encrypter', $encrypter);
 }
 /**
  * Process configuration to bind services, interfaces etc
  *
  * @param Cubex                   $cubex
  * @param ConfigProviderInterface $conf
  */
 public static function processConfiguration(Cubex $cubex, ConfigProviderInterface $conf)
 {
     //Abstract, section, value, default
     $defaults = array();
     $defaults[] = ['\\Cubex\\Kernel\\CubexKernel', "kernel", "default", null];
     $defaults[] = ['\\Cubex\\Routing\\IRouter', "routing", "router", '\\Cubex\\Routing\\Router'];
     $defaults[] = ['404', "errors", "404", '\\Cubex\\Responses\\Error404Response'];
     $defaults[] = ['cookie', "user", "cookie", '\\Illuminate\\Cookie\\CookieJar'];
     foreach ($defaults as $item) {
         $cubex->bindFromConfigIf($conf, $item[0], $item[1], $item[2], $item[3]);
     }
 }
示例#8
0
 public function getCommandOutput(ConsoleCommand $command, $options)
 {
     $console = new Console();
     $cubex = new Cubex();
     $cubex->boot();
     $console->setCubex($cubex);
     $command->setApplication($console);
     $input = new ArrayInput(array_merge(['command' => $command->getName()], $options));
     $output = new BufferedOutput();
     $command->run($input, $output);
     return $output->fetch();
 }
 public function prepareViewModel(Request $request = null)
 {
     $view = $this->getMockForAbstractClass('\\Cubex\\View\\BrandedTemplateView');
     /**
      * @var $view BrandedTemplateView
      */
     $view->setTemplateDir(__DIR__ . DIRECTORY_SEPARATOR . 'res');
     $view->setTemplateFile('branded');
     if ($request !== null) {
         $cubex = new Cubex();
         $cubex->instance('request', $request);
         $view->setCubex($cubex);
     }
     return $view;
 }
示例#10
0
 public function testAuthFacade()
 {
     $provider = new TestAuthProvider();
     $authy = new AuthedUser('brooke', 1);
     $provider->setRetrieve($authy);
     $cubex = new Cubex();
     $cubex->configure(new TestConfigProvider());
     $cubex->processConfiguration($cubex->getConfiguration());
     $cubex->instance('request', Request::createFromGlobals());
     $cubex->instance('\\Cubex\\Auth\\IAuthProvider', $provider);
     $sm = new ServiceManager();
     $sm->setCubex($cubex);
     $sm->boot();
     Auth::setFacadeApplication($cubex);
     $username = '******';
     $this->assertTrue(Auth::forgottenPassword($username));
     $authUser = Auth::login($username, 'password');
     $this->assertEquals("brooke", $authUser->getUsername());
     $autho = Auth::getAuthedUser();
     $this->assertEquals("brooke", $autho->getUsername());
     Auth::updateAuthedUser($autho);
     $this->assertTrue(Auth::isLoggedIn());
     $this->assertTrue(Auth::logout());
     $this->assertFalse(Auth::isLoggedIn());
 }
示例#11
0
 /**
  * @param \Exception $e
  * @param            $contains
  *
  * @dataProvider exceptionProvider
  */
 public function testExceptionAsString(\Exception $e, $contains)
 {
     if (is_array($contains)) {
         foreach ($contains as $contain) {
             $this->assertContains($contain, Cubex::exceptionAsString($e));
         }
     } else {
         $this->assertContains($contains, Cubex::exceptionAsString($e));
     }
 }
示例#12
0
 /**
  * @param $uri
  * @param $route
  *
  * @dataProvider baseRoutesProvider
  *
  * @link         https://github.com/cubex/framework/issues/2
  */
 public function testBaseRoutes($uri, $route)
 {
     $request = Request::createFromGlobals();
     $request->server->set('REQUEST_URI', $uri);
     $cubex = new Cubex();
     $cubex->prepareCubex();
     $cubex->processConfiguration($cubex->getConfiguration());
     /**
      * @var CubexKernel|\PHPUnit_Framework_MockObject_MockObject $kernel
      */
     $kernel = $this->getMock('\\Cubex\\Kernel\\CubexKernel', ['getRoutes', 'resp']);
     $kernel->expects($this->any())->method("getRoutes")->will($this->returnValue([$route => 'resp']));
     $kernel->expects($this->any())->method("resp")->will($this->returnValue("respdata"));
     $kernel->setCubex($cubex);
     $resp = $kernel->handle($request, Cubex::MASTER_REQUEST, false);
     $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $resp);
     $this->assertEquals("respdata", $resp->getContent());
 }
示例#13
0
 /**
  * Convert the view model to a string by calling render
  *
  * @return string
  */
 public function __toString()
 {
     try {
         return $this->render();
     } catch (\Exception $e) {
         return Cubex::exceptionAsString($e);
     }
 }