Author: Alexandru Stanoi
Date: 2006-11-13 16:07:45 +0100 (Mon, 13 Nov 2006)
New Revision: 3913

Log:
- Implemented feature request #9240: added ezcUrlCreator class to allow
  working with predefined locations (eg. images, design);

Added:
   trunk/Url/docs/tutorial_url_creator.php
   trunk/Url/docs/tutorial_url_creator_params.php
   trunk/Url/src/url_creator.php
   trunk/Url/tests/url_creator_test.php
Modified:
   trunk/Url/ChangeLog
   trunk/Url/docs/tutorial.txt
   trunk/Url/src/exceptions/url_exception.php
   trunk/Url/src/exceptions/url_invalid_parameter_exception.php
   trunk/Url/src/exceptions/url_no_configuration_exception.php
   trunk/Url/src/exceptions/url_not_registered_exception.php
   trunk/Url/src/url.php
   trunk/Url/src/url_autoload.php
   trunk/Url/tests/suite.php
   trunk/Url/tests/url_configuration_test.php
   trunk/Url/tests/url_test.php

Modified: trunk/Url/ChangeLog
===================================================================
--- trunk/Url/ChangeLog 2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/ChangeLog 2006-11-13 15:07:45 UTC (rev 3913)
@@ -1,3 +1,10 @@
+1.2beta2 - [RELEASEDATE]
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Implemented feature request #9240: added ezcUrlCreator class to allow
+  working with predefined locations (eg. images, design);
+
+
 1.0beta1 - Tuesday 24 October 2006
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 

Modified: trunk/Url/docs/tutorial.txt
===================================================================
--- trunk/Url/docs/tutorial.txt 2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/docs/tutorial.txt 2006-11-13 15:07:45 UTC (rev 3913)
@@ -7,7 +7,7 @@
 ============
 
 The Url package provides basic operations to handle urls (parse, build,
-get/set path parameters, get/set query).
+get/set path parameters, get/set query, create formatted urls).
 
 Class overview
 ==============
@@ -17,10 +17,15 @@
   building, get/set parameters, get/set query.
 
 ezcUrlConfiguration
