diff --git a/common/persistence/class.PhpFileDriver.php b/common/persistence/class.PhpFileDriver.php index 74ac08796..b3218c24e 100755 --- a/common/persistence/class.PhpFileDriver.php +++ b/common/persistence/class.PhpFileDriver.php @@ -202,8 +202,11 @@ private function writeFile($id, $value, $preWriteValueProcessor = null) public function get($id) { $entry = $this->readFile($id); - if ($entry != false && $this->isTtlMode()) { - $entry = (is_null($entry[static::ENTRY_EXPIRATION]) || $entry[static::ENTRY_EXPIRATION] > $this->getTime()) + + if ($entry !== false && $this->isTtlMode()) { + $entry = isset($entry) + && array_key_exists(static::ENTRY_EXPIRATION, $entry) + && (is_null($entry[static::ENTRY_EXPIRATION]) || $entry[static::ENTRY_EXPIRATION] > $this->getTime()) ? $entry[static::ENTRY_VALUE] : false ; @@ -352,7 +355,7 @@ public function purge() } /** - * Map the provided key to a relativ path + * Map the provided key to a relative path * * @param string $key * @return string diff --git a/manifest.php b/manifest.php index 6b0a6547b..0054a3b87 100755 --- a/manifest.php +++ b/manifest.php @@ -31,7 +31,7 @@ 'label' => 'Generis Core', 'description' => 'Core extension, provide the low level framework and an API to manage ontologies', 'license' => 'GPL-2.0', - 'version' => '9.0.2', + 'version' => '9.0.3', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => array(), 'models' => array( diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index 8250689a6..c5f2f253a 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -361,6 +361,6 @@ public function update($initialVersion) $this->setVersion('8.0.0'); } - $this->skip('8.0.0', '9.0.2'); + $this->skip('8.0.0', '9.0.3'); } } diff --git a/test/integration/common/PhpFileDriverTest.php b/test/integration/common/PhpFileDriverTest.php new file mode 100644 index 000000000..ef5084eaf --- /dev/null +++ b/test/integration/common/PhpFileDriverTest.php @@ -0,0 +1,89 @@ + + */ + +namespace oat\generis\test\integration\common; + +use common_persistence_PhpFileDriver; +use PHPUnit_Framework_TestCase; + +class PhpFileDriverTest extends PHPUnit_Framework_TestCase +{ + /** + * @var common_persistence_PhpFileDriver + */ + private $driver; + + protected function setUp() + { + $this->driver = new common_persistence_PhpFileDriver(); + } + + public function testGetFalse() + { + self::assertFalse($this->driver->get(false)); + self::assertFalse($this->driver->get(null)); + self::assertFalse($this->driver->get('')); + self::assertFalse($this->driver->get('not existent')); + } + + public function testGet() + { + $this->driver->connect(false, [ + 'dir' => __DIR__ . '/samples/', + 'humanReadable' => true, + ]); + self::assertEquals('content is here', $this->driver->get('test')); + } + + public function testTtlMode() + { + $this->driver->connect(false, [ + 'dir' => __DIR__ . '/samples/', + 'humanReadable' => true, + 'ttlMode' => true, + ]); + self::assertEquals('Sword', $this->driver->get('testTtl')); + } + + public function ttlFalseDataProvider () + { + return [ + ['testTtlEmpty'], + ['testTtlNull'], + ['testTtlNoExpires'], + ['testTtlExpired'], + ]; + } + + /** + * @dataProvider ttlFalseDataProvider + */ + public function testFalseTtl($id) + { + $this->driver->connect(false, [ + 'dir' => __DIR__ . '/samples/', + 'humanReadable' => true, + 'ttlMode' => true, + ]); + self::assertFalse($this->driver->get($id)); + } + +} diff --git a/test/integration/common/samples/test.php b/test/integration/common/samples/test.php new file mode 100644 index 000000000..59521c87d --- /dev/null +++ b/test/integration/common/samples/test.php @@ -0,0 +1,2 @@ + time() + 1000, + 'value' => 'Sword', + ]; diff --git a/test/integration/common/samples/testTtlEmpty.php b/test/integration/common/samples/testTtlEmpty.php new file mode 100644 index 000000000..9e1f040fd --- /dev/null +++ b/test/integration/common/samples/testTtlEmpty.php @@ -0,0 +1,2 @@ + time() - 1000, + 'value' => 'Sword', + ]; diff --git a/test/integration/common/samples/testTtlNoExpires.php b/test/integration/common/samples/testTtlNoExpires.php new file mode 100644 index 000000000..0f2a0cbf8 --- /dev/null +++ b/test/integration/common/samples/testTtlNoExpires.php @@ -0,0 +1,4 @@ + 'Sword', + ]; diff --git a/test/integration/common/samples/testTtlNull.php b/test/integration/common/samples/testTtlNull.php new file mode 100644 index 000000000..78f5ddf01 --- /dev/null +++ b/test/integration/common/samples/testTtlNull.php @@ -0,0 +1,2 @@ +