lithium\tests\cases\net\http\MediaTest::testAssetPathGeneration PHP Method

testAssetPathGeneration() public method

    public function testAssetPathGeneration()
    {
        $resources = Libraries::get(true, 'resources');
        $this->skipIf(!is_writable($resources), "Cannot write test app to resources directory.");
        $paths = array("{$resources}/media_test/webroot/css", "{$resources}/media_test/webroot/js");
        foreach ($paths as $path) {
            if (!is_dir($path)) {
                mkdir($path, 0777, true);
            }
        }
        touch("{$paths[0]}/debug.css");
        Libraries::add('media_test', array('path' => "{$resources}/media_test"));
        $result = Media::asset('debug', 'css', array('check' => true, 'library' => 'media_test'));
        $this->assertEqual('/media_test/css/debug.css', $result);
        $result = Media::asset('debug', 'css', array('timestamp' => true, 'library' => 'media_test'));
        $this->assertPattern('%^/media_test/css/debug\\.css\\?\\d+$%', $result);
        $result = Media::asset('debug.css?type=test', 'css', array('check' => true, 'base' => 'foo', 'library' => 'media_test'));
        $this->assertEqual('foo/media_test/css/debug.css?type=test', $result);
        $result = Media::asset('debug.css?type=test', 'css', array('check' => true, 'base' => 'foo', 'timestamp' => true, 'library' => 'media_test'));
        $this->assertPattern('%^foo/media_test/css/debug\\.css\\?type=test&\\d+$%', $result);
        $file = Media::path('css/debug.css', 'bar', array('library' => 'media_test'));
        $this->assertFileExists($file);
        $result = Media::asset('this.file.should.not.exist', 'css', array('check' => true));
        $this->assertFalse($result);
        unlink("{$paths[0]}/debug.css");
        foreach (array_merge($paths, array(dirname($paths[0]))) as $path) {
            rmdir($path);
        }
    }