Skip to content

Commit

Permalink
Merge branch 'captureCache' of git://github.com/poisa/zf2 into featur…
Browse files Browse the repository at this point in the history
…e/3747
  • Loading branch information
weierophinney committed Feb 19, 2013
2 parents 855b115 + fc0ce21 commit 42e7b7f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
19 changes: 19 additions & 0 deletions library/Zend/Cache/Pattern/CaptureCache.php
Expand Up @@ -377,4 +377,23 @@ protected function createDirectoryStructure($pathname)

ErrorHandler::stop();
}

/**
* Returns the generated file name.
*
* @param null|string $pageId
* @return string
*/
public function getFilename($pageId = null)
{
if ($pageId === null) {
$pageId = $this->detectPageId();
}

$publicDir = $this->getOptions()->getPublicDir();
$path = $this->pageId2Path($pageId);
$file = $path . \DIRECTORY_SEPARATOR . $this->pageId2Filename($pageId);

return $publicDir . $file;
}
}
49 changes: 49 additions & 0 deletions tests/ZendTest/Cache/Pattern/CaptureCacheTest.php
Expand Up @@ -23,9 +23,11 @@ class CaptureCacheTest extends CommonPatternTest

protected $_tmpCacheDir;
protected $_umask;
protected $_bufferedServerSuperGlobal;

public function setUp()
{
$this->_bufferedServerSuperGlobal = $_SERVER;
$this->_umask = umask();

$this->_tmpCacheDir = @tempnam(sys_get_temp_dir(), 'zend_cache_test_');
Expand All @@ -51,6 +53,8 @@ public function setUp()

public function tearDown()
{
$_SERVER = $this->_bufferedServerSuperGlobal;

$this->_removeRecursive($this->_tmpCacheDir);

if ($this->_umask != umask()) {
Expand Down Expand Up @@ -129,4 +133,49 @@ public function testRemoveThrowsLogicExceptionOnMissingPublicDir()
$this->setExpectedException('Zend\Cache\Exception\LogicException');
$captureCache->remove('/pageId');
}

public function testGetFilenameWithoutPublicDir()
{
$captureCache = new Cache\Pattern\CaptureCache();

$this->assertEquals('/index.html', $captureCache->getFilename('/'));
$this->assertEquals('/dir1/test', $captureCache->getFilename('/dir1/test'));
$this->assertEquals('/dir1/test.html', $captureCache->getFilename('/dir1/test.html'));
$this->assertEquals('/dir1/dir2/test.html', $captureCache->getFilename('/dir1/dir2/test.html'));
}

public function testGetFilenameWithoutPublicDirAndNoPageId()
{
$_SERVER['REQUEST_URI'] = '/dir1/test.html';
$captureCache = new Cache\Pattern\CaptureCache();
$this->assertEquals('/dir1/test.html', $captureCache->getFilename());
}

public function testGetFilenameWithPublicDir()
{
$options = new Cache\Pattern\PatternOptions(array(
'public_dir' => $this->_tmpCacheDir
));

$captureCache = new Cache\Pattern\CaptureCache();
$captureCache->setOptions($options);

$this->assertEquals($this->_tmpCacheDir . '/index.html', $captureCache->getFilename('/'));
$this->assertEquals($this->_tmpCacheDir . '/dir1/test', $captureCache->getFilename('/dir1/test'));
$this->assertEquals($this->_tmpCacheDir . '/dir1/test.html', $captureCache->getFilename('/dir1/test.html'));
$this->assertEquals($this->_tmpCacheDir . '/dir1/dir2/test.html', $captureCache->getFilename('/dir1/dir2/test.html'));
}

public function testGetFilenameWithPublicDirAndNoPageId()
{
$_SERVER['REQUEST_URI'] = '/dir1/test.html';

$options = new Cache\Pattern\PatternOptions(array(
'public_dir' => $this->_tmpCacheDir
));
$captureCache = new Cache\Pattern\CaptureCache();
$captureCache->setOptions($options);

$this->assertEquals($this->_tmpCacheDir . '/dir1/test.html', $captureCache->getFilename());
}
}

0 comments on commit 42e7b7f

Please sign in to comment.