示例#1
0
 function test_filebased_logger_writes_to_file_when_logging()
 {
     $GLOBALS['log'] = "";
     $debugger = new k_logging_LogDebugger('var://log');
     $glob = new k_adapter_MockGlobalsAccess(array(), array(), array('SERVER_NAME' => 'localhost'));
     $http = new k_HttpRequest('/web2.0', '/web2.0/foo/bar/cux', new k_DefaultIdentityLoader(), null, null, $glob);
     $components = new k_DefaultComponentCreator();
     $components->setDebugger($debugger);
     $root = $components->create('test_CircularComponent', $http);
     $result = $root->dispatch();
     $this->assertPattern('/\\(dispatch/', $GLOBALS['log']);
 }
示例#2
0
 function createComponent($method, $headers = array())
 {
     $glob = new k_adapter_MockGlobalsAccess(array(), array(), array('SERVER_NAME' => 'localhost', 'REQUEST_METHOD' => $method), $headers);
     $translator_loader = new test_TranslatorLoader();
     $http = new k_HttpRequest('', '/', new k_DefaultIdentityLoader(), null, $translator_loader, $glob);
     $components = new k_DefaultComponentCreator();
     return $components->create('test_ContentTypeComponent', $http);
 }
示例#3
0
 function test_subview_cares_about_underscores()
 {
     $http = $this->createHttp('/web2.0', '/foo/bar?delete');
     $components = new k_DefaultComponentCreator();
     $root = $components->create('test_CircularComponent', $http);
     $this->assertEqual('delete', $root->subview());
     $http = $this->createHttp('/web2.0', '/foo/bar?delete_something');
     $components = new k_DefaultComponentCreator();
     $root = $components->create('test_CircularComponent', $http);
     $this->assertEqual('delete_something', $root->subview());
 }
示例#4
0
    {
        if ($this->identity()->anonymous()) {
            throw new k_NotAuthorized();
        }
        return parent::dispatch();
    }
    function renderHtml()
    {
        return sprintf("<p>Hello %s, anon=%s</p>", htmlspecialchars($this->identity()->user()), $this->identity()->anonymous() ? 't' : 'f') . sprintf("<form method='post' action='%s'><p><input type='submit' value='Log out' /></p></form>", htmlspecialchars($this->url('/logout'))) . sprintf("<p><a href='%s'>the dojo</a></p>", htmlspecialchars($this->url('dojo')));
    }
}
class DojoController extends k_Component
{
    function dispatch()
    {
        if ($this->identity()->user() != 'ninja') {
            throw new k_Forbidden();
        }
        return parent::dispatch();
    }
    function renderHtml()
    {
        return "Welcome to the dojo, where only ninjas are allowed";
    }
}
if (realpath($_SERVER['SCRIPT_FILENAME']) == __FILE__) {
    $components = new k_DefaultComponentCreator();
    $components->setImplementation('k_DefaultNotAuthorizedComponent', 'NotAuthorizedComponent');
    $identity_loader = new k_SessionIdentityLoader();
    k()->setComponentCreator($components)->setIdentityLoader($identity_loader)->run('Root')->out();
}
示例#5
0
 function test_can_create_simple_component_with_default_container()
 {
     $components = new k_DefaultComponentCreator();
     $root = $components->create('test_BasicComponent', $this->makeHttp());
     $this->assertIsA($root, 'test_BasicComponent');
 }
示例#6
0
 /**
  * @param Object
  * @return void
  */
 function __construct($injector, $document = null)
 {
     if (!method_exists($injector, 'create')) {
         throw new Exception("Injector must provide a method `create`");
     }
     parent::__construct($document);
     $this->injector = $injector;
 }
示例#7
0
 function test_wrapped_response_retains_status()
 {
     $glob = new k_adapter_MockGlobalsAccess(array(), array(), array('SERVER_NAME' => 'localhost', 'REQUEST_METHOD' => 'get'));
     $http = new k_HttpRequest('', '/hello', new k_DefaultIdentityLoader(), null, null, $glob);
     $components = new k_DefaultComponentCreator();
     $root = $components->create('test_response_RootThreeComponent', $http);
     $r = $root->dispatch();
     $this->assertEqual($r->status(), 500);
     $this->assertEqual($r->toContentType($r->contentType()), "<div class='wrap'><p>Hello world</p></div>");
 }
示例#8
0
 function createBrowser()
 {
     $components = new k_DefaultComponentCreator();
     $components->setImplementation('k_DefaultNotAuthorizedComponent', 'NotAuthorizedComponent');
     return new k_VirtualSimpleBrowser('Root', $components, null, new k_SessionIdentityLoader());
 }