Author: dr
Date: Wed Jan 30 16:39:36 2008
New Revision: 7263

Log:
- Implemented issue #9973: Added a translation compiler to convert a string in
  the original language, to the translated one without substituting parameters.
  This is to have translation support for the Template component.

Added:
    trunk/TemplateTranslationTiein/
    trunk/TemplateTranslationTiein/CREDITS
    trunk/TemplateTranslationTiein/ChangeLog
    trunk/TemplateTranslationTiein/DEPS
    trunk/TemplateTranslationTiein/DESCRIPTION
    trunk/TemplateTranslationTiein/design/
    trunk/TemplateTranslationTiein/design/class_diagram.png   (with props)
    trunk/TemplateTranslationTiein/docs/
    trunk/TemplateTranslationTiein/src/
    trunk/TemplateTranslationTiein/src/configuration.php   (with props)
    trunk/TemplateTranslationTiein/src/exceptions/
    trunk/TemplateTranslationTiein/src/exceptions/exception.php   (with props)
    trunk/TemplateTranslationTiein/src/exceptions/manager_not_configured.php   
(with props)
    trunk/TemplateTranslationTiein/src/provider.php   (with props)
    trunk/TemplateTranslationTiein/src/template_translation_autoload.php   
(with props)
    trunk/TemplateTranslationTiein/tests/
    trunk/TemplateTranslationTiein/tests/configuration.php   (with props)
    trunk/TemplateTranslationTiein/tests/provider.php   (with props)
    trunk/TemplateTranslationTiein/tests/suite.php   (with props)
    trunk/TemplateTranslationTiein/tests/translations/
    trunk/TemplateTranslationTiein/tests/translations/test.xml

Added: trunk/TemplateTranslationTiein/CREDITS
==============================================================================
--- trunk/TemplateTranslationTiein/CREDITS (added)
+++ trunk/TemplateTranslationTiein/CREDITS [iso-8859-1] Wed Jan 30 16:39:36 2008
@@ -1,0 +1,11 @@
+CREDITS
+=======
+
+eZ Components team
+------------------
+
+- Sebastian Bergmann
+- Kore Nordmann
+- Derick Rethans
+- Tobias Schlitt
+- Alexandru Stanoi

Added: trunk/TemplateTranslationTiein/ChangeLog
==============================================================================
--- trunk/TemplateTranslationTiein/ChangeLog (added)
+++ trunk/TemplateTranslationTiein/ChangeLog [iso-8859-1] Wed Jan 30 16:39:36 
2008
@@ -1,0 +1,4 @@
+1.0alpha1 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Initial release of this package.

Added: trunk/TemplateTranslationTiein/DEPS
==============================================================================
--- trunk/TemplateTranslationTiein/DEPS (added)
+++ trunk/TemplateTranslationTiein/DEPS [iso-8859-1] Wed Jan 30 16:39:36 2008
@@ -1,0 +1,2 @@
+Template: 1.3alpha1
+Translation: 1.2alpha1

Added: trunk/TemplateTranslationTiein/DESCRIPTION
==============================================================================
--- trunk/TemplateTranslationTiein/DESCRIPTION (added)
+++ trunk/TemplateTranslationTiein/DESCRIPTION [iso-8859-1] Wed Jan 30 16:39:36 
2008
@@ -1,0 +1,1 @@
+Provides functionality to use translations inside templates.

Added: trunk/TemplateTranslationTiein/design/class_diagram.png
==============================================================================
Binary file - no diff available.

Propchange: trunk/TemplateTranslationTiein/design/class_diagram.png
------------------------------------------------------------------------------
    svn:mime-type = image/png