-  This class allows definition of url configurations( basedir, script,
+  This class allows definition of url configurations (basedir, script,
   ordered parameters, unordered parameters, delimiters for unordered
   parameters names).
 
+ezcUrlCreator
+  This class allows registering an url under a alias, and then using that
+  alias to generate another url suffixed with a value, or to create urls
+  formatted using the syntax of the PHP function sprintf().
+
 Notes
 =====
 
@@ -235,6 +240,41 @@
 
     string(7) "Beatles"
 
+Using the url creator
+=====================
+
+Append a suffix to an url
+-------------------------
+
+With the url creator you can register an url under an alias, and then use that
+alias when you want to prepend the url to a filename.
+
+.. include:: tutorial_url_creator.php
+    :literal:
+
+The output will be: ::
+
+    string(53) "/images/geo/map_norway.gif?xsize=450&ysize=450&zoom=4"
+
+    string(53) "/images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4"
+
+    string(38) "/images/geo?xsize=450&ysize=450&zoom=4"
+
+Use formatting for an url
+-------------------------
+
+With the url creator you can register an url under an alias, and then use that
+alias when you want to apply formating to an url.
+
+.. include:: tutorial_url_creator_params.php
+    :literal:
+
+The output will be: ::
+
+    string(53) "/images/geo/map_norway.gif?xsize=450&ysize=450&zoom=4"
+
+    string(53) "/images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4"
+
 
 ..
    Local Variables:

Added: trunk/Url/docs/tutorial_url_creator.php
===================================================================
--- trunk/Url/docs/tutorial_url_creator.php     2006-11-13 13:30:36 UTC (rev 
3912)
+++ trunk/Url/docs/tutorial_url_creator.php     2006-11-13 15:07:45 UTC (rev 
3913)
@@ -0,0 +1,16 @@
+<?php
+require_once 'tutorial_autoload.php';
+
+// register an url under the alias 'map'
+ezcUrlCreator::registerUrl( 'map', '/images/geo?xsize=450&ysize=450&zoom=4' );
+
+// display the the url prepended to map_norway.gif
+var_dump( ezcUrlCreator::prependUrl( 'map', 'map_norway.gif' ) );
+
+// display the the url prepended to map_sweden.gif
+var_dump( ezcUrlCreator::prependUrl( 'map', 'map_sweden.gif' ) );
+
+// display the stored url under the alias 'map'
+var_dump( ezcUrlCreator::getUrl( 'map' ) );
+
+?>


Property changes on: trunk/Url/docs/tutorial_url_creator.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/Url/docs/tutorial_url_creator_params.php
===================================================================
--- trunk/Url/docs/tutorial_url_creator_params.php      2006-11-13 13:30:36 UTC 
(rev 3912)
+++ trunk/Url/docs/tutorial_url_creator_params.php      2006-11-13 15:07:45 UTC 
(rev 3913)
@@ -0,0 +1,12 @@
+<?php
+require_once 'tutorial_autoload.php';
+
+// register an url under the alias 'map'
+ezcUrlCreator::registerUrl( 'map', '/images/geo/%s?xsize=%d&ysize=%d&zoom=%d' 
);
+
+// display the stored url under the alias 'map' formatted with parameters
+var_dump( ezcUrlCreator::getUrl( 'map', 'map_norway.gif', 450, 450, 4 ) );
+
+// display the stored url under the alias 'map' formatted with other parameters
+var_dump( ezcUrlCreator::getUrl( 'map', 'map_sweden.gif', 450, 450, 4 ) );
+?>


Property changes on: trunk/Url/docs/tutorial_url_creator_params.php
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/Url/src/exceptions/url_exception.php
===================================================================
--- trunk/Url/src/exceptions/url_exception.php  2006-11-13 13:30:36 UTC (rev 
3912)
+++ trunk/Url/src/exceptions/url_exception.php  2006-11-13 15:07:45 UTC (rev 
3913)
@@ -22,9 +22,9 @@
      * @param string $message
      * @param int $code
      */
-    public function __construct( $message )
+    public function __construct( $message, $code = 0 )
     {
-        parent::__construct( $message, 0 );
+        parent::__construct( $message, $code );
     }
 }
 ?>

Modified: trunk/Url/src/exceptions/url_invalid_parameter_exception.php
===================================================================
--- trunk/Url/src/exceptions/url_invalid_parameter_exception.php        
2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/src/exceptions/url_invalid_parameter_exception.php        
2006-11-13 15:07:45 UTC (rev 3913)
@@ -8,7 +8,8 @@
  * @license http://ez.no/licenses/new_bsd New BSD License
  */
 /**
- * ezcUrlInvalidParameterException is thrown at get/set of undefined parameter
+ * ezcUrlInvalidParameterException is thrown at get/set of a parameter
+ * undefined in the configuration.
  *
  * @package Url
  * @version //autogen//
@@ -22,7 +23,7 @@
      */
     public function __construct( $param )
     {
-        $message = "The parameter {$param} could not be set/get because it is 
not defined in the configuration.";
+        $message = "The parameter <{$param}> could not be set/get because it 
is not defined in the configuration.";
         parent::__construct( $message, 0 );
     }
 }

