cacheObj = new ezcCacheStorageFileArray( $this->createTempDir( 'ezcTranslationBackendCacheTest' ) ); $expected = array( new ezcTranslationData( 'Node ID: %node_id Visibility: %visibility', 'Knoop ID: %node_id Zichtbaar: %visibility', false, ezcTranslationData::TRANSLATED ) ); $this->cacheObj->store( 'nl-nl/contentstructuremenu/show_content_structure', $expected ); $expected = array(); $expected[] = new ezcTranslationData( 'Approval', 'Goedkeuring', false, ezcTranslationData::UNFINISHED ); $expected[] = new ezcTranslationData( 'Approvals', false, false, ezcTranslationData::UNFINISHED ); $this->cacheObj->store( 'nl-nl/design/admin/collaboration', $expected ); $expected = array(); $expected[] = new ezcTranslationData( 'Groups', 'Groepen', false, ezcTranslationData::OBSOLETE ); $this->cacheObj->store( 'nl-nl/design/admin/collaboration/group_tree', $expected ); } public function tearDown() { $this->removeTempDir(); } /* * There are no configuration options yet, so comment this test out for now. public function testConfigSetting() { $backend = new ezcTranslationCacheBackend( $this->cacheObj ); $backend->setOptions( array ( 'location' => 'tests/translations', 'format' => '[LOCALE].xml' ) ); } */ public function testConfigSettingBroken() { $backend = new ezcTranslationCacheBackend( $this->cacheObj ); try { $backend->setOptions( array ( 'lOcAtIOn' => 'tests/translations' ) ); } catch ( ezcBaseConfigException $e ) { self::assertEquals( ezcBaseConfigException::UNKNOWN_CONFIG_SETTING, $e->getCode() ); } } public function testGetContext1() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); $context = $backend->getContext( 'nl-nl', 'contentstructuremenu/show_content_structure' ); $expected = array( new ezcTranslationData( 'Node ID: %node_id Visibility: %visibility', 'Knoop ID: %node_id Zichtbaar: %visibility', false, ezcTranslationData::TRANSLATED ) ); self::assertEquals( $expected, $context ); } public function testGetContextUnfinishedData() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); $context = $backend->getContext( 'nl-nl', 'design/admin/collaboration' ); $expected = array(); $expected[] = new ezcTranslationData( 'Approval', 'Goedkeuring', false, ezcTranslationData::UNFINISHED ); $expected[] = new ezcTranslationData( 'Approvals', false, false, ezcTranslationData::UNFINISHED ); self::assertEquals( $expected, $context ); } public function testGetContextObsolete() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); $context = $backend->getContext( 'nl-nl', 'design/admin/collaboration/group_tree' ); $expected = array(); self::assertEquals( $expected, $context ); } public function testGetMissingContext() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); try { $context = $backend->getContext( 'nl-nl', 'does/not/exist' ); } catch ( ezcTranslationException $e ) { self::assertEquals( ezcTranslationException::CONTEXT_NOT_AVAILABLE, $e->getCode() ); } } /** * Writer tests */ public function testWriter1() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); $backend->initWriter( 'nb-no' ); $contextName = 'contentstructuremenu/show_content_structure'; $contextData = array( new ezcTranslationData( 'Node ID: %node_id Visibility: %visibility', 'Node-ID: %node_id Synlig/skjult: %visibility', false, ezcTranslationData::TRANSLATED ), new ezcTranslationData( 'Approvals', false, false, ezcTranslationData::UNFINISHED ), new ezcTranslationData( 'Groups', 'Groepen', false, ezcTranslationData::OBSOLETE ), ); $backend->storeContext( $contextName, $contextData ); /* Unsetting element 2, as that should not be in the returned context */ unset( $contextData[2] ); $storedContext = $backend->getContext( 'nb-no', $contextName ); self::assertEquals( $contextData, $storedContext ); } public function testNonInitException1() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); try { $backend->storeContext( 'dummy', array() ); } catch ( ezcTranslationException $e ) { self::assertEquals( ezcTranslationException::WRITER_NOT_INITIALIZED, $e->getCode() ); } } public function testNonInitException2() { $currentDir = dirname( __FILE__ ); $backend = new ezcTranslationCacheBackend( $this->cacheObj ); try { $backend->deinitWriter(); } catch ( ezcTranslationException $e ) { self::assertEquals( ezcTranslationException::WRITER_NOT_INITIALIZED, $e->getCode() ); } } public static function suite() { return new ezcTestSuite( "ezcTranslationBackendCacheTest" ); } } ?>