Added: trunk/TemplateTranslationTiein/src/configuration.php
==============================================================================
--- trunk/TemplateTranslationTiein/src/configuration.php (added)
+++ trunk/TemplateTranslationTiein/src/configuration.php [iso-8859-1] Wed Jan 
30 16:39:36 2008
@@ -1,0 +1,137 @@
+<?php
+/**
+ * File containing the ezcTemplateTranslationConfiguration class
+ *
+ * @package TemplateTranslationTiein
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * ezcTemplateTranslationConfiguration provides an environment for 
translations in templates.
+ *
+ * @package TemplateTranslationTiein
+ * @mainclass
+ * @version //autogen//
+ */
+class ezcTemplateTranslationConfiguration
+{
+    /**
+     * @param ezcTemplateTranslationConfiguration Instance
+     */
+    static private $instance = null;
+
+    /**
+     * Holds the properties of this class.
+     *
+     * @var array(string=>mixed)
+     */
+    private $properties = array();
+
+    /**
+     * Private constructor to prevent non-singleton use
+     */
+    private function __construct()
+    {
+        $this->properties = array( 'locale' => null, 'manager' => null );
+    }
+
+    /**
+     * Returns an instance of the class ezcTemplateTranslationConfiguration
+     *
+     * @return ezcTemplateTranslationConfiguration Instance of 
ezcTemplateTranslationConfiguration
+     */
+    public static function getInstance()
+    {
+        if ( is_null( self::$instance ) )
+        {
+            self::$instance = new ezcTemplateTranslationConfiguration();
+        }
+        return self::$instance;
+    }
+
+    /**
+     * Sets the property $name to $value.
+     *
+     * @throws ezcBasePropertyNotFoundException if the property does not exist.
+     * @throws ezcBaseValueException if a the value for a property is out of
+     *         range.
+     * @param string $name
+     * @param mixed $value
+     * @ignore
+     */
+    public function __set( $name, $value )
+    {
+        switch ( $name )
+        {
+            case 'locale':
+                if ( !is_string( $value ) )
+                {
+                    throw new ezcBaseValueException( $name, $value, 'string' );
+                }
+                break;
+
+            case 'manager':
+                if ( (!$value instanceof ezcTranslationManager) && $value !== 
null )
+                {
+                    throw new ezcBaseValueException( $name, $value, 'instance 
of ezcTranslationManager or null' );
+                }
+                break;
+
+            default:
+                throw new ezcBasePropertyNotFoundException( $name );
+        }
+        $this->properties[$name] = $value;
+    }
+
+    /**
+     * Returns the value of the property $name.
+     *
+     * @throws ezcBasePropertyNotFoundException if the property does not exist.
+     * @param string $name
+     * @ignore
+     */
+    public function __get( $name )
+    {
+        switch ( $name )
+        {
+            case 'locale':
+                return $this->properties[$name];
+
+            case 'manager':
+                if ( $this->properties[$name] === null )
+                {
+                    ezcBaseInit::fetchConfig( 
'ezcInitTemplateTranslationManager', $this );
+                }
+                if ( $this->properties[$name] === null )
+                {
+                    throw new 
ezcTemplateTranslationManagerNotConfiguredException();
+                }
+                return $this->properties[$name];
+        }
+        throw new ezcBasePropertyNotFoundException( $name );
+    }
+
+    /**
+     * Returns true if the property $name is set, otherwise false.
+     *
+     * @param string $name
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $name )
+    {
+        switch ( $name )
+        {
+            case 'locale':
+            case 'manager':
+                return isset( $this->properties[$name] );
+
+            default:
+                return false;
+        }
+        // if there is no default case before:
+        return parent::__isset( $name );
+    }
+}

Propchange: trunk/TemplateTranslationTiein/src/configuration.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/src/exceptions/exception.php
==============================================================================
--- trunk/TemplateTranslationTiein/src/exceptions/exception.php (added)
+++ trunk/TemplateTranslationTiein/src/exceptions/exception.php [iso-8859-1] 
Wed Jan 30 16:39:36 2008
@@ -1,0 +1,19 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package TemplateTranslationTiein
+ */
+
+/**
+ * The general exception class as used by the TemplateTranslationTiein classes.
+ *
+ * @package TemplateTranslationTiein
+ * @version //autogentag//
+ */
+abstract class ezcTemplateTranslationTieinException extends ezcBaseException
+{
+}
+?>

Propchange: trunk/TemplateTranslationTiein/src/exceptions/exception.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/src/exceptions/manager_not_configured.php
==============================================================================
--- trunk/TemplateTranslationTiein/src/exceptions/manager_not_configured.php 
(added)
+++ trunk/TemplateTranslationTiein/src/exceptions/manager_not_configured.php 
[iso-8859-1] Wed Jan 30 16:39:36 2008
@@ -1,0 +1,28 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package TemplateTranslationTiein
+ */
+
+/**
+ * Thrown when a required configuration setting was not made for a backend.
+ *
+ * @package TemplateTranslationTiein
+ * @version //autogentag//
+ */
+class ezcTemplateTranslationManagerNotConfiguredException extends 
ezcTemplateTranslationTieinException
+{
+    /**
+     * Constructs a new ezcTemplateTranslationManagerNotConfiguredException.
+     *
+     * @return void
+     */
+    function __construct()
+    {
+        parent::__construct( "The manager property of the 
ezcTemplateTranslationConfiguration has not been configured." );
+    }
+}
+?>

Propchange: 
trunk/TemplateTranslationTiein/src/exceptions/manager_not_configured.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/src/provider.php
==============================================================================
--- trunk/TemplateTranslationTiein/src/provider.php (added)
+++ trunk/TemplateTranslationTiein/src/provider.php [iso-8859-1] Wed Jan 30 
16:39:36 2008
@@ -1,0 +1,58 @@
+<?php
+/**
+ * File containing the ezcTemplateTranslationProvider class
+ *
+ * @package TemplateTranslationTiein
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * ezcTemplateTranslationProvider provides functions that are called from the
+ * template compiler to either translate strings, or convert them into code.
+ *
+ * @package TemplateTranslationTiein
+ * @mainclass
+ * @version //autogen//
+ */
+class ezcTemplateTranslationProvider
+{
+    /**
+     * Translates the string $string from the context $context with $arguments 
as variables.
+     *
+     * This static method is called whenever a template directly needs a
+     * translated string with the variables substituted.
+     *
+     * @param string $string
+     * @param string $context
+     * @param array(string=>mixed) $arguments
+     * @return string
+     */
+    static public function translate( $string, $context, $arguments )
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ctxt = $ttc->manager->getContext( $ttc->locale, $context );
+        $translation = $ctxt->getTranslation( $string, $arguments );
+        return $translation;
+    }
+
+    /**
+     * Compiles the string $string from the context $context with $arguments 
as variables into executable code.
+     *
+     * This static method translates a string, but inserts special code as
+     * replacements for the variables.
+     *
+     * @param string $string
+     * @param string $context
+     * @param array(string=>mixed) $arguments
+     * @return string
+     */
+    static public function compile( $string, $context, $arguments )
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ctxt = $ttc->manager->getContext( $ttc->locale, $context );
+        $translation = $ctxt->compileTranslation( $string, $arguments );
+        return $translation;
+    }
+}

Propchange: trunk/TemplateTranslationTiein/src/provider.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/src/template_translation_autoload.php
==============================================================================
--- trunk/TemplateTranslationTiein/src/template_translation_autoload.php (added)
+++ trunk/TemplateTranslationTiein/src/template_translation_autoload.php 
[iso-8859-1] Wed Jan 30 16:39:36 2008
@@ -1,0 +1,18 @@
+<?php
+/**
+ * Autoloader definition for the TemplateTranslationTiein component.
+ *
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package TemplateTranslationTiein
+ */
+
+return array(
+    'ezcTemplateTranslationTieinException'                => 
'TemplateTranslationTiein/exceptions/exception.php',
+    'ezcTemplateTranslationManagerNotConfiguredException' => 
'TemplateTranslationTiein/exceptions/manager_not_configured.php',
+    'ezcTemplateTranslationConfiguration'                 => 
'TemplateTranslationTiein/configuration.php',
+    'ezcTemplateTranslationProvider'                      => 
'TemplateTranslationTiein/provider.php',
+);
+?>

Propchange: trunk/TemplateTranslationTiein/src/template_translation_autoload.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/tests/configuration.php
==============================================================================
--- trunk/TemplateTranslationTiein/tests/configuration.php (added)
+++ trunk/TemplateTranslationTiein/tests/configuration.php [iso-8859-1] Wed Jan 
30 16:39:36 2008
@@ -1,0 +1,113 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package TemplateTranslationTiein
+ * @subpackage Tests
+ */
+
+/**
+ * @package TemplateTranslationTiein
+ * @subpackage Tests
+ */
+class ezcTemplateTranslationConfigurationTest extends ezcTestCase
+{
+    public function testGetInstance()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        $t->locale = "test";
+        $t2 = ezcTemplateTranslationConfiguration::getInstance();
+
+        self::assertEquals( "test", $t2->locale );
+        self::assertSame( $t, $t2 );
+    }
+
+    public function testWrongLocale()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        try
+        {
+            $t->locale = 42;
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            self::assertEquals( "The value '42' that you were trying to assign 
to setting 'locale' is invalid. Allowed values are: string.", $e->getMessage() 
);
+        }
+    }
+
+    public function testWrongManager()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        $t->manager = null;
+        try
+        {
+            $t->manager = 42;
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            self::assertEquals( "The value '42' that you were trying to assign 
to setting 'manager' is invalid. Allowed values are: instance of 
ezcTranslationManager or null.", $e->getMessage() );
+        }
+    }
+
+    public function testSetUnknownProperty()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        try
+        {
+            $t->notHere = 42;
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            self::assertEquals( "No such property name 'notHere'.", 
$e->getMessage() );
+        }
+    }
+
+    public function testGetUnknownProperty()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        try
+        {
+            $foo = $t->notHere;
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            self::assertEquals( "No such property name 'notHere'.", 
$e->getMessage() );
+        }
+    }
+
+    public function testSetManager()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        $t->manager = null;
+        $t->manager = new ezcTranslationManager( new ezcTranslationTsBackend( 
'.' ) );
+        self::assertType( 'ezcTranslationManager', $t->manager );
+    }
+
+    public function testGetManagerException()
+    {
+        $t = ezcTemplateTranslationConfiguration::getInstance();
+        $t->manager = null;
+        try
+        {
+            $manager = $t->manager;
+            self::fail( "Expected exception not thrown." );
+        }
+        catch ( ezcTemplateTranslationManagerNotConfiguredException $e )
+        {
+            self::assertEquals( "The manager property of the 
ezcTemplateTranslationConfiguration has not been configured.", $e->getMessage() 
);
+        }
+    }
+
+    public static function suite()
+    {
+         return new PHPUnit_Framework_TestSuite( 
'ezcTemplateTranslationConfigurationTest' );
+    }
+}
+
+?>

