public function test() { // XXX SimpleTest does some really crazy stuff in the background // to do equality checks. Unfortunately, this makes some // versions of PHP segfault. So we need to define a better, // homebrew notion of equality and use that instead. For now, // the identical asserts are commented out. $cache = new HTMLPurifier_DefinitionCache_Serializer('Test'); $config = $this->generateConfigMock('serial'); $config->setReturnValue('get', 2, array('Test.DefinitionRev')); $config->version = '1.0.0'; $config_md5 = '1.0.0,serial,2'; $file = realpath($rel_file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer/Test/' . $config_md5 . '.ser'); if ($file && file_exists($file)) { unlink($file); } // prevent previous failures from causing problems $this->assertIdentical($config_md5, $cache->generateKey($config)); $def_original = $this->generateDefinition(); $cache->add($def_original, $config); $this->assertFileExist($rel_file); $file_generated = $cache->generateFilePath($config); $this->assertIdentical(realpath($rel_file), realpath($file_generated)); $def_1 = $cache->get($config); // $this->assertIdentical($def_original, $def_1); $def_original->info_random = 'changed'; $cache->set($def_original, $config); $def_2 = $cache->get($config); // $this->assertIdentical($def_original, $def_2); // $this->assertNotEqual ($def_original, $def_1); $def_original->info_random = 'did it change?'; $this->assertFalse($cache->add($def_original, $config)); $def_3 = $cache->get($config); // $this->assertNotEqual ($def_original, $def_3); // did not change! // $this->assertIdentical($def_3, $def_2); $cache->replace($def_original, $config); $def_4 = $cache->get($config); // $this->assertIdentical($def_original, $def_4); $cache->remove($config); $this->assertFileNotExist($file); $this->assertFalse($cache->replace($def_original, $config)); $def_5 = $cache->get($config); $this->assertFalse($def_5); }
function test() { $cache = new HTMLPurifier_DefinitionCache_Serializer('Test'); $config = $this->generateConfigMock('serial'); $config->setReturnValue('get', 2, array('Test', 'DefinitionRev')); $config->version = '1.0.0'; $config_md5 = '1.0.0,serial,2'; $file = realpath($rel_file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer/Test/' . $config_md5 . '.ser'); if ($file && file_exists($file)) { unlink($file); } // prevent previous failures from causing problems $this->assertIdentical($config_md5, $cache->generateKey($config)); $def_original = $this->generateDefinition(); $cache->add($def_original, $config); $this->assertFileExist($rel_file); $file_generated = $cache->generateFilePath($config); $this->assertIdentical(realpath($rel_file), realpath($file_generated)); $def_1 = $cache->get($config); $this->assertIdentical($def_original, $def_1); $def_original->info_random = 'changed'; $cache->set($def_original, $config); $def_2 = $cache->get($config); $this->assertIdentical($def_original, $def_2); $this->assertNotEqual($def_original, $def_1); $def_original->info_random = 'did it change?'; $this->assertFalse($cache->add($def_original, $config)); $def_3 = $cache->get($config); $this->assertNotEqual($def_original, $def_3); // did not change! $this->assertIdentical($def_3, $def_2); $cache->replace($def_original, $config); $def_4 = $cache->get($config); $this->assertIdentical($def_original, $def_4); $cache->remove($config); $this->assertFileNotExist($file); $this->assertFalse($cache->replace($def_original, $config)); $def_5 = $cache->get($config); $this->assertFalse($def_5); }