Modified: trunk/Url/src/exceptions/url_no_configuration_exception.php
===================================================================
--- trunk/Url/src/exceptions/url_no_configuration_exception.php 2006-11-13 
13:30:36 UTC (rev 3912)
+++ trunk/Url/src/exceptions/url_no_configuration_exception.php 2006-11-13 
15:07:45 UTC (rev 3913)
@@ -9,7 +9,7 @@
  */
 /**
  * ezcUrlNoConfigurationException is thrown whenever you try to use a url
- * that is not registered.
+ * configuration that is not defined.
  *
  * @package Url
  * @version //autogen//
@@ -23,7 +23,7 @@
      */
     public function __construct( $param )
     {
-        $message = "The parameter {$param} could not be set/get because the 
url doesn't have a configuration defined.";
+        $message = "The parameter <{$param}> could not be set/get because the 
url doesn't have a configuration defined.";
         parent::__construct( $message, 0 );
     }
 }

Modified: trunk/Url/src/exceptions/url_not_registered_exception.php
===================================================================
--- trunk/Url/src/exceptions/url_not_registered_exception.php   2006-11-13 
13:30:36 UTC (rev 3912)
+++ trunk/Url/src/exceptions/url_not_registered_exception.php   2006-11-13 
15:07:45 UTC (rev 3913)
@@ -23,7 +23,7 @@
      */
     public function __construct( $name )
     {
-        $message = "The url {$name} is not registered.";
+        $message = "The url <{$name}> is not registered.";
         parent::__construct( $message, 0 );
     }
 }

Modified: trunk/Url/src/url.php
===================================================================
--- trunk/Url/src/url.php       2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/src/url.php       2006-11-13 15:07:45 UTC (rev 3913)
@@ -10,7 +10,7 @@
  */
 
 /**
- * ezcUrl stores a URL both absolute and relative and contains methods to
+ * ezcUrl stores an URL both absolute and relative and contains methods to
  * retrieve the various parts of the URL and to manipulate them.
  *
  * @property string $host
@@ -56,7 +56,7 @@
      *
      * @var ezcUrlConfiguration
      */
-    public $urlCfg = null;
+    private $urlCfg = null;
 
     /**
      * Constructs a new ezcUrl object from the string $url.
@@ -77,7 +77,7 @@
      * Sets the property $name to $value.
      *
      * @throws ezcBasePropertyNotFoundException
-     *         if the property does not exist.
+     *         if the property does not exist
      * @param string $name
      * @param mixed $value
      * @ignore
@@ -100,6 +100,7 @@
             case 'uparams':
                 $this->properties[$name] = $value;
                 break;
+
             default:
                 throw new ezcBasePropertyNotFoundException( $name );
                 break;
@@ -110,7 +111,7 @@
      * Returns the property $name.
      *
      * @throws ezcBasePropertyNotFoundException
-     *         if the property does not exist.
+     *         if the property does not exist
      * @param string $name
      * @return mixed
      * @ignore
@@ -132,14 +133,43 @@
             case 'params':
             case 'uparams':
                 return $this->properties[$name];
-                break;
+
             default:
                 throw new ezcBasePropertyNotFoundException( $name );
-                break;
         }
     }
 
     /**
+     * Returns true if the property $name is set, otherwise false.
+     *
+     * @param $name
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $name )
+    {
+        switch ( $name )
+        {
+            case 'host':
+            case 'path':
+            case 'user':
+            case 'pass':
+            case 'port':
+            case 'scheme':
+            case 'fragment':
+            case 'query':
+            case 'basedir':
+            case 'script':
+            case 'params':
+            case 'uparams':
+                return isset( $this->properties[$name] );
+
+            default:
+                return false;
+        }
+    }
+
+    /**
      * Returns this URL as a string by calling [EMAIL PROTECTED] buildUrl()}.
      *
      * @return string
@@ -184,35 +214,31 @@
     /**
      * Applies the configuration $urlCfg to the current url.
      *
+     * It fills the arrays $basedir, $script, $params and $uparams with values
+     * from $path.
+     *
      * @param ezcUrlConfiguration $urlCfg
      */
     public function applyConfiguration( $urlCfg )
     {
         $this->urlCfg = $urlCfg;
-        $this->basedir = $this->parseElement( $urlCfg->basedir, 0 );
-        $this->script = $this->parseElement( $urlCfg->script, count( 
$this->basedir ) );
-        $this->uparams = $this->parseUnorderedParameters();
-        if ( count( $this->uparams ) != 0 )
-        {
-            $this->params = array_slice( $this->path, count( $this->basedir ) 
+ count( $this->script ), count( $this->path ) - count( $this->uparams, 
COUNT_RECURSIVE ) );
-        }
-        else
-        {
-            $this->params = array_slice( $this->path, count( $this->basedir ) 
+ count( $this->script ) );
-        }
+        $this->basedir = $this->parsePathElement( $urlCfg->basedir, 0 );
+        $this->script = $this->parsePathElement( $urlCfg->script, count( 
$this->basedir ) );
+        $this->params = $this->parseOrderedParameters( 
$urlCfg->orderedParameters, count( $this->basedir ) + count( $this->script ) );
+        $this->uparams = $this->parseUnorderedParameters( 
$urlCfg->unorderedParameters, count( $this->basedir ) + count( $this->script ) 
+ count( $this->params ) );
     }
 
     /**
-     * Parses start of $this->path based on the configuration provided.
+     * Parses $path based on the configuration $config, starting from $index.
      *
      * Returns the first few elements of $this->path matching $config,
      * starting from $index.
      *
      * @param string $config
      * @param int $index
-     * @return array
+     * @return array(string=>mixed)
      */
