示例#1
0
 /**
  * Stores a context.
  *
  * This method stores the context that it received to the backend specified
  * storage place.
  *
  * @throws ezcTranslationWriterNotInitializedException when the writer is
  *         not initialized with initWriter().
  * @param string $context The context's name
  * @param array(ezcTranslationData)  $data The context's translation map
  * @return void
  */
 public function storeContext($context, array $data)
 {
     if (is_null($this->writeLocale)) {
         throw new ezcTranslationWriterNotInitializedException();
     }
     foreach ($data as $key => $cachedElement) {
         if ($cachedElement->status == ezcTranslationData::OBSOLETE) {
             unset($data[$key]);
         }
     }
     $cachedContext = $this->cache->store("{$this->writeLocale}/{$context}", $data);
 }
 public function testOptions()
 {
     $obj = new ezcCacheStorageFileArray($this->createTempDir(__CLASS__));
     $options = new ezcCacheStorageFileOptions();
     $optionsGeneral = new ezcCacheStorageOptions();
     $this->assertEquals($options, $obj->getOptions());
     $obj->options = $optionsGeneral;
     $this->assertEquals($options, $obj->getOptions());
     $obj->options = $options;
     $this->assertEquals($options, $obj->getOptions());
     $obj->setOptions($optionsGeneral);
     $this->assertEquals($options, $obj->getOptions());
     $obj->setOptions($options);
     $this->assertEquals($options, $obj->getOptions());
     try {
         $obj->setOptions('wrong value');
         $this->fail("Expected exception was not thrown.");
     } catch (ezcBaseValueException $e) {
         $this->assertEquals("The value 'wrong value' that you were trying to assign to " . "setting 'options' is invalid. Allowed values are: " . "instance of ezcCacheStorageFileOptions or (deprecated) " . "ezcCacheStorageOptions.", $e->getMessage());
     }
 }
 public function testMetaDataFailure()
 {
     $temp = $this->createTempDir(__CLASS__);
     $storage = new ezcCacheStorageFileArray($temp);
     $this->assertFalse(file_exists($storage->getLocation() . $storage->options->metaDataFile), 'Meta data file existed before the storage was created.');
     $restoredMeta = $storage->restoreMetaData();
     $this->assertNull($restoredMeta, 'Meta data not restored correctly.');
     $this->assertFalse(file_exists($storage->getLocation() . $storage->options->metaDataFile), 'Meta data file existed before the storage was created.');
     $this->removeTempDir();
 }