Propchange: trunk/TemplateTranslationTiein/tests/configuration.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/tests/provider.php
==============================================================================
--- trunk/TemplateTranslationTiein/tests/provider.php (added)
+++ trunk/TemplateTranslationTiein/tests/provider.php [iso-8859-1] Wed Jan 30 
16:39:36 2008
@@ -1,0 +1,226 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package TemplateTranslationTiein
+ * @subpackage Tests
+ */
+
+/**
+ * @package TemplateTranslationTiein
+ * @subpackage Tests
+ */
+class ezcTemplateTranslationProviderTest extends ezcTestCase
+{
+    public function setUp()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = null;
+    }
+
+    public function testTranslateManagerNotConfigured()
+    {
+        try
+        {
+            ezcTemplateTranslationProvider::translate( "Test", "test", array() 
);
+            self::fail( "Expected exception not thrown." );
+        }
+        catch ( ezcTemplateTranslationManagerNotConfiguredException $e )
+        {
+            self::assertEquals( "The manager property of the 
ezcTemplateTranslationConfiguration has not been configured.", $e->getMessage() 
);
+        }
+    }
+
+    public function testTranslate()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( 'Test Eén', 
ezcTemplateTranslationProvider::translate( "Test 1", "test", array() ) );
+    }
+
+    public function testTranslateWithNumericParams()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( 'Test Eén (a, c, b)', 
ezcTemplateTranslationProvider::translate( "Test 1 %1 %2 %3", "test", array( 1 
=> 'a', 'b', 'c' ) ) );
+    }
+
+    public function testTranslateWithNumericParamsWithMissingParam()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::translate( "Test 1 %1 %2 %3", 
"test", array( 1 => 'a', 'b' ) );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationParameterMissingException $e )
+        {
+            self::assertEquals( "The parameter '%3' does not exist.", 
$e->getMessage() );
+        }
+    }
+
+    public function testTranslateWithNamedParams()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( 'Test Eén (a, c, b)', 
ezcTemplateTranslationProvider::translate( "Test 1 %un %deux %trois", "test", 
array( 'un' => 'a', 'deux' => 'b', 'trois' => 'c', 'quatre' => 'd' ) ) );
+    }
+
+    public function testTranslateWithNamedParamsWithMissingParam()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::translate( "Test 1 %un %deux 
%trois", "test", array( 'un' => 'a', 'trois' => 'b' ) );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationParameterMissingException $e )
+        {
+            self::assertEquals( "The parameter '%deux' does not exist.", 
$e->getMessage() );
+        }
+    }
+
+    public function testTranslateWithWrongKey()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::translate( "Test 2", "test", 
array() );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationKeyNotAvailableException $e )
+        {
+            self::assertEquals( "The key 'Test 2' does not exist in the 
translation map.", $e->getMessage() );
+        }
+    }
+
+    public function testTranslateWithWrongContext()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::translate( "Test 3", "test2", 
array() );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationContextNotAvailableException $e )
+        {
+            self::assertEquals( "The context 'test2' does not exist.", 
$e->getMessage() );
+        }
+    }
+
+    public function testCompile()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( "'Test Eén'", 
ezcTemplateTranslationProvider::compile( "Test 1", "test", array() ) );
+    }
+
+    public function testCompileWithNumericParams()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( "'Test Eén (' . a . ', ' . c . ', ' . b . ')'", 
ezcTemplateTranslationProvider::compile( "Test 1 %1 %2 %3", "test", array( 1 => 
'a', 'b', 'c' ) ) );
+    }
+
+    public function testCompileWithNumericParamsWithMissingParam()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::compile( "Test 1 %1 %2 %3", 
"test", array( 1 => 'a', 'b' ) );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationParameterMissingException $e )
+        {
+            self::assertEquals( "The parameter '%3' does not exist.", 
$e->getMessage() );
+        }
+    }
+
+    public function testCompileWithQuote()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( "'He that loves to be flattered is worthy o\'' .  
the flatterer . '.'", ezcTemplateTranslationProvider::compile( "Test with 
quotes in result", "test", array( 'hvem' => ' the flatterer' ) ) );
+    }
+
+    public function testCompileWithNamedParams()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        self::assertEquals( "'Test Eén (' . a . ', ' . c . ', ' . b . ')'", 
ezcTemplateTranslationProvider::compile( "Test 1 %un %deux %trois", "test", 
array( 'un' => 'a', 'deux' => 'b', 'trois' => 'c', 'quatre' => 'd' ) ) );
+    }
+
+    public function testCompileWithNamedParamsWithMissingParam()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::compile( "Test 1 %un %deux 
%trois", "test", array( 'un' => 'a', 'trois' => 'b' ) );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationParameterMissingException $e )
+        {
+            self::assertEquals( "The parameter '%deux' does not exist.", 
$e->getMessage() );
+        }
+    }
+
+    public function testCompileWithWrongKey()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::compile( "Test 2", "test", array() 
);
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationKeyNotAvailableException $e )
+        {
+            self::assertEquals( "The key 'Test 2' does not exist in the 
translation map.", $e->getMessage() );
+        }
+    }
+
+    public function testCompileWithWrongContext()
+    {
+        $ttc = ezcTemplateTranslationConfiguration::getInstance();
+        $ttc->manager = new ezcTranslationManager( new 
ezcTranslationTsBackend( dirname( __FILE__ ) . '/translations' ) );
+
+        try
+        {
+            ezcTemplateTranslationProvider::compile( "Test 3", "test2", 
array() );
+            self::fail( 'Expected exception not thrown.' );
+        }
+        catch ( ezcTranslationContextNotAvailableException $e )
+        {
+            self::assertEquals( "The context 'test2' does not exist.", 
$e->getMessage() );
+        }
+    }
+
+    public static function suite()
+    {
+         return new PHPUnit_Framework_TestSuite( 
'ezcTemplateTranslationProviderTest' );
+    }
+}
+
+?>