-    private function parseElement( $config, $index )
+    private function parsePathElement( $config, $index )
     {
         $paramParts = explode( '/', $config );
         $pathElement = array();
@@ -228,34 +254,58 @@
     }
 
     /**
-     * Parses the $path array.
+     * Returns ordered parameters from the $path array.
      *
+     * @param array(int=>string) $config
+     * @param int $index
      * @return array(string=>mixed)
      */
-    private function parseUnorderedParameters()
+    public function parseOrderedParameters( $config, $index )
     {
         $result = array();
-        $path = $this->path;
-        $pathCount = count( $path );
-        if ( $pathCount == 0 || ( $pathCount == 1 && trim( $path[0] ) === "" ) 
)
+        $pathCount = count( $this->path );
+        for ( $i = 0; $i < count( $config ); $i++ )
         {
+            if ( isset( $this->path[$index + $i] ) )
+            {
+                $result[] = $this->path[$index + $i];
+            }
+            else
+            {
+                $result[] = null;
+            }
+        }
+        return $result;
+    }
+
+    /**
+     * Returns unordered parameters from the $path array.
+     *
+     * @param array(int=>string) $config
+     * @param int $index
+     * @return array(string=>mixed)
+     */
+    public function parseUnorderedParameters( $config, $index )
+    {
+        $result = array();
+        $pathCount = count( $this->path );
+        if ( $pathCount == 0 || ( $pathCount == 1 && trim( $this->path[0] ) 
=== "" ) )
+        {
             // special case: a bug? in parse_url() which makes $this->path
             // be array( "" ) if the provided url is null or empty
             return $result;
         }
-        for ( $i = 0; $i < $pathCount; $i++ )
+        for ( $i = $index; $i < $pathCount; $i++ )
         {
-            $param = $path[$i];
+            $param = $this->path[$i];
             if ( $param{0} == $this->urlCfg->unorderedDelimiters[0] )
             {
-                $param = trim( trim( $param, 
$this->urlCfg->unorderedDelimiters[0] ),
-                    $this->urlCfg->unorderedDelimiters[1] );
+                $param = trim( trim( $param, 
$this->urlCfg->unorderedDelimiters[0] ), $this->urlCfg->unorderedDelimiters[1] 
);
                 $result[$param] = array();
                 $j = 1;
-                while ( ( $i + $j ) < $pathCount && $path[$i + $j]{0} != 
$this->urlCfg->unorderedDelimiters[0] )
+                while ( ( $i + $j ) < $pathCount && $this->path[$i + $j]{0} != 
$this->urlCfg->unorderedDelimiters[0] )
                 {
-                    $result[$param][] = trim( trim( $path[$i + $j], 
$this->urlCfg->unorderedDelimiters[0] ),
-                        $this->urlCfg->unorderedDelimiters[1]  );
+                    $result[$param][] = trim( trim( $this->path[$i + $j], 
$this->urlCfg->unorderedDelimiters[0] ), $this->urlCfg->unorderedDelimiters[1] 
);
                     $j++;
                 }
             }
@@ -362,9 +412,9 @@
      * Returns the specified parameter from the url based on $urlCfg.
      *
      * @throws ezcUrlNoConfigurationException
-     *         if an url configuration was not defined.
+     *         if an $urlCfg is not defined
      * @throws ezcUrlInvalidParameterException
-     *         if the specified parameter is not defined in the configuration.
+     *         if the specified parameter is not defined in $urlCfg
      * @param string $name
      * @return mixed
      */
@@ -410,9 +460,9 @@
      * Sets the specified parameter in the url based on $urlCfg.
      *
      * @throws ezcUrlNoConfigurationException
-     *         if an url configuration was not defined.
+     *         if an $urlCfg is not defined
      * @throws ezcUrlInvalidParameterException
-     *         if the specified parameter is not defined in the configuration.
+     *         if the specified parameter is not defined in $urlCfg
      * @param string $name
      * @param string $value
      */
@@ -454,7 +504,7 @@
      * for 'http://www.example.com/mydir/shop?content=view&products=10'
      * returns array( 'content' => 'view', 'products' => '10' )
      *
-     * @return array
+     * @return array(string=>mixed)
      */
     public function getQuery()
     {

Modified: trunk/Url/src/url_autoload.php
===================================================================
--- trunk/Url/src/url_autoload.php      2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/src/url_autoload.php      2006-11-13 15:07:45 UTC (rev 3913)
@@ -10,6 +10,7 @@
 return array(
     'ezcUrl'                => 'Url/url.php',
     'ezcUrlConfiguration'   => 'Url/url_configuration.php',
+    'ezcUrlCreator'         => 'Url/url_creator.php',
 
     'ezcUrlException'                 => 'Url/exceptions/url_exception.php',
     'ezcUrlNotRegisteredException'    => 
'Url/exceptions/url_not_registered_exception.php',

Added: trunk/Url/src/url_creator.php
===================================================================
--- trunk/Url/src/url_creator.php       2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/src/url_creator.php       2006-11-13 15:07:45 UTC (rev 3913)
@@ -0,0 +1,105 @@
+<?php
+/**
+ * File containing the ezcUrlCreator class.
+ *
+ * @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 Url
+ */
+
+/**
+ * @package Url
+ * @version //autogen//
+ */
+class ezcUrlCreator
+{
+    /**
+     * Holds the registered urls.
+     *
+     * @var array(string=>string)
+     */
+    private static $urls = array();
+
+    /**
+     * Registers $url as $name in the urls list.
+     *
+     * If $name is already registered, it will be overwritten.
+     *
+     * @param string $name
+     * @param string $url
+     */
+    public static function registerUrl( $name, $url )
+    {
+        self::$urls[$name] = $url;
+    }
+
+    /**
+     * Returns the url registerd as $name prepended to $suffix.
+     *
+     * Example:
+     * <code>
+     * ezcUrlCreator::registerUrl( 'map', 
'/images/geo?xsize=450&ysize=450&zoom=4' );
+     * echo ezcUrlCreator::prependUrl( 'map', 'map_sweden.gif' );
+     * </code>
+     * will output:
+     * /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4
+     *
+     * @throws ezcUrlNotRegisteredException
+     *         if $name is not registered
+     * @param string $name
+     * @param string $suffix
+     * @return string
+     */
+    public static function prependUrl( $name, $suffix )
+    {
+        if ( !isset( self::$urls[$name] ) )
+        {
+            throw new ezcUrlNotRegisteredException( $name );
+        }
+
+        $url = new ezcUrl( self::$urls[$name] );
+        $url->path = array_merge( $url->path, explode( '/', $suffix ) );
+        return $url->buildUrl();
+    }
+
+    /**
+     * Returns the url registered as $name.
+     *
+     * This function accepts a variable number of arguments like the sprintf()
+     * function. If you specify more than 1 arguments when calling this
+     * function, the registered url will be formatted using those arguments
+     * similar with the sprintf() function.
+     * Example:
+     * <code>
+     * ezcUrlCreator::registerUrl( 'map', 
'/images/geo/%s?xsize=%d&ysize=%d&zoom=%d' );
+     * echo ezcUrlCreator::getUrl( 'map', 'map_sweden.gif', 450, 450, 4 );
+     * </code>
+     * will output:
+     * /images/geo/map_sweden.gif?xsize=450&ysize=450&zoom=4
+     *
+     * @throws ezcUrlNotRegisteredException
+     *         if $name is not registered
+     * @param string $name
+     * @param ... mixed args
+     * @return string
+     */
+    public static function getUrl( $name )
+    {
+        if ( !isset( self::$urls[$name] ) )
+        {
+            throw new ezcUrlNotRegisteredException( $name );
+        }
+
+        if ( func_num_args() > 1 )
+        {
+            $args = func_get_args();
+            // get rid of the first argument ($name)
+            unset( $args[0] );
+            return vsprintf( self::$urls[$name], $args );
+        }
+        return self::$urls[$name];
+    }
+}
+?>


Property changes on: trunk/Url/src/url_creator.php
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/Url/tests/suite.php
===================================================================
--- trunk/Url/tests/suite.php   2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/tests/suite.php   2006-11-13 15:07:45 UTC (rev 3913)
@@ -13,6 +13,7 @@
  */
 require_once( "url_test.php" );
 require_once( "url_configuration_test.php" );
+require_once( "url_creator_test.php" );
 
 /**
  * @package Url
@@ -27,6 +28,7 @@
 
         $this->addTest( ezcUrlTest::suite() );
         $this->addTest( ezcUrlConfigurationTest::suite() );
+        $this->addTest( ezcUrlCreatorTest::suite() );
     }
 
     public static function suite()

Modified: trunk/Url/tests/url_configuration_test.php
===================================================================
--- trunk/Url/tests/url_configuration_test.php  2006-11-13 13:30:36 UTC (rev 
3912)
+++ trunk/Url/tests/url_configuration_test.php  2006-11-13 15:07:45 UTC (rev 
3913)
@@ -46,6 +46,8 @@
         }
         catch ( ezcBasePropertyNotFoundException $e )
         {
+            $expected = 'No such property name <no_such_property>.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -64,7 +66,7 @@
         $this->assertEquals( '/mydir/shop', $urlCfg->basedir );
         $this->assertEquals( 'index.php', $urlCfg->script );
         $this->assertEquals( array( 'section' => 0, 'module' => 1, 'view' => 
2, 'branch' => 3 ),
-            $urlCfg->orderedParameters );
+                             $urlCfg->orderedParameters );
         $this->assertEquals( array( 'file' => 1 ), 
$urlCfg->unorderedParameters );
         $this->assertEquals( array( '_', '_' ), $urlCfg->unorderedDelimiters );
     }
@@ -79,6 +81,8 @@
         }
         catch ( ezcBasePropertyNotFoundException $e )
         {
+            $expected = 'No such property name <no_such_property>.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 

Added: trunk/Url/tests/url_creator_test.php
===================================================================
--- trunk/Url/tests/url_creator_test.php        2006-11-13 13:30:36 UTC (rev 
3912)
+++ trunk/Url/tests/url_creator_test.php        2006-11-13 15:07:45 UTC (rev 
3913)
@@ -0,0 +1,71 @@
+<?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 Url
+ * @subpackage Tests
+ */
+
+/**
+ * @package Url
+ * @subpackage Tests
+ */
+class ezcUrlCreatorTest extends ezcTestCase
+{
+    public function testGetUrl()
+    {
+        ezcUrlCreator::registerUrl( 'map', 'http://www.example.com' );
+        $expected = 'http://www.example.com';
+        $this->assertEquals( $expected, ezcUrlCreator::getUrl( 'map' ) );
+    }
+
+    public function testGetUrlNotRegistered()
+    {
+        try
+        {
+            ezcUrlCreator::getUrl( 'not registered url' );
+            $this->fail( 'Expected exception was not thrown' );
+        }
+        catch ( ezcUrlNotRegisteredException $e )
+        {
+            $expected = 'The url <not registered url> is not registered.';
+            $this->assertEquals( $expected, $e->getMessage() );
+        }
+    }
+
+    public function testGetUrlFormatted()
+    {
+        ezcUrlCreator::registerUrl( 'map', 
'http://www.example.com/images/%s?xsize=%d&ysize=%d&zoom=%d' );
+        $expected = 
'http://www.example.com/images/map_sweden.gif?xsize=400&ysize=300&zoom=4';
+        $this->assertEquals( $expected, ezcUrlCreator::getUrl( 'map', 
'map_sweden.gif', 400, 300, 4 ) );
+    }
+
+    public function testPrependUrl()
+    {
+        ezcUrlCreator::registerUrl( 'map', 'http://www.example.com?id=1' );
+        $expected = 'http://www.example.com/images?id=1';
+        $this->assertEquals( $expected, ezcUrlCreator::prependUrl( 'map', 
'images' ) );
+    }
+
+    public function testPrependUrlNotRegistered()
+    {
+        try
+        {
+            ezcUrlCreator::prependUrl( 'not registered url', 'images' );
+            $this->fail( 'Expected exception was not thrown' );
+        }
+        catch ( ezcUrlNotRegisteredException $e )
+        {
+            $expected = 'The url <not registered url> is not registered.';
+            $this->assertEquals( $expected, $e->getMessage() );
+        }
+    }
+
+    public static function suite()
+    {
+         return new PHPUnit_Framework_TestSuite( "ezcUrlCreatorTest" );
+    }
+}
+?>


Property changes on: trunk/Url/tests/url_creator_test.php
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/Url/tests/url_test.php
===================================================================
--- trunk/Url/tests/url_test.php        2006-11-13 13:30:36 UTC (rev 3912)
+++ trunk/Url/tests/url_test.php        2006-11-13 15:07:45 UTC (rev 3913)
@@ -37,6 +37,8 @@
         }
         catch ( ezcBasePropertyNotFoundException $e )
         {
+            $expected = 'No such property name <no_such_property>.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -65,6 +67,8 @@
         }
         catch ( ezcBasePropertyNotFoundException $e )
         {
+            $expected = 'No such property name <no_such_property>.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -98,6 +102,10 @@
         $urlCfg = new ezcUrlConfiguration();
         $urlCfg->basedir = 'mydir/shop';
         $urlCfg->script = 'index.php';
+        $urlCfg->addOrderedParameter( 'section' );
+        $urlCfg->addOrderedParameter( 'module' );
+        $urlCfg->addOrderedParameter( 'view' );
+        $urlCfg->addOrderedParameter( 'content' );
 
         $url = new ezcUrl( 
'http://www.example.com/mydir/shop/index.php/doc/components/view/trunk', 
$urlCfg );
         $expected = 
'http://www.example.com/mydir/shop/doc/components/view/trunk';
@@ -180,6 +188,8 @@
         }
         catch ( ezcUrlInvalidParameterException $e )
         {
+            $expected = 'The parameter <section> could not be set/get because 
it is not defined in the configuration.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -193,6 +203,8 @@
         }
         catch ( ezcUrlNoConfigurationException $e )
         {
+            $expected = 'The parameter <section> could not be set/get because 
the url doesn\'t have a configuration defined.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -222,6 +234,8 @@
         }
         catch ( ezcUrlInvalidParameterException $e )
         {
+            $expected = 'The parameter <section> could not be set/get because 
it is not defined in the configuration.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -235,6 +249,8 @@
         }
         catch ( ezcUrlNoConfigurationException $e )
         {
+            $expected = 'The parameter <section> could not be set/get because 
the url doesn\'t have a configuration defined.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -277,6 +293,8 @@
         }
         catch ( ezcUrlInvalidParameterException $e )
         {
+            $expected = 'The parameter <file> could not be set/get because it 
is not defined in the configuration.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -290,6 +308,8 @@
         }
         catch ( ezcUrlNoConfigurationException $e )
         {
+            $expected = 'The parameter <file> could not be set/get because the 
url doesn\'t have a configuration defined.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -297,6 +317,10 @@
     {
         $urlCfg = new ezcUrlConfiguration();
         $urlCfg->addUnorderedParameter( 'file' );
+        $urlCfg->addOrderedParameter( 'section' );
+        $urlCfg->addOrderedParameter( 'module' );
+        $urlCfg->addOrderedParameter( 'view' );
+        $urlCfg->addOrderedParameter( 'content' );
 
         $url = new ezcUrl( 'http://www.example.com/doc/components/view/trunk', 
$urlCfg );
         $expected = 
'http://www.example.com/doc/components/view/trunk/(file)/Base';
@@ -308,6 +332,10 @@
     {
         $urlCfg = new ezcUrlConfiguration();
         $urlCfg->addUnorderedParameter( 'file', 
ezcUrlConfiguration::MULTIPLE_ARGUMENTS );
+        $urlCfg->addOrderedParameter( 'section' );
+        $urlCfg->addOrderedParameter( 'module' );
+        $urlCfg->addOrderedParameter( 'view' );
+        $urlCfg->addOrderedParameter( 'content' );
 
         $url = new ezcUrl( 'http://www.example.com/doc/components/view/trunk', 
$urlCfg );
         $expected = 
'http://www.example.com/doc/components/view/trunk/(file)/Base/ezcBase.html';
@@ -327,6 +355,8 @@
         }
         catch ( ezcUrlInvalidParameterException $e )
         {
+            $expected = 'The parameter <file> could not be set/get because it 
is not defined in the configuration.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
@@ -340,9 +370,29 @@
         }
         catch ( ezcUrlNoConfigurationException $e )
         {
+            $expected = 'The parameter <file> could not be set/get because the 
url doesn\'t have a configuration defined.';
+            $this->assertEquals( $expected, $e->getMessage() );
         }
     }
 
+    public function testIsSet()
+    {
+        $url = new ezcUrl( 'http://www.example.com' );
+        $this->assertEquals( true, isset( $url->host ) );
+        $this->assertEquals( false, isset( $url->user ) );
+        $this->assertEquals( false, isset( $url->pass ) );
+        $this->assertEquals( false, isset( $url->port ) );
+        $this->assertEquals( true, isset( $url->scheme ) );
+        $this->assertEquals( false, isset( $url->fragment ) );
+        $this->assertEquals( true, isset( $url->path ) );
+        $this->assertEquals( true, isset( $url->basedir ) );
+        $this->assertEquals( true, isset( $url->script ) );
+        $this->assertEquals( true, isset( $url->params ) );
+        $this->assertEquals( true, isset( $url->uparams ) );
+        $this->assertEquals( true, isset( $url->query ) );
+        $this->assertEquals( false, isset( $url->no_such_property ) );
+    }
+
     public static function suite()
     {
          return new PHPUnit_Framework_TestSuite( "ezcUrlTest" );

-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to