Author: Derick Rethans Date: 2006-01-24 16:55:29 +0100 (Tue, 24 Jan 2006) New Revision: 2015
Log: - Create TranslationCacheTiein package by splitting out the ezcTranslationCacheBackend from the Translation component. Added: packages/TranslationCacheTiein/ packages/TranslationCacheTiein/trunk/ packages/TranslationCacheTiein/trunk/CREDITS packages/TranslationCacheTiein/trunk/ChangeLog packages/TranslationCacheTiein/trunk/DEPS packages/TranslationCacheTiein/trunk/DESCRIPTION packages/TranslationCacheTiein/trunk/docs/ packages/TranslationCacheTiein/trunk/src/ packages/TranslationCacheTiein/trunk/src/backends/ packages/TranslationCacheTiein/trunk/src/backends/cache_backend.php packages/TranslationCacheTiein/trunk/src/translation_cache_autoload.php packages/TranslationCacheTiein/trunk/tests/ packages/TranslationCacheTiein/trunk/tests/suite.php packages/TranslationCacheTiein/trunk/tests/translation_backend_cache_test.php Removed: packages/Translation/trunk/src/backends/cache_backend.php packages/Translation/trunk/src/translation_cache_autoload.php packages/Translation/trunk/tests/translation_backend_cache_test.php Modified: packages/Translation/trunk/ChangeLog packages/Translation/trunk/tests/suite.php Modified: packages/Translation/trunk/ChangeLog =================================================================== --- packages/Translation/trunk/ChangeLog 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/Translation/trunk/ChangeLog 2006-01-24 15:55:29 UTC (rev 2015) @@ -1,3 +1,9 @@ +1.0 - [RELEASEDATE] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Moved ezcTranslationCacheBackend to the TranslationCacheTiein component. + + 1.0rc1 - Monday 16 January 2006 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Deleted: packages/Translation/trunk/src/backends/cache_backend.php =================================================================== --- packages/Translation/trunk/src/backends/cache_backend.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/Translation/trunk/src/backends/cache_backend.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -1,215 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package TranslationCacheTiein - */ - -/** - * Translation backend that reads translation data from a cache. - * - * This class is a backend implementation for the Translation system. This - * specific one uses the Cache Component to store and serve cached translation - * data. - * - * Example that uses both the [EMAIL PROTECTED] ezcCacheStorageFileArray} and [EMAIL PROTECTED] - * ezcTranslationCacheBackend} classes: - * <code> - * <?php - * // Create a cache object with content - * $cacheObj = new ezcCacheStorageFileArray( 'ezcTranslationCacheBackendTest' ) ); - * - * $expected = array( - * new ezcTranslationData( 'Node ID: %node_id Visibility: %visibility', - * 'Knoop ID: %node_id Zichtbaar: %visibility', - * false, ezcTranslationData::TRANSLATED ) - * ); - * $cacheObj->store( 'nl-nl/contentstructuremenu/show_content_structure', $expected ); - * - * // Use the cache backend - * $backend = new ezcTranslationCacheBackend( $cacheObj ); - * $context = $backend->getContext( 'nl-nl', 'contentstructuremenu/show_content_structure' ); - * $translation = new ezcTranslation( $context ); - * echo $translation->getTranslation( 'Node ID: %node_id Visibility: %visibility', - * array( 'node_id' => 42, 'visibility' => 'yes' ) ); - * ?> - * </code> - * - * Example that stores a whole translation file into a cache by using [EMAIL PROTECTED] - * ezcTranslationContextRead} interface that is implemented by the [EMAIL PROTECTED] - * ezcTranslationTsBackend} and the [EMAIL PROTECTED] ezcTranslationContextWrite} - * interface that is implemented by this class: - * <code> - * <?php - * // Settings - * $locale = 'nb-no'; - * - * // Setup the cache object - * $cacheObj = new ezcCacheStorageFileArray( 'ezcTranslationCacheBackendTest' ); - * - * // Initialize the writer - * $writer = new ezcTranslationCacheBackend( $cacheObj ); - * $writer->initWriter( $locale ); - * - * // Initialize the reader - * $reader = new ezcTranslationTsBackend( "translations" ); - * $reader->setOptions( array ( 'format' => '[LOCALE].xml' ) ); - * $reader->initReader( $locale ); - * - * // Process the data - * $contexts = array(); - * foreach ( $reader as $contextName => $contextData ) - * { - * $cacheObj->store( "{$locale}/{$contextName}", $contextData ); - * } - * - * // Deinitialize the writer and reader - * $writer->deinitWriter(); - * $reader->deinitReader(); - * ?> - * </code> - * - * @package TranslationCacheTiein - */ -class ezcTranslationCacheBackend implements ezcTranslationBackend, ezcTranslationContextWrite -{ - /** - * Stores the cache object to use for storing and fetching. - * - * @var ezcCacheStorageFileArray - */ - private $cache; - - /** - * The locale to write to. - * - * @var string - */ - private $writeLocale; - - /** - * Constructs a new ezcTranslationCacheBackend that will store data to $cacheObject. - * - * @param ezcCacheStorageFileArray $cacheObject - */ - public function __construct( ezcCacheStorageFileArray $cacheObject ) - { - $this->cache = $cacheObject; - } - - /** - * Sets configuration data - * - * This backend accepts no settings at all, and will always throw an - * ezcBaseConfigException if this setOptions() method is called. - * - * @param array $configurationData - * @throws ezcBaseSettingNotFoundException if an unknown setting is passed. - * @return void - */ - public function setOptions( array $configurationData ) - { - foreach ( $configurationData as $name => $value ) - { - switch ( $name ) - { - default: - throw new ezcBaseSettingNotFoundException( $name ); - } - } - } - /** - * Returns a array containing the translation map for the specified - * $locale and $context. - * - * It uses the $tsLocationPath and - * $tsFilenameFormat properties to locate the file, unless caching is - * enabled. If a cache object is available it will be used to retrieve the - * information from the cache. - * - * @throws ezcTranslationContextNotAvailableException if the context is not available. - * @param $locale string - * @param $context string - * @return array(ezcTranslationData) - */ - public function getContext( $locale, $context ) - { - $cachedContext = $this->cache->restore( "$locale/$context" ); - if ( $cachedContext === false ) - { - throw new ezcTranslationContextNotAvailableException( $context ); - } - foreach ( $cachedContext as $key => $cachedElement ) - { - if ( $cachedElement->status == ezcTranslationData::OBSOLETE ) - { - unset( $cachedContext[$key] ); - } - } - return $cachedContext; - } - - /** - * Initializes the writer to write to the locale $locale. - * - * Before starting to writer contexts to the writer, you should call - * this method to initialize it. - * - * @param string $locale - * $return void - */ - public function initWriter( $locale ) - { - $this->writeLocale = $locale; - } - - /** - * Deinitializes the writer. - * - * This method should be called after the last context was written to - * cleanup resources. - * - * @throws ezcTranslationWriterNotInitializedException when the writer is - * not initialized with initWriter(). - * @return void - */ - public function deinitWriter() - { - if ( is_null( $this->writeLocale ) ) - { - throw new ezcTranslationWriterNotInitializedException(); - } - $this->writeLocale = null; - } - - /** - * 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 $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 ); - } -} -?> Deleted: packages/Translation/trunk/src/translation_cache_autoload.php =================================================================== --- packages/Translation/trunk/src/translation_cache_autoload.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/Translation/trunk/src/translation_cache_autoload.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -1,15 +0,0 @@ -<?php -/** - * Autoloader definition for the TranslationCacheTiein component. - * - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package TranslationCacheTiein - */ - -return array( - 'ezcTranslationCacheBackend' => 'Translation/backends/cache_backend.php', -); -?> Modified: packages/Translation/trunk/tests/suite.php =================================================================== --- packages/Translation/trunk/tests/suite.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/Translation/trunk/tests/suite.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -13,7 +13,6 @@ */ require_once 'translation_test.php'; require_once 'translation_backend_ts_test.php'; -require_once 'translation_backend_cache_test.php'; require_once 'translation_filter_borkify_test.php'; require_once 'translation_filter_leetify_test.php'; require_once 'translation_manager_test.php'; @@ -31,7 +30,6 @@ $this->addTest( ezcTranslationTest::suite() ); $this->addTest( ezcTranslationTsBackendTest::suite() ); - $this->addTest( ezcTranslationCacheBackendTest::suite() ); $this->addTest( ezcTranslationManagerTest::suite() ); $this->addTest( ezcTranslationFilterBorkifyTest::suite() ); $this->addTest( ezcTranslationFilterLeetifyTest::suite() ); Deleted: packages/Translation/trunk/tests/translation_backend_cache_test.php =================================================================== --- packages/Translation/trunk/tests/translation_backend_cache_test.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/Translation/trunk/tests/translation_backend_cache_test.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -1,169 +0,0 @@ -<?php -/** - * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @version //autogentag// - * @filesource - * @package TranslationCacheTiein - * @subpackage Tests - */ - -/** - * @package TranslationCacheTiein - * @subpackage Tests - */ -class ezcTranslationCacheBackendTest extends ezcTestCase -{ - private $cacheObj; - - public function setUp() - { - $this->cacheObj = new ezcCacheStorageFileArray( $this->createTempDir( 'ezcTranslationCacheBackendTest' ) ); - - $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 ( ezcBaseSettingNotFoundException $e ) - { - self::assertEquals( "The setting <lOcAtIOn> is not a valid configuration setting.", $e->getMessage() ); - } - } - - 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 ( ezcTranslationContextNotAvailableException $e ) - { - self::assertEquals( "The context <does/not/exist> does not exist.", $e->getMessage() ); - } - } - - /** - * 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 ( ezcTranslationWriterNotInitializedException $e ) - { - self::assertEquals( "The writer is not initialized with the initWriter() method.", $e->getMessage() ); - } - } - - public function testNonInitException2() - { - $currentDir = dirname( __FILE__ ); - $backend = new ezcTranslationCacheBackend( $this->cacheObj ); - - try - { - $backend->deinitWriter(); - } - catch ( ezcTranslationWriterNotInitializedException $e ) - { - self::assertEquals( "The writer is not initialized with the initWriter() method.", $e->getMessage() ); - } - } - - public static function suite() - { - return new ezcTestSuite( "ezcTranslationCacheBackendTest" ); - } -} - -?> Added: packages/TranslationCacheTiein/trunk/CREDITS =================================================================== --- packages/TranslationCacheTiein/trunk/CREDITS 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/CREDITS 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,11 @@ +CREDITS +======= + +eZ components team: +------------------- +Jan Borsodi +Raymond Bosman +Frederik Holljen +Derick Rethans +Vadym Savchuk +Tobias Schlitt Added: packages/TranslationCacheTiein/trunk/ChangeLog =================================================================== --- packages/TranslationCacheTiein/trunk/ChangeLog 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/ChangeLog 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,4 @@ +1.0 - [RELEASEDATE] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +- Initial release of this package, split from Translation component. Added: packages/TranslationCacheTiein/trunk/DEPS =================================================================== --- packages/TranslationCacheTiein/trunk/DEPS 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/DEPS 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,2 @@ +Translation: 1.0 +Cache: 1.0 Added: packages/TranslationCacheTiein/trunk/DESCRIPTION =================================================================== --- packages/TranslationCacheTiein/trunk/DESCRIPTION 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/DESCRIPTION 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,4 @@ +A component that reads XML translation definitions (the Qt Linguist format), +supports caching of translation contexts and presents you with a class to apply +translations to strings. A filter system allows you to transform translation +definitions for special use. Added: packages/TranslationCacheTiein/trunk/src/backends/cache_backend.php =================================================================== --- packages/TranslationCacheTiein/trunk/src/backends/cache_backend.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/src/backends/cache_backend.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,215 @@ +<?php +/** + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package TranslationCacheTiein + */ + +/** + * Translation backend that reads translation data from a cache. + * + * This class is a backend implementation for the Translation system. This + * specific one uses the Cache Component to store and serve cached translation + * data. + * + * Example that uses both the [EMAIL PROTECTED] ezcCacheStorageFileArray} and [EMAIL PROTECTED] + * ezcTranslationCacheBackend} classes: + * <code> + * <?php + * // Create a cache object with content + * $cacheObj = new ezcCacheStorageFileArray( 'ezcTranslationCacheBackendTest' ) ); + * + * $expected = array( + * new ezcTranslationData( 'Node ID: %node_id Visibility: %visibility', + * 'Knoop ID: %node_id Zichtbaar: %visibility', + * false, ezcTranslationData::TRANSLATED ) + * ); + * $cacheObj->store( 'nl-nl/contentstructuremenu/show_content_structure', $expected ); + * + * // Use the cache backend + * $backend = new ezcTranslationCacheBackend( $cacheObj ); + * $context = $backend->getContext( 'nl-nl', 'contentstructuremenu/show_content_structure' ); + * $translation = new ezcTranslation( $context ); + * echo $translation->getTranslation( 'Node ID: %node_id Visibility: %visibility', + * array( 'node_id' => 42, 'visibility' => 'yes' ) ); + * ?> + * </code> + * + * Example that stores a whole translation file into a cache by using [EMAIL PROTECTED] + * ezcTranslationContextRead} interface that is implemented by the [EMAIL PROTECTED] + * ezcTranslationTsBackend} and the [EMAIL PROTECTED] ezcTranslationContextWrite} + * interface that is implemented by this class: + * <code> + * <?php + * // Settings + * $locale = 'nb-no'; + * + * // Setup the cache object + * $cacheObj = new ezcCacheStorageFileArray( 'ezcTranslationCacheBackendTest' ); + * + * // Initialize the writer + * $writer = new ezcTranslationCacheBackend( $cacheObj ); + * $writer->initWriter( $locale ); + * + * // Initialize the reader + * $reader = new ezcTranslationTsBackend( "translations" ); + * $reader->setOptions( array ( 'format' => '[LOCALE].xml' ) ); + * $reader->initReader( $locale ); + * + * // Process the data + * $contexts = array(); + * foreach ( $reader as $contextName => $contextData ) + * { + * $cacheObj->store( "{$locale}/{$contextName}", $contextData ); + * } + * + * // Deinitialize the writer and reader + * $writer->deinitWriter(); + * $reader->deinitReader(); + * ?> + * </code> + * + * @package TranslationCacheTiein + */ +class ezcTranslationCacheBackend implements ezcTranslationBackend, ezcTranslationContextWrite +{ + /** + * Stores the cache object to use for storing and fetching. + * + * @var ezcCacheStorageFileArray + */ + private $cache; + + /** + * The locale to write to. + * + * @var string + */ + private $writeLocale; + + /** + * Constructs a new ezcTranslationCacheBackend that will store data to $cacheObject. + * + * @param ezcCacheStorageFileArray $cacheObject + */ + public function __construct( ezcCacheStorageFileArray $cacheObject ) + { + $this->cache = $cacheObject; + } + + /** + * Sets configuration data + * + * This backend accepts no settings at all, and will always throw an + * ezcBaseConfigException if this setOptions() method is called. + * + * @param array $configurationData + * @throws ezcBaseSettingNotFoundException if an unknown setting is passed. + * @return void + */ + public function setOptions( array $configurationData ) + { + foreach ( $configurationData as $name => $value ) + { + switch ( $name ) + { + default: + throw new ezcBaseSettingNotFoundException( $name ); + } + } + } + /** + * Returns a array containing the translation map for the specified + * $locale and $context. + * + * It uses the $tsLocationPath and + * $tsFilenameFormat properties to locate the file, unless caching is + * enabled. If a cache object is available it will be used to retrieve the + * information from the cache. + * + * @throws ezcTranslationContextNotAvailableException if the context is not available. + * @param $locale string + * @param $context string + * @return array(ezcTranslationData) + */ + public function getContext( $locale, $context ) + { + $cachedContext = $this->cache->restore( "$locale/$context" ); + if ( $cachedContext === false ) + { + throw new ezcTranslationContextNotAvailableException( $context ); + } + foreach ( $cachedContext as $key => $cachedElement ) + { + if ( $cachedElement->status == ezcTranslationData::OBSOLETE ) + { + unset( $cachedContext[$key] ); + } + } + return $cachedContext; + } + + /** + * Initializes the writer to write to the locale $locale. + * + * Before starting to writer contexts to the writer, you should call + * this method to initialize it. + * + * @param string $locale + * $return void + */ + public function initWriter( $locale ) + { + $this->writeLocale = $locale; + } + + /** + * Deinitializes the writer. + * + * This method should be called after the last context was written to + * cleanup resources. + * + * @throws ezcTranslationWriterNotInitializedException when the writer is + * not initialized with initWriter(). + * @return void + */ + public function deinitWriter() + { + if ( is_null( $this->writeLocale ) ) + { + throw new ezcTranslationWriterNotInitializedException(); + } + $this->writeLocale = null; + } + + /** + * 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 $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 ); + } +} +?> Property changes on: packages/TranslationCacheTiein/trunk/src/backends/cache_backend.php ___________________________________________________________________ Name: svn:eol-style + native Added: packages/TranslationCacheTiein/trunk/src/translation_cache_autoload.php =================================================================== --- packages/TranslationCacheTiein/trunk/src/translation_cache_autoload.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/src/translation_cache_autoload.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,15 @@ +<?php +/** + * Autoloader definition for the TranslationCacheTiein component. + * + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package TranslationCacheTiein + */ + +return array( + 'ezcTranslationCacheBackend' => 'TranslationCacheTiein/backends/cache_backend.php', +); +?> Property changes on: packages/TranslationCacheTiein/trunk/src/translation_cache_autoload.php ___________________________________________________________________ Name: svn:eol-style + native Added: packages/TranslationCacheTiein/trunk/tests/suite.php =================================================================== --- packages/TranslationCacheTiein/trunk/tests/suite.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/tests/suite.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,36 @@ +<?php +/** + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package Translation + * @subpackage Tests + */ + +/** + * Require the tests + */ +require_once 'translation_backend_cache_test.php'; + +/** + * @package Translation + * @subpackage Tests + */ +class ezcTranslationCacheTieinSuite extends ezcTestSuite +{ + public function __construct() + { + parent::__construct(); + $this->setName("TranslationCacheTiein"); + + $this->addTest( ezcTranslationCacheBackendTest::suite() ); + } + + public static function suite() + { + return new ezcTranslationCacheTieinSuite(); + } +} + +?> Property changes on: packages/TranslationCacheTiein/trunk/tests/suite.php ___________________________________________________________________ Name: svn:eol-style + native Added: packages/TranslationCacheTiein/trunk/tests/translation_backend_cache_test.php =================================================================== --- packages/TranslationCacheTiein/trunk/tests/translation_backend_cache_test.php 2006-01-24 15:41:20 UTC (rev 2014) +++ packages/TranslationCacheTiein/trunk/tests/translation_backend_cache_test.php 2006-01-24 15:55:29 UTC (rev 2015) @@ -0,0 +1,169 @@ +<?php +/** + * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved. + * @license http://ez.no/licenses/new_bsd New BSD License + * @version //autogentag// + * @filesource + * @package TranslationCacheTiein + * @subpackage Tests + */ + +/** + * @package TranslationCacheTiein + * @subpackage Tests + */ +class ezcTranslationCacheBackendTest extends ezcTestCase +{ + private $cacheObj; + + public function setUp() + { + $this->cacheObj = new ezcCacheStorageFileArray( $this->createTempDir( 'ezcTranslationCacheBackendTest' ) ); + + $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 ( ezcBaseSettingNotFoundException $e ) + { + self::assertEquals( "The setting <lOcAtIOn> is not a valid configuration setting.", $e->getMessage() ); + } + } + + 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 ( ezcTranslationContextNotAvailableException $e ) + { + self::assertEquals( "The context <does/not/exist> does not exist.", $e->getMessage() ); + } + } + + /** + * 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 ( ezcTranslationWriterNotInitializedException $e ) + { + self::assertEquals( "The writer is not initialized with the initWriter() method.", $e->getMessage() ); + } + } + + public function testNonInitException2() + { + $currentDir = dirname( __FILE__ ); + $backend = new ezcTranslationCacheBackend( $this->cacheObj ); + + try + { + $backend->deinitWriter(); + } + catch ( ezcTranslationWriterNotInitializedException $e ) + { + self::assertEquals( "The writer is not initialized with the initWriter() method.", $e->getMessage() ); + } + } + + public static function suite() + { + return new ezcTestSuite( "ezcTranslationCacheBackendTest" ); + } +} + +?> Property changes on: packages/TranslationCacheTiein/trunk/tests/translation_backend_cache_test.php ___________________________________________________________________ Name: svn:eol-style + native -- svn-components mailing list [email protected] http://lists.ez.no/mailman/listinfo/svn-components
