Skip to content

Commit

Permalink
Merge pull request #18 from matomo-org/small-mods
Browse files Browse the repository at this point in the history
Make File::getFilename() public and return correct value in File::doFlush().
  • Loading branch information
tsteur authored Mar 5, 2018
2 parents df16f20 + 4ae0db1 commit 5d20f42
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Backend/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ public function doFlush()
{
// if the directory does not exist, do not bother to continue clearing
if (!is_dir($this->directory)) {
return;
return false;
}

foreach ($this->getFileIterator() as $name => $file) {
$this->opCacheInvalidate($name);
}

parent::doFlush();
return parent::doFlush();
}

private function invalidateCacheFile($id)
Expand All @@ -105,7 +105,7 @@ private function invalidateCacheFile($id)
*
* @return string
*/
protected function getFilename($id)
public function getFilename($id)
{
$path = $this->directory . DIRECTORY_SEPARATOR;
$id = preg_replace('@[\\\/:"*?<>|]+@', '', $id);
Expand Down
19 changes: 19 additions & 0 deletions tests/Backend/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,23 @@ public function test_doSave_shouldSetLifeTime()
$this->assertLessThan(time() + 550, $contents['lifetime']);
}

/**
* @dataProvider getTestDataForGetFilename
*/
public function test_getFilename_shouldConstructFilenameFromId($id, $expectedFilename)
{
$this->assertEquals($expectedFilename, $this->cache->getFilename($id));
}

public function getTestDataForGetFilename()
{
$dir = realpath($this->getPath());

return [
['genericid', $dir . '/genericid.php'],
['id with space', $dir . '/id with space.php'],
['id \/ with :"?_ spe<>cial cha|rs', $dir . '/id with _ special chars.php'],
['with % allowed & special chars', $dir . '/with % allowed & special chars.php'],
];
}
}

0 comments on commit 5d20f42

Please sign in to comment.