[Pkg-owncloud-commits] [php-sabre-vobject] 06/43: Support for formatting

David Prévot taffit at moszumanska.debian.org
Sat Sep 5 15:23:47 UTC 2015


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

taffit pushed a commit to tag 4.0.0-alpha2
in repository php-sabre-vobject.

commit b05b356f3f8f6156454f07971e3747f6bd9c53d4
Author: Dominik Tobschall <dominik at fruux.com>
Date:   Wed Jul 8 14:32:42 2015 +0200

    Support for formatting
---
 lib/BirthdayCalendarGenerator.php               | 24 +++++++++++++--
 tests/VObject/BirthdayCalendarGeneratorTest.php | 39 +++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/lib/BirthdayCalendarGenerator.php b/lib/BirthdayCalendarGenerator.php
index 9c2c7b8..26c62e4 100644
--- a/lib/BirthdayCalendarGenerator.php
+++ b/lib/BirthdayCalendarGenerator.php
@@ -46,6 +46,13 @@ class BirthdayCalendarGenerator {
     protected $defaultYear = 1900;
 
     /**
+     * Output format for the SUMMARY.
+     *
+     * @var string
+     */
+    protected $format = '%1$s\'s Birthday';
+
+    /**
      * Creates the generator.
      *
      * Check the setTimeRange and setObjects methods for details about the
@@ -122,6 +129,19 @@ class BirthdayCalendarGenerator {
     }
 
     /**
+     * Sets the output format for the SUMMARY
+     *
+     * @param string $format
+     *
+     * @return void
+     */
+    function setFormat($format) {
+
+        $this->format = $format;
+
+    }
+
+    /**
      * Parses the input data and returns a VCALENDAR.
      *
      * @return Component/VCalendar
@@ -163,7 +183,7 @@ class BirthdayCalendarGenerator {
 
             // Create event.
             $event = $calendar->add('VEVENT', [
-                'SUMMARY'      => $object->FN->getValue() .'\'s Birthday',
+                'SUMMARY'      => sprintf($this->format, $object->FN->getValue()),
                 'DTSTART'      => new \DateTime($object->BDAY->getValue(), $this->timeZone),
                 'RRULE'        => 'FREQ=YEARLY',
                 'TRANSP'       => 'TRANSPARENT',
@@ -181,6 +201,4 @@ class BirthdayCalendarGenerator {
 
     }
 
-
-
 }
diff --git a/tests/VObject/BirthdayCalendarGeneratorTest.php b/tests/VObject/BirthdayCalendarGeneratorTest.php
index b612c3b..3108ba6 100644
--- a/tests/VObject/BirthdayCalendarGeneratorTest.php
+++ b/tests/VObject/BirthdayCalendarGeneratorTest.php
@@ -317,4 +317,43 @@ ICS;
 
     }
 
+    function testVcardStringWithValidBirthdayLocalized() {
+
+        $input = <<<VCF
+BEGIN:VCARD
+VERSION:3.0
+N:Gump;Forrest;;Mr.
+FN:Forrest Gump
+BDAY:19850407
+UID:foo
+END:VCARD
+VCF;
+
+        $expected = <<<ICS
+BEGIN:VCALENDAR
+VERSION:2.0
+BEGIN:VEVENT
+SUMMARY:Forrest Gump's Geburtstag
+DTSTART:19850407T000000Z
+RRULE:FREQ=YEARLY
+TRANSP:TRANSPARENT
+X-SABRE-BDAY;X-SABRE-VCARD-UID=foo;X-SABRE-VCARD-FN=Forrest Gump:BDAY
+END:VEVENT
+END:VCALENDAR
+ICS;
+
+        $this->generator->setObjects($input);
+        $this->generator->setFormat('%1$s\'s Geburtstag');
+        $output = $this->generator->getResult();
+
+        $this->assertVObjEquals(
+            $expected,
+            $output
+        );
+
+        // Reset to default format
+        $this->generator->setFormat('%1$s\'s Birthday');
+
+    }
+
 }

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



More information about the Pkg-owncloud-commits mailing list