Propchange: trunk/TemplateTranslationTiein/tests/provider.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/tests/suite.php
==============================================================================
--- trunk/TemplateTranslationTiein/tests/suite.php (added)
+++ trunk/TemplateTranslationTiein/tests/suite.php [iso-8859-1] Wed Jan 30 
16:39:36 2008
@@ -1,0 +1,38 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package TemplateTranslationTiein
+ * @subpackage Tests
+ */
+
+/**
+ * Require the tests
+ */
+require_once 'configuration.php';
+require_once 'provider.php';
+
+/**
+ * @package TemplateTranslationTiein
+ * @subpackage Tests
+ */
+class ezcTemplateTranslationTieinSuite extends PHPUnit_Framework_TestSuite
+{
+    public function __construct()
+    {
+        parent::__construct();
+        $this->setName( 'TemplateTranslationTiein' );
+
+        $this->addTest( ezcTemplateTranslationConfigurationTest::suite() );
+        $this->addTest( ezcTemplateTranslationProviderTest::suite() );
+    }
+
+    public static function suite()
+    {
+        return new ezcTemplateTranslationTieinSuite();
+    }
+}
+
+?>

Propchange: trunk/TemplateTranslationTiein/tests/suite.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/TemplateTranslationTiein/tests/translations/test.xml
==============================================================================
--- trunk/TemplateTranslationTiein/tests/translations/test.xml (added)
+++ trunk/TemplateTranslationTiein/tests/translations/test.xml [iso-8859-1] Wed 
Jan 30 16:39:36 2008
@@ -1,0 +1,22 @@
+<!DOCTYPE TS>
+<TS>
+<context>
+    <name>test</name>
+    <message>
+        <source>Test 1</source>
+        <translation>Test Eén</translation>
+    </message>
+    <message>
+        <source>Test 1 %1 %2 %3</source>
+        <translation>Test Eén (%1, %3, %2)</translation>
+    </message>
+    <message>
+        <source>Test 1 %un %deux %trois</source>
+        <translation>Test Eén (%un, %trois, %deux)</translation>
+    </message>
+    <message>
+        <source>Test with quotes in result</source>
+        <translation>He that loves to be flattered is worthy 
o'%hvem.</translation>
+    </message>
+</context>
+</TS>


-- 
svn-components mailing list
[EMAIL PROTECTED]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to