[Pkg-owncloud-commits] [php-sabredav] 91/148: Testing deserializing GetLastModified.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 52fe21681dd92b5738e21fd1805c89be97f8488e
Author: Evert Pot <me at evertpot.com>
Date:   Tue Mar 24 12:07:04 2015 -0400

    Testing deserializing GetLastModified.
---
 lib/DAV/Xml/Property/GetLastModified.php          | 24 ++++++++++++-----------
 tests/Sabre/DAV/Xml/Property/LastModifiedTest.php | 18 +++++++++++++++++
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/lib/DAV/Xml/Property/GetLastModified.php b/lib/DAV/Xml/Property/GetLastModified.php
index 6551cf1..46c6e8e 100644
--- a/lib/DAV/Xml/Property/GetLastModified.php
+++ b/lib/DAV/Xml/Property/GetLastModified.php
@@ -6,7 +6,9 @@ use
     Sabre\Xml\Element,
     Sabre\Xml\Reader,
     Sabre\Xml\Writer,
-    Sabre\HTTP;
+    Sabre\HTTP,
+    DateTime,
+    DateTimeZone;
 
 /**
  * This property represents the {DAV:}getlastmodified property.
@@ -23,7 +25,7 @@ class GetLastModified implements Element {
     /**
      * time
      *
-     * @var \DateTime
+     * @var DateTime
      */
     public $time;
 
@@ -32,25 +34,25 @@ class GetLastModified implements Element {
      *
      * @param int|DateTime $time
      */
-    public function __construct($time) {
+    function __construct($time) {
 
-        if ($time instanceof \DateTime) {
+        if ($time instanceof DateTime) {
             $this->time = clone $time;
         } else {
-            $this->time = new \DateTime('@' . $time);
+            $this->time = new DateTime('@' . $time);
         }
 
         // Setting timezone to UTC
-        $this->time->setTimezone(new \DateTimeZone('UTC'));
+        $this->time->setTimezone(new DateTimeZone('UTC'));
 
     }
 
     /**
      * getTime
      *
-     * @return \DateTime
+     * @return DateTime
      */
-    public function getTime() {
+    function getTime() {
 
         return $this->time;
 
@@ -71,7 +73,7 @@ class GetLastModified implements Element {
      * @param Writer $writer
      * @return void
      */
-    public function xmlSerialize(Writer $writer) {
+    function xmlSerialize(Writer $writer) {
 
         $writer->write(
             HTTP\Util::toHTTPDate($this->time)
@@ -100,10 +102,10 @@ class GetLastModified implements Element {
      * @param Reader $reader
      * @return mixed
      */
-    static public function xmlDeserialize(Reader $reader) {
+    static function xmlDeserialize(Reader $reader) {
 
         return
-            new self($reader->parseInnerTree());
+            new self(new DateTime($reader->parseInnerTree()));
 
     }
 }
diff --git a/tests/Sabre/DAV/Xml/Property/LastModifiedTest.php b/tests/Sabre/DAV/Xml/Property/LastModifiedTest.php
index eb6c1c7..cd402b5 100644
--- a/tests/Sabre/DAV/Xml/Property/LastModifiedTest.php
+++ b/tests/Sabre/DAV/Xml/Property/LastModifiedTest.php
@@ -38,4 +38,22 @@ XML;
         $this->assertXmlStringEqualsXmlString($expected, $result);
 
     }
+
+    function testDeserialize() {
+
+        $input = <<<XML
+<?xml version="1.0"?>
+<d:getlastmodified xmlns:d="DAV:">Tue, 24 Mar 2015 18:47:00 GMT</d:getlastmodified>
+XML;
+
+        $elementMap = ['{DAV:}getlastmodified' => 'Sabre\DAV\Xml\Property\GetLastModified'];
+        $result = $this->parse($input, $elementMap);
+
+        $this->assertEquals(
+            new DateTime('2015-03-24 18:47:00', new DateTimeZone('UTC')),
+            $result['value']->getTime()
+        );
+
+    }
+
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list