/** * CCValidator::post tests */ public function test_post() { CCIn::instance(new CCIn_Instance(array(), array('agb' => 1), array(), array(), array())); $validator = CCValidator::post(array('agb' => (bool) CCIn::post('agb'))); $this->assertTrue($validator instanceof CCValidator); $this->assertInternalType('bool', $validator->data('agb')); $this->assertTrue($validator->data('agb')); }
/** * Execute the Request * * @param array $action * @param array $params * * @return self */ public function perform() { // set the input if (!is_null($this->input)) { CCIn::instance($this->input); } else { CCIn::instance(CCServer::instance()); } // set current request static::$_current =& $this; // route is invalid show 404 if (!$this->route instanceof CCRoute) { $this->route = CCRouter::resolve('#404'); } /* * call wake events * if one event returns an response all other calls will be skipped also events! */ foreach (CCRouter::events_matching('wake', $this->route->uri) as $callback) { if (($return = CCContainer::call($callback)) instanceof CCResponse) { $this->response = $return; return $this; } } /* * a closure */ if (!is_array($this->route->callback) && is_callable($this->route->callback)) { // execute and capture the output ob_start(); // run the closure $return = call_user_func_array($this->route->callback, $this->route->params); // catch the output $output = ob_get_clean(); // do we got a response? if (!$return instanceof CCResponse) { // if not create one with the captured output $return = CCResponse::create($output); } } elseif (is_callable($this->route->callback)) { // execute the callback and get the return $return = call_user_func_array($this->route->callback, array($this->route->action, $this->route->params)); // do we got a response? if (!$return instanceof CCResponse) { // if not create one with the return as string $return = CCResponse::create((string) $return); } } else { $return = CCResponse::error(404); } // set the response $this->response = $return; /* * call sleep events * if one event returns an response all other calls will be skipped also events! */ foreach (CCRouter::events_matching('sleep', $this->route->uri) as $callback) { if ($return = CCContainer::call($callback, $this->response) instanceof CCResponse) { $this->response = $return; return $this; } } return $this; }
/** * test assignment * generates an clean Input instance * you can pass custom params for testing */ public function fakeServerData($add_get = array(), $add_post = array(), $add_server = array()) { $add_get = array_merge(array('foo' => 32, 'hello' => 'world', 'id' => '453'), $add_get); $add_post = array_merge(array('foo' => 32, 'hello' => 'world', 'id' => '453', 'some' => 'Other other String'), $add_post); $add_server = array_merge(array('HTTP_HOST' => 'local.ccf2.com', 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71', 'HTTP_ACCEPT_LANGUAGE' => 'en-us', 'HTTP_CACHE_CONTROL' => 'max-age=0', 'HTTP_CONNECTION' => 'keep-alive', 'SERVER_SOFTWARE' => 'Apache/2.4.4 (Unix) PHP/5.4.16 OpenSSL/1.0.1e mod_perl/2.0.8-dev Perl/v5.16.3', 'SERVER_NAME' => 'local.ccf2.com', 'SERVER_ADDR' => '127.0.0.1', 'SERVER_PORT' => '80', 'REMOTE_ADDR' => '123.121.123.121', 'REQUEST_SCHEME' => 'http', 'REMOTE_PORT' => '51749', 'GATEWAY_INTERFACE' => 'CGI/1.1', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_METHOD' => 'POST', 'QUERY_STRING' => '', 'REQUEST_URI' => '/', 'SCRIPT_NAME' => '/index.php', 'PHP_SELF' => '/index.php', 'REQUEST_TIME' => time(), 'CLANCATS_ENV' => 'development'), $add_server); CCIn::instance(new CCIn_Instance($add_get, $add_post, array(), array(), $add_server)); }
/** * CCUrl::active tests */ public function test_active() { // fake some data CCIn::instance(new CCIn_Instance(array('param' => 1, 'test' => 'tee'), array(), array(), array(), array('REQUEST_URI' => '//foo/bar//file.xml?param=1&test=tee'))); $this->assertFalse(CCUrl::active('/')); $this->assertTrue(CCUrl::active('/foo/bar')); $this->assertFalse(CCUrl::active('/foo/boo')); $this->assertTrue(CCUrl::active('http://example.com/foo/bar')); $this->assertTrue(CCUrl::active('foo')); $this->assertTrue(CCUrl::active('foo/bar/file.xml?sdfsd')); }
/** * Handler::sign_in keep login tests */ public function test_sign_in_keeper() { Auth\Handler::kill_instance('main'); $example_user = clone static::$current_user; $auth = Auth\Handler::create(); $auth->sign_in($example_user, false); $this->assertTrue($auth->user instanceof DB\Model); $this->assertEquals(static::$current_user->id, $auth->user->id); // test valid Auth\Handler::kill_instance('main'); $auth = Auth\Handler::create(); $this->assertTrue($auth->valid()); // lets create an keeper login now $this->create_keeper_login(); // lets test the login store event $this->assertEquals(null, $auth->login()->client_ip); $auth->session->destroy(); CCEvent::mind('auth.store_login', function ($data) { $data['client_ip'] = '127.0.0.1'; return $data; }); Auth\Handler::kill_instance('main'); $auth = Auth\Handler::create(); $this->assertTrue($auth->valid()); $this->assertEquals('127.0.0.1', $auth->login()->client_ip); // now lets modify some data to force restore failure // changing the the current client ip will force failure CCIn::instance(new CCIn_Instance(array(), array(), array(), array(), array('REMOTE_ADDR' => '192.168.1.42'))); $this->keeper_login_false(); // next lets modify the users password wich will force a failure $this->create_keeper_login(); $this->keeper_login_true(); static::$current_user->password = "******"; static::$current_user->save(); $this->keeper_login_false(); // modifiy the restore_id $this->create_keeper_login(); $this->keeper_login_true(); CCCookie::set('ccauth-restore-id', '34'); $this->keeper_login_false(); // modifiy the restore_token $this->create_keeper_login(); $this->keeper_login_true(); CCCookie::set('ccauth-restore-token', 'wrong'); $this->keeper_login_false(); // delete the user $this->create_keeper_login(); $this->keeper_login_true(); static::$current_user->delete(); $this->keeper_login_false(); // create him again static::$current_user->save(); }