コード例 #1
0
ファイル: coreurlTest.php プロジェクト: photon/photon
 public function testUrlGenerate()
 {
     Conf::set('urls', array(array('regex' => '#^/home/(.+)/$#', 'view' => array('\\helloworld\\views\\Views', 'you'), 'name' => 'home')));
     $this->assertequals('/home/', URL::generate('/home/'));
     $this->assertequals('/home/?p=foo', URL::generate('/home/', array('p' => 'foo')));
     $this->assertequals('/home/?p=foo&b=bar', URL::generate('/home/', array('p' => 'foo', 'b' => 'bar'), false));
     $this->assertequals('/home/?p=foo&b=bar', URL::generate('/home/', array('p' => 'foo', 'b' => 'bar')));
 }
コード例 #2
0
ファイル: responseTest.php プロジェクト: photon/photon
 public function testRedirectToLogin()
 {
     $request = (object) array('method' => 'POST', 'path' => '/toto');
     $res = new response\RedirectToLogin($request, '/login');
     $this->assertSame(302, $res->status_code);
     Conf::set('urls', array(array('regex' => '#^/login$#', 'view' => array('Dummy', 'dummy'), 'name' => 'login_view')));
     $res = new response\RedirectToLogin($request);
     $this->assertSame(302, $res->status_code);
 }
コード例 #3
0
ファイル: configTest.php プロジェクト: photon/photon
 public function testPf()
 {
     Conf::set('mail_host', '127.0.0.1');
     $mail = Conf::pf('mail_', true);
     $this->assertArrayHasKey('host', $mail);
     $this->assertequals($mail['host'], '127.0.0.1');
     Conf::set('mail_port', 1234);
     $mail = Conf::pf('mail_', false);
     $this->assertequals(count($mail), 2);
     $this->assertArrayHasKey('mail_host', $mail);
     $this->assertArrayHasKey('mail_port', $mail);
 }
コード例 #4
0
ファイル: authTest.php プロジェクト: photon/photon
 public function testAuth()
 {
     Conf::set('auth_config_users', array('foo' => 'hashed', 'foobar' => Hash::hashPass('secret')));
     $user = \photon\auth\Auth::authenticate(array('login' => 'foobar', 'password' => 'secret'));
     $this->assertEquals('foobar', $user->login);
     $req = \photon\test\HTTP::baseRequest();
     $req->session = array();
     $this->assertEquals(true, \photon\auth\Auth::login($req, $user));
     $this->assertEquals(false, \photon\auth\Auth::login($req, false));
     $user->is_anonymous = true;
     $this->assertEquals(false, \photon\auth\Auth::login($req, $user));
 }
コード例 #5
0
ファイル: logTest.php プロジェクト: photon/photon
 public function testLog()
 {
     Log::setLevel('ALL');
     Conf::set('log_delayed', true);
     Conf::set('log_handlers', array('\\photon\\log\\NullBackend'));
     $message = 'dummy message';
     $i = 0;
     Log::plog($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::debug($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::info($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::perf($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::event($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::warn($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::error($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     Log::fatal($message);
     $i++;
     $this->assertEquals($i, count(Log::$stack));
     FileBackend::$return = true;
     Log::flush();
     $this->assertEquals(0, count(Log::$stack));
     FileBackend::$return = false;
     Log::flush();
     $this->assertEquals(0, count(Log::$stack));
     Log::flush();
     $this->assertEquals(0, count(Log::$stack));
     Conf::set('log_delayed', false);
     Log::info($message);
     $this->assertEquals(0, count(Log::$stack));
 }
コード例 #6
0
ファイル: sessionFileTest.php プロジェクト: photon/photon
 public function setup()
 {
     parent::setup();
     Conf::set('session_storage', '\\photon\\session\\storage\\File');
 }
コード例 #7
0
ファイル: translateTest.php プロジェクト: photon/photon
 public function testLoadLocaleWithPhoton()
 {
     Conf::set('locale_folders', array('locale_dummyapp'));
     $pos = Translation::loadLocale('fr', true);
     $this->assertEquals(2, count($pos));
 }
コード例 #8
0
ファイル: manager.php プロジェクト: photon/photon
 /**
  * Custom configuration generation.
  *
  * The goal of the selftest sequence is to perform Photon tests
  * without the need of a configuration file or a project. This
  * makes the run a bit tricky as we need to figure out everything
  * without help from the user. But this is really important for
  * the ease of use of Photon.
  *
  * If the configuration file is forced with the --conf option, it
  * will be used. Else it will use an automatically generated
  * configuration and will use it.
  */
 public function loadConfig($default = 'config.php')
 {
     try {
         $path = parent::loadConfig($default);
     } catch (Exception $e) {
         $this->verbose('Uses automatically generated configuration:');
         $config = array('tmp_folder' => sys_get_temp_dir(), 'secret_key' => 'SECRET_KEY');
         $this->verbose(var_export($config, true));
         Conf::load($config);
         Conf::set('cmd_params', $this->params);
         $path = '';
     }
     return $path;
 }
コード例 #9
0
ファイル: coredispatchTest.php プロジェクト: photon/photon
 public function testViewFoundInSub()
 {
     $views = array(array('regex' => '#^/hello#', 'sub' => array(array('regex' => '#^/home/(.+)/$#', 'view' => function () {
         return false;
     }, 'name' => 'home'))), array('regex' => '#^/foo/(.+)/$#', 'view' => function () {
         throw new \Exception();
     }, 'name' => 'foo_bar'));
     Conf::set('urls', $views);
     $headers = (object) array('METHOD' => 'GET');
     $msg = new Message('dummy', 'dummy', '/hello/home/foo/', $headers, '');
     $req = new \photon\http\Request($msg);
     list($req, $resp) = Dispatcher::dispatch($req);
     $this->assertEquals(false, $resp);
 }
コード例 #10
0
ファイル: rendererTest.php プロジェクト: photon/photon
 public function testCustomTag()
 {
     $tags = Conf::f('template_tags', array());
     $tags['relativity'] = '\\photon\\tests\\template\\rendererTest\\LocalTag';
     Conf::set('template_tags', $tags);
     $renderer = new template\Renderer('data-template-custom-tag.html', array(__DIR__));
     $this->assertequals("E=mc²\n", $renderer->render());
     Conf::set('template_tags', array());
 }
コード例 #11
0
ファイル: baseTest.php プロジェクト: photon/photon
 public function testServerErrorWithTemplate()
 {
     $mess = (object) array('headers' => (object) array('QUERY' => 'a=b&c=d', 'METHOD' => 'GET'), 'path' => '/home', 'sender' => 'mongrel2', 'body' => '', 'conn_id' => '1234');
     $req = new Request($mess);
     try {
         throw new \Exception('Bad exception', 123);
     } catch (\Exception $e) {
     }
     Conf::set('template_folders', array(__DIR__));
     $res = new \photon\http\response\ServerError($e);
     $this->assertEquals('Server Error!' . "\n", $res->content);
 }
コード例 #12
0
ファイル: middlewareTest.php プロジェクト: photon/photon
 public function testHPKP_enable()
 {
     Conf::set('middleware_security', array('hpkp' => true, 'hpkp_options' => array('pin-sha256' => array("MASTER_KEY_IN_BASE64", "BACKUP_KEY_IN_BASE64"))));
     $req = HTTP::baseRequest('GET', '/');
     list($req, $resp) = Dispatcher::dispatch($req);
     $this->assertEquals(200, $resp->status_code);
     $this->assertArrayHasKey('Public-Key-Pins', $resp->headers);
 }