/** * Tests the writing mechanism. At first, no Response object is bound to the logger, so * it queues up the messages. When the Response object finally gets bound, it flushes the * needed headers and all messages at once. All messages coming after this point get added * to the header immediately. */ public function testWrite() { $response = new Response(); $result = Logger::write('debug', 'FirePhp to the rescue!', array('name' => 'firephp')); $this->assertTrue($result); $this->assertFalse($response->headers()); $host = 'meta.firephp.org'; $expected = array("X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2", "X-Wf-1-Plugin-1: http://{$host}/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3", "X-Wf-1-Structure-1: http://{$host}/Wildfire/Structure/FirePHP/FirebugConsole/0.1", "X-Wf-1-1-1-1: 41|[{\"Type\":\"LOG\"},\"FirePhp to the rescue!\"]|"); Logger::adapter('firephp')->bind($response); $this->assertEqual($expected, $response->headers()); $result = Logger::write('debug', 'Add this immediately.', array('name' => 'firephp')); $this->assertTrue($result); $expected[] = 'X-Wf-1-1-1-2: 40|[{"Type":"LOG"},"Add this immediately."]|'; $this->assertEqual($expected, $response->headers()); }
public function render() { $this->testHeaders = array(); parent::render(); $this->headers = array(); }
/** * Tests that attempts to render a media type with no handler registered produces an * 'unhandled media type' exception, even if the type itself is a registered content type. * * @return void */ public function testUnregisteredContentHandler() { $response = new Response(); $response->type('xml'); $this->expectException("Unhandled media type `xml`."); Media::render($response, array('foo' => 'bar')); $result = $response->body; $this->assertNull($result); }
public function testRenderWithOptionsMerging() { $base = Libraries::get(true, 'resources') . '/tmp'; $this->skipIf(!is_writable($base), "Path `{$base}` is not writable."); $request = new Request(); $request->params['controller'] = 'pages'; $response = new Response(); $response->type('html'); $this->assertException("/Template not found/", function () use($response) { Media::render($response, null, compact('request')); }); $this->_cleanUp(); }
public function testDefaultTypeInitialization() { $response = new Response(array('request' => new MockRequestType())); $this->assertEqual('foo', $response->type()); }
*/ $backend = Libraries::get('li3_backend', 'urlPrefix'); $backend || ($backend = 'backend'); /** * Enable access to assets from installed libraries * This route expect all `lithium` libraries prefixed with `li3_` * * For example route `'/assets/backend/css/bootstrap.css'` is equivalent to: * `'/assets/li3_backend/css/bootstrap.css'` and will look for assets in library `webroot` dir. * * To speed up your application you can copy any asset to your public webroot. Just create same * directory structure as url and your asset will be loaded properly. */ Router::connect('/assets/{:library}/{:args}', array(), function ($request) { $file = Media::webroot('li3_' . $request->params['library']); $file .= '/' . join('/', $request->params['args']); if (file_exists($file)) { $info = pathinfo($file); $media = Media::type($info['extension']); $content = (array) $media['content']; $response = new Response(array('headers' => array('Content-type' => reset($content)), 'body' => file_get_contents($file))); $response->cache('+1 hour'); return $response; } throw new \lithium\action\DispatchException(); }); /** * Backend routing * `backend` prefix is prepended to `action` name. */ Router::connect('/' . $backend . '/{:args}', array('backend' => true), array('continue' => true));
public function testRender() { $response = new Response(); $response->type('json'); $data = array('something'); Media::render($response, $data); $expected = array('Content-type: application/json'); $result = $response->headers(); $this->assertEqual($expected, $result); $expected = json_encode($data); $result = $response->body(); $this->assertEqual($expected, $result); }