Просмотр исходного кода

[ZF-10266]
added sizelimit and timelimit parameters to Zend_Ldap::search()

added Zend_Ldap_Converter built by Andreas Heigl

integrated Zend_Ldap_Converter into existing infrastructure

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22996 44c647ce-9c0f-0410-b52a-842ac1e357ba

sgehrig 15 лет назад
Родитель
Сommit
ccbdf08508

+ 18 - 7
library/Zend/Ldap.php

@@ -913,6 +913,8 @@ class Zend_Ldap
      * - attributes
      * - sort
      * - collectionClass
+     * - sizelimit
+     * - timelimit
      *
      * @param  string|Zend_Ldap_Filter_Abstract|array $filter
      * @param  string|Zend_Ldap_Dn|null               $basedn
@@ -920,11 +922,13 @@ class Zend_Ldap
      * @param  array                                  $attributes
      * @param  string|null                            $sort
      * @param  string|null                            $collectionClass
+     * @param  integer                            	  $sizelimit
+     * @param  integer                            	  $timelimit
      * @return Zend_Ldap_Collection
      * @throws Zend_Ldap_Exception
      */
-    public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
-        array $attributes = array(), $sort = null, $collectionClass = null)
+    public function search($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB, array $attributes = array(),
+        $sort = null, $collectionClass = null, $sizelimit = 0, $timelimit = 0)
     {
         if (is_array($filter)) {
             $options = array_change_key_case($filter, CASE_LOWER);
@@ -944,6 +948,9 @@ class Zend_Ldap
                     case 'collectionclass':
                         $collectionClass = $value;
                         break;
+                    case 'sizelimit':
+                    case 'timelimit':
+                        $$key = (int)$value;
                 }
             }
         }
