lithium\tests\cases\net\http\MediaTest::testAssetPathGenerationWithLocation PHP Метод

testAssetPathGenerationWithLocation() публичный Метод

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