@@ -961,14 +968,14 @@ class Zend_Ldap
 
         switch ($scope) {
             case self::SEARCH_SCOPE_ONE:
-                $search = @ldap_list($this->getResource(), $basedn, $filter, $attributes);
+                $search = @ldap_list($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
                 break;
             case self::SEARCH_SCOPE_BASE:
-                $search = @ldap_read($this->getResource(), $basedn, $filter, $attributes);
+                $search = @ldap_read($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
                 break;
             case self::SEARCH_SCOPE_SUB:
             default:
-                $search = @ldap_search($this->getResource(), $basedn, $filter, $attributes);
+                $search = @ldap_search($this->getResource(), $basedn, $filter, $attributes, 0, $sizelimit, $timelimit);
                 break;
         }
 
@@ -1091,6 +1098,8 @@ class Zend_Ldap
      * - attributes
      * - sort
      * - reverseSort
+     * - sizelimit
+     * - timelimit
      *
      * @param  string|Zend_Ldap_Filter_Abstract|array $filter
      * @param  string|Zend_Ldap_Dn|null               $basedn
@@ -1098,11 +1107,13 @@ class Zend_Ldap
      * @param  array                                  $attributes
      * @param  string|null                            $sort
      * @param  boolean                                $reverseSort
+     * @param  integer                            	  $sizelimit
+     * @param  integer                            	  $timelimit
      * @return array
      * @throws Zend_Ldap_Exception
      */
     public function searchEntries($filter, $basedn = null, $scope = self::SEARCH_SCOPE_SUB,
-        array $attributes = array(), $sort = null, $reverseSort = false)
+        array $attributes = array(), $sort = null, $reverseSort = false, $sizelimit = 0, $timelimit = 0)
     {
         if (is_array($filter)) {
             $filter = array_change_key_case($filter, CASE_LOWER);
@@ -1114,7 +1125,7 @@ class Zend_Ldap
                 unset($filter['reversesort']);
             }
         }
-        $result = $this->search($filter, $basedn, $scope, $attributes, $sort);
+        $result = $this->search($filter, $basedn, $scope, $attributes, $sort, null, $sizelimit, $timelimit);
         $items = $result->toArray();
         if ((bool)$reverseSort === true) {
             $items = array_reverse($items, false);

+ 33 - 39
library/Zend/Ldap/Attribute.php

@@ -20,6 +20,11 @@
  */
 
 /**
+ * @see Zend_Ldap_Converter
+ */
+require_once 'Zend/Ldap/Converter.php';
+
+/**
  * Zend_Ldap_Attribute is a collection of LDAP attribute related functions.
  *
  * @category   Zend
@@ -185,32 +190,33 @@ class Zend_Ldap_Attribute
      */
     private static function _valueToLdap($value)
     {
-        if (is_string($value)) return $value;
-        else if (is_int($value) || is_float($value)) return (string)$value;
-        else if (is_bool($value)) return ($value === true) ? 'TRUE' : 'FALSE';
-        else if (is_object($value) || is_array($value)) return serialize($value);
-        else if (is_resource($value) && get_resource_type($value) === 'stream')
-            return stream_get_contents($value);
-        else return null;
+        return Zend_Ldap_Converter::toLdap($value);
     }
 
     /**
      * @param  string $value
-     * @return string|boolean
+     * @return mixed
      */
     private static function _valueFromLdap($value)
     {
-        $value = (string)$value;
-        if ($value === 'TRUE') return true;
-        else if ($value === 'FALSE') return false;
-        else return $value;
+        try {
+            $return = Zend_Ldap_Converter::fromLdap($value, Zend_Ldap_Converter::STANDARD, false);
+            if ($return instanceof DateTime) {
+                return Zend_Ldap_Converter::toLdapDateTime($return, false);
+            } else {
+                return $return;
+            }
+        } catch (InvalidArgumentException $e) {
+            return $value;
+        }
     }
 
     /**
      * Converts a PHP data type into its LDAP representation
      *
-     * @param  mixed $value
-     * @return string|null - null if the PHP data type cannot be converted.
+     * @deprected	use Zend_Ldap_Converter instead
+     * @param  		mixed $value
+     * @return 		string|null - null if the PHP data type cannot be converted.
      */
     public static function convertToLdapValue($value)
     {
@@ -220,8 +226,9 @@ class Zend_Ldap_Attribute
     /**
      * Converts an LDAP value into its PHP data type
      *
-     * @param  string $value
-     * @return mixed
+     * @deprected	use Zend_Ldap_Converter instead
+     * @param  		string $value
+     * @return 		mixed
      */
     public static function convertFromLdapValue($value)
     {
@@ -362,8 +369,7 @@ class Zend_Ldap_Attribute
     private static function _valueToLdapDateTime($value, $utc)
     {
         if (is_int($value)) {
-            if ($utc === true) return gmdate('YmdHis', $value) . 'Z';
-            else return date('YmdHisO', $value);
+            return Zend_Ldap_Converter::toLdapDateTime($value, $utc);
         }
         else return null;
     }
@@ -393,31 +399,19 @@ class Zend_Ldap_Attribute
     }
 
     /**
-     * @param  string $value
+     * @param  string|DateTime $value
      * @return integer|null
      */
     private static function _valueFromLdapDateTime($value)
     {
-        $matches = array();
-        if (preg_match('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:\.0)?([+-]\d{4}|Z)$/', $value, $matches)) {
-            $year = $matches[1];
-            $month = $matches[2];
-            $day = $matches[3];
-            $hour = $matches[4];
-            $minute = $matches[5];
-            $second = $matches[6];
-            $timezone = $matches[7];
-            $date = gmmktime($hour, $minute, $second, $month, $day, $year);
-            if ($timezone !== 'Z') {
-                $tzDirection = substr($timezone, 0, 1);
-                $tzOffsetHour = substr($timezone, 1, 2);
-                $tzOffsetMinute = substr($timezone, 3, 2);
-                $tzOffset = ($tzOffsetHour*60*60) + ($tzOffsetMinute*60);
-                if ($tzDirection == '+') $date -= $tzOffset;
-                else if ($tzDirection == '-') $date += $tzOffset;
+        if ($value instanceof DateTime) {
+            return $value->format('U');
+        } else if (is_string($value)) {
+            try {
+                return Zend_Ldap_Converter::fromLdapDateTime($value, false)->format('U');
+            } catch (InvalidArgumentException $e) {
+                return null;
             }
-            return $date;
-        }
-        else return null;
+        } else return null;
     }
 }

+ 325 - 0
library/Zend/Ldap/Converter.php

@@ -29,6 +29,10 @@
  */
 class Zend_Ldap_Converter
 {
+    const STANDARD         = 0;
+    const BOOLEAN          = 1;
+    const GENERALIZED_TIME = 2;
+
     /**
      * Converts all ASCII chars < 32 to "\HEX"
      *
@@ -68,4 +72,325 @@ class Zend_Ldap_Converter
         $string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
         return $string;
     }
+
+	/**
+     * Convert any value to an LDAP-compatible value.
+     *
+     * By setting the <var>$type</var>-parameter the conversion of a certain
+     * type can be forced
+     *
+     * @todo write more tests
+     *
+     * @param	mixed 	$value 	The value to convert
+     * @param	int   	$ytpe  	The conversion type to use
+     * @return	string
+     * @throws	Zend_Ldap_Converter_Exception
+     */
+    public static function toLdap($value, $type = self::STANDARD)
+    {
+        try {
+            switch ($type) {
+                case self::BOOLEAN:
+                    return self::toldapBoolean($value);
+                    break;
+                case self::GENERALIZED_TIME:
+                    return self::toLdapDatetime($value);
+                    break;
+                default:
+                    if (is_string($value)) {
+                        return $value;
+                    } else if (is_int($value) || is_float($value)) {
+                        return (string)$value;
+                    } else if (is_bool($value)) {
+                        return self::toldapBoolean($value);
+                    } else if (is_object($value)) {
+                        if ($value instanceof DateTime) {
+                            return self::toLdapDatetime($value);
+                        } else if ($value instanceof Zend_Date) {
+                            return self::toLdapDatetime($value);
+                        } else {
+                            return self::toLdapSerialize($value);
+                        }
+                    } else if (is_array($value)) {
+                        return self::toLdapSerialize($value);
+                    } else if (is_resource($value) && get_resource_type($value) === 'stream') {
+                        return stream_get_contents($value);
+                    } else {
+                        return null;
+                    }
+                    break;
+            }
+        } catch (Exception $e) {
+            throw new Zend_Ldap_Converter_Exception($e->getMessage(), $e->getCode(), $e);
+        }
+    }
+
+    /**
+     * Converts a date-entity to an LDAP-compatible date-string
+     *
+     * The date-entity <var>$date</var> can be either a timestamp, a
+     * DateTime Object, a string that is parseable by strtotime() or a Zend_Date
+     * Object.
+     *
+     * @param	integer|string|DateTimt|Zend_Date		$date	The date-entity
+     * @param	boolean									$asUtc	Whether to return the LDAP-compatible date-string
+     *                          								as UTC or as local value
+     * @return	string
+     * @throws	InvalidArgumentException
+     */
+    public static function toLdapDateTime($date, $asUtc = true)
+    {
+        if (!($date instanceof DateTime)) {
+            if (is_int($date)) {
+                $date = new DateTime('@' . $date);
+                $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
+            } else if (is_string($date)) {
+                $date = new DateTime($date);
+            } else if ($date instanceof Zend_Date) {
+                $date = new DateTime($date->get(Zend_Date::ISO_8601));
+            } else {
+                throw new InvalidArgumentException('Parameter $date is not of the expected type');
+            }
+        }
+        $timezone = $date->format('O');
+        if (true === $asUtc) {
+            $date->setTimezone(new DateTimeZone('UTC'));
+            $timezone = 'Z';
+        }
+        if ( '+0000' === $timezone ) {
+            $timezone = 'Z';
+        }
+        return $date->format('YmdHis') . $timezone;
+    }
+
+    /**
+     * Convert a boolean value to an LDAP-compatible string
+     *
+     * This converts a boolean value of TRUE, an integer-value of 1 and a
+     * case-insensitive string 'true' to an LDAP-compatible 'TRUE'. All other
+     * other values are converted to an LDAP-compatible 'FALSE'.
+     *
+     * @param	boolean|integer|string		$value	The boolean value to encode
+     * @return	string
+     */
+    public static function toLdapBoolean($value)
+    {
+        $return = 'FALSE';
+        if (!is_scalar($value)) {
+            return $return;
+        }
+        if (true === $value || 'true' === strtolower($value) || 1 === $value) {
+            $return = 'TRUE';
+        }
+        return $return;
+    }
+
+    /**
+     * Serialize any value for storage in LDAP
+     *
+     * @param	mixed		$value	The value to serialize
+     * @return	string
+     */
+    public static function toLdapSerialize($value)
+    {
+        return serialize($value);
+    }
+
+    /**
+     * Convert an LDAP-compatible value to a corresponding PHP-value.
+     *
+     * By setting the <var>$type</var>-parameter the conversion of a certain
+     * type can be forced
+     * .
+     * @param	string	$value 			The value to convert
+     * @param	int		$ytpe  			The conversion type to use
+     * @param	boolean	$dateTimeAsUtc	Return DateTime values in UTC timezone
+     * @return	mixed
+     * @throws	Zend_Ldap_Converter_Exception
+     */
+    public static function fromLdap($value, $type = self::STANDARD, $dateTimeAsUtc = true)
+    {
+        switch ($type) {
+            case self::BOOLEAN:
+                return self::fromldapBoolean($value);
+                break;
+            case self::GENERALIZED_TIME:
+                return self::fromLdapDateTime($value);
+                break;
+            default:
+                if (is_numeric($value)) {
+                    return (float)$value;
+                } else if ('TRUE' === $value || 'FALSE' === $value) {
+                    return self::fromLdapBoolean($value);
+                }
+                if (preg_match('/^\d{4}[\d\+\-Z\.]*$/', $value)) {
+                    return self::fromLdapDateTime($value, $dateTimeAsUtc);
+                }
+                try {
+                    return self::fromLdapUnserialize($value);
+                } catch (UnexpectedValueException $e) { }
+                break;
+        }
+        return $value;
+    }
+
+    /**
+     * Convert an LDAP-Generalized-Time-entry into a DateTime-Object
+     *
+     * CAVEAT: The DateTime-Object returned will alwasy be set to UTC-Timezone.
+     *
+     * @param	string		$date	The generalized-Time
+     * @param	boolean		$asUtc	Return the DateTime with UTC timezone
+     * @return	DateTime
+     * @throws	InvalidArgumentException if a non-parseable-format is given
+     */
+    public static function fromLdapDateTime($date, $asUtc = true)
+    {
+        $datepart = array ();
+        if (!preg_match('/^(\d{4})/', $date, $datepart) ) {
+            throw new InvalidArgumentException('Invalid date format found');
+        }
+
+        if ($datepart[1] < 4) {
+            throw new InvalidArgumentException('Invalid date format found (too short)');
+        }
+
+        $time = array (
+            // The year is mandatory!
+            'year'   => $datepart[1],
+            'month'  => 1,
+            'day'    => 1,
+            'hour'   => 0,
+            'minute' => 0,
+            'second' => 0,
+            'offdir' => '+',
+            'offsethours' => 0,
+			'offsetminutes' => 0
+        );
+
+        $length = strlen($date);
+
+        // Check for month.
+        if ($length >= 6) {
+            $month = substr($date, 4, 2);
+            if ($month < 1 || $month > 12) {
+                throw new InvalidArgumentException('Invalid date format found (invalid month)');
+            }
+            $time['month'] = $month;
+        }
+
+        // Check for day
+        if ($length >= 8) {
+            $day = substr($date, 6, 2);
+            if ($day < 1 || $day > 31) {
+                throw new InvalidArgumentException('Invalid date format found (invalid day)');
+            }
+            $time['day'] = $day;
+        }
+
+        // Check for Hour
+        if ($length >= 10) {
+            $hour = substr($date, 8, 2);
+            if ($hour < 0 || $hour > 23) {
+                throw new InvalidArgumentException('Invalid date format found (invalid hour)');
+            }
+            $time['hour'] = $hour;
+        }
+
+        // Check for minute
+        if ($length >= 12) {
+            $minute = substr($date, 10, 2);
+            if ($minute < 0 || $minute > 59) {
+                throw new InvalidArgumentException('Invalid date format found (invalid minute)');
+            }
+            $time['minute'] = $minute;
+        }
+
+        // Check for seconds
+        if ($length >= 14) {
+            $second = substr($date, 12, 2);
+            if ($second < 0 || $second > 59) {
+                throw new InvalidArgumentException('Invalid date format found (invalid second)');
+            }
+            $time['second'] = $second;
+        }
+
+        // Set Offset
+        $offsetRegEx = '/([Z\-\+])(\d{2}\'?){0,1}(\d{2}\'?){0,1}$/';
+        $off         = array ();
+        if (preg_match($offsetRegEx, $date, $off)) {
+            $offset = $off[1];
+            if ($offset == '+' || $offset == '-') {
+                $time['offdir'] = $offset;
+                // we have an offset, so lets calculate it.
+                if (isset($off[2])) {
+                    $offsetHours = substr($off[2], 0, 2);
+                    if ($offsetHours < 0 || $offsetHours > 12) {
+                        throw new InvalidArgumentException('Invalid date format found (invalid offset hour)');
+                    }
+                    $time['offsethours'] = $offsetHours;
+                }
+                if (isset($off[3])) {
+                    $offsetMinutes = substr($off[3], 0, 2);
+                    if ($offsetMinutes < 0 || $offsetMinutes > 59) {
+                        throw new InvalidArgumentException('Invalid date format found (invalid offset minute)');
+                    }
+                    $time['offsetminutes'] = $offsetMinutes;
+                }
+            }
+        }
+
+        // Raw-Data is present, so lets create a DateTime-Object from it.
+        $offset = $time['offdir']
+                . str_pad($time['offsethours'],2,'0',STR_PAD_LEFT)
+                . str_pad($time['offsetminutes'],2,'0',STR_PAD_LEFT);
+        $timestring = $time['year'] . '-'
+                    . str_pad($time['month'], 2, '0', STR_PAD_LEFT) . '-'
+                    . str_pad($time['day'], 2, '0', STR_PAD_LEFT) . ' '
+                    . str_pad($time['hour'], 2, '0', STR_PAD_LEFT) . ':'
+                    . str_pad($time['minute'], 2, '0', STR_PAD_LEFT) . ':'
+                    . str_pad($time['second'], 2, '0', STR_PAD_LEFT)
+                    . $time['offdir']
+                    . str_pad($time['offsethours'], 2, '0', STR_PAD_LEFT)
+                    . str_pad($time['offsetminutes'], 2, '0', STR_PAD_LEFT);
+        $date = new DateTime($timestring);
+        if ($asUtc) {
+            $date->setTimezone(new DateTimeZone('UTC'));
+        }
+        return $date;
+    }
+
+    /**
+     * Convert an LDAP-compatible boolean value into a PHP-compatible one
+     *
+     * @param	string		$value		The value to convert
+     * @return	boolean
+     * @throws	InvalidArgumentException
+     */
+    public static function fromLdapBoolean($value)
+    {
+        if ( 'TRUE' === $value ) {
+            return true;
+        } else if ( 'FALSE' === $value ) {
+            return false;
+        } else {
+            throw new InvalidArgumentException('The given value is not a boolean value');
+        }
+    }
+
+    /**
+     * Unserialize a serialized value to return the corresponding object
+     *
+     * @param	string		$value	The value to convert
+     * @return	mixed
+     * @throws	UnexpectedValueException
+     */
+    public static function fromLdapUnserialize($value)
+    {
+        $v = @unserialize($value);
+        if (false===$v && $value != 'b:0;') {
+            throw new UnexpectedValueException('The given value could not be unserialized');
+        }
+        return $v;
+    }
 }

+ 35 - 0
library/Zend/Ldap/Converter/Exception.php

@@ -0,0 +1,35 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Ldap
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
+ */
+
+/**
+ * @see Zend_Exception
+ */
+require_once 'Zend/Exception.php';
+
+/**
+ * @category   Zend
+ * @package    Zend_Ldap
+ * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Ldap_Converter_Exception extends Zend_Exception
+{
+}

+ 0 - 1
library/Zend/Ldap/Exception.php

@@ -1,5 +1,4 @@
 <?php
-
 /**
  * Zend Framework
  *

+ 160 - 0
tests/Zend/Ldap/ConverterTest.php

@@ -63,5 +63,165 @@ class Zend_Ldap_ConverterTest extends PHPUnit_Framework_TestCase
             'hijklmnopqrstuvwxyz{|}~';
         $this->assertEquals($expected, Zend_Ldap_Converter::hex32ToAsc($str));
     }
+
+	/**
+     * @dataProvider toLdapDateTimeProvider
+     */
+    public function testToLdapDateTime($convert,$expect)
+    {
+        $result = Zend_Ldap_Converter::toLdapDatetime($convert['date'], $convert['utc']);
+        $this->assertEquals( $expect,$result);
+    }
+
+    public function toLdapDateTimeProvider(){
+        include_once 'Zend/Date.php';
+        $tz = new DateTimeZone('UTC');
+        return array(
+            array(array('date'=> 0, 'utc' => true ),'19700101000000Z'),
+            array(array('date'=> new DateTime('2010-05-12 13:14:45+0300', $tz), 'utc' => false ),'20100512131445+0300'),
+            array(array('date'=> new DateTime('2010-05-12 13:14:45+0300', $tz), 'utc' => true ),'20100512101445Z'),
+            array(array('date'=> '2010-05-12 13:14:45+0300', 'utc' => false ),'20100512131445+0300'),
+            array(array('date'=> '2010-05-12 13:14:45+0300', 'utc' => true ),'20100512101445Z'),
+            array(array('date'=> new Zend_Date('2010-05-12T13:14:45+0300', Zend_Date::ISO_8601), 'utc' => true ),'20100512101445Z'),
+            array(array('date'=> new Zend_Date('2010-05-12T13:14:45+0300', Zend_Date::ISO_8601), 'utc' => false ),'20100512131445+0300'),
+            array(array('date'=> new Zend_Date('0', Zend_Date::TIMESTAMP), 'utc' => true ),'19700101000000Z'),
+        );
+    }
+
+    /**
+     * @dataProvider toLdapBooleanProvider
+     */
+    public function testToLdapBoolean($expect, $convert)
+    {
+        $this->assertEquals($expect, Zend_Ldap_Converter::toldapBoolean($convert));
+    }
+
+    public function toLdapBooleanProvider(){
+        return array (
+            array('TRUE',true),
+            array('TRUE',1),
+            array('TRUE','true'),
+            array('FALSE','false'),
+            array('FALSE', false),
+            array('FALSE', array('true')),
+            array('FALSE', array('false')),
+        );
+    }
+
+    /**
+     * @dataProvider toLdapSerializeProvider
+     */
+    public function testToLdapSerialize($expect, $convert){
+        $this->assertEquals($expect, Zend_Ldap_Converter::toLdapSerialize($convert));
+    }
+
+    public function toLdapSerializeProvider(){
+        return array(
+            array('N;', null),
+            array('i:1;', 1),
+            array('O:8:"DateTime":3:{s:4:"date";s:19:"1970-01-01 00:00:00";s:13:"timezone_type";i:1;s:8:"timezone";s:6:"+00:00";}', new DateTime('@0')),
+            array('a:3:{i:0;s:4:"test";i:1;i:1;s:3:"foo";s:3:"bar";}', array('test',1,'foo'=>'bar')),
+        );
+    }
+
+    /**
+     * @dataProvider toLdapProvider
+     */
+    public function testToLdap($expect, $convert){
+        $this->assertEquals($expect, Zend_Ldap_Converter::toLdap($convert['value'], $convert['type']));
+    }
+
+    public function toLdapProvider(){
+        return array(
+            array(null, array('value' => null,'type' => 0)),
+            array('19700101000000Z',array ('value'=> 0, 'type' => 2)),
+            array('0',array ('value'=> 0, 'type' => 0)),
+            array('FALSE',array ('value'=> 0, 'type' => 1)),
+            array('19700101000000Z',array('value'=>new Zend_Date('1970-01-01T00:00:00+0000',Zend_Date::ISO_8601),'type'=>0)),
+
+        );
+    }
+
+    /**
+     * @dataProvider fromLdapUnserializeProvider
+     */
+    public function testFromLdapUnserialize ($expect, $convert)
+    {
+        $this->assertEquals($expect, Zend_Ldap_Converter::fromLdapUnserialize($convert));
+    }
+
+    public function testFromLdapUnserializeThrowsException ()
+    {
+        $this->setExpectedException('UnexpectedValueException');
+        Zend_Ldap_Converter::fromLdapUnserialize('--');
+    }
+
+    public function fromLdapUnserializeProvider(){
+        return array (
+                array(null,'N;'),
+                array(1,'i:1;'),
+                array(false,'b:0;'),
+        );
+    }
+
+    public function testFromLdapBoolean()
+    {
+        $this->assertTrue(Zend_Ldap_Converter::fromLdapBoolean('TRUE'));
+        $this->assertFalse(Zend_Ldap_Converter::fromLdapBoolean('FALSE'));
+        $this->setExpectedException('InvalidArgumentException');
+        Zend_Ldap_Converter::fromLdapBoolean('test');
+    }
+
+    /**
+     * @dataProvider fromLdapDateTimeProvider
+     */
+    public function testFromLdapDateTime($expected, $convert, $utc)
+    {
+        if ( true === $utc ) {
+            $expected -> setTimezone(new DateTimeZone('UTC'));
+        }
+        $this->assertEquals($expected, Zend_Ldap_Converter::fromLdapDatetime($convert,$utc));
+    }
+
+    public function fromLdapDateTimeProvider ()
+    {
+        $tz = new DateTimeZone('UTC');
+        $tz = null;
+        return array (
+                array(new DateTime('2010-12-24 08:00:23+0300'),'20101224080023+0300', false),
+                array(new DateTime('2010-12-24 08:00:23+0300'),'20101224080023+03\'00\'', false),
+                array(new DateTime('2010-12-24 08:00:23+0000'),'20101224080023', false),
+                array(new DateTime('2010-12-24 08:00:00+0000'),'201012240800', false),
+                array(new DateTime('2010-12-24 08:00:00+0000'),'2010122408', false),
+                array(new DateTime('2010-12-24 00:00:00+0000'),'20101224', false),
+                array(new DateTime('2010-12-01 00:00:00+0000'),'201012', false),
+                array(new DateTime('2010-01-01 00:00:00+0000'),'2010', false),
+                array(new DateTime('2010-04-03 12:23:34+0000'), '20100403122334', true),
+        );
+    }
+
+    /**
+     * @expectedException	InvalidArgumentException
+     * @dataProvider		fromLdapDateTimeException
+     */
+    public function testFromLdapDateTimeThrowsException ($value)
+    {
+        Zend_Ldap_Converter::fromLdapDatetime($value);
+    }
+
+    public static function fromLdapDateTimeException ()
+    {
+        return array (
+                array('foobar'),
+                array('201'),
+                array('201013'),
+                array('20101232'),
+                array('2010123124'),
+                array('201012312360'),
+                array('20101231235960'),
+                array('20101231235959+13'),
+                array('20101231235959+1160'),
+            );
+    }
 }