aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/lib/PHPUnitAssertions.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-05-10 17:26:44 -0700
committerredmatrix <git@macgirvin.com>2016-05-10 17:26:44 -0700
commit0b02a6d123b2014705998c94ddf3d460948d3eac (patch)
tree78ff2cab9944a4f5ab3f80ec93cbe1120de90bb2 /vendor/sabre/vobject/lib/PHPUnitAssertions.php
parent40b5b6e9d2da7ab65c8b4d38cdceac83a4d78deb (diff)
downloadvolse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.tar.gz
volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.tar.bz2
volse-hubzilla-0b02a6d123b2014705998c94ddf3d460948d3eac.zip
initial sabre upgrade (needs lots of work - to wit: authentication, redo the browser interface, and rework event export/import)
Diffstat (limited to 'vendor/sabre/vobject/lib/PHPUnitAssertions.php')
-rw-r--r--vendor/sabre/vobject/lib/PHPUnitAssertions.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/vendor/sabre/vobject/lib/PHPUnitAssertions.php b/vendor/sabre/vobject/lib/PHPUnitAssertions.php
new file mode 100644
index 000000000..87ec75e8f
--- /dev/null
+++ b/vendor/sabre/vobject/lib/PHPUnitAssertions.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace Sabre\VObject;
+
+/**
+ * PHPUnit Assertions
+ *
+ * This trait can be added to your unittest to make it easier to test iCalendar
+ * and/or vCards.
+ *
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+trait PHPUnitAssertions {
+
+ /**
+ * This method tests wether two vcards or icalendar objects are
+ * semantically identical.
+ *
+ * It supports objects being supplied as strings, streams or
+ * Sabre\VObject\Component instances.
+ *
+ * PRODID is removed from both objects as this is often changes and would
+ * just get in the way.
+ *
+ * CALSCALE will automatically get removed if it's set to GREGORIAN.
+ *
+ * Any property that has the value **ANY** will be treated as a wildcard.
+ *
+ * @param resource|string|Component $expected
+ * @param resource|string|Component $actual
+ * @param string $message
+ */
+ function assertVObjectEqualsVObject($expected, $actual, $message = '') {
+
+ $self = $this;
+ $getObj = function($input) use ($self) {
+
+ if (is_resource($input)) {
+ $input = stream_get_contents($input);
+ }
+ if (is_string($input)) {
+ $input = Reader::read($input);
+ }
+ if (!$input instanceof Component) {
+ $this->fail('Input must be a string, stream or VObject component');
+ }
+ unset($input->PRODID);
+ if ($input instanceof Component\VCalendar && (string)$input->CALSCALE === 'GREGORIAN') {
+ unset($input->CALSCALE);
+ }
+ return $input;
+
+ };
+
+ $expected = $getObj($expected)->serialize();
+ $actual = $getObj($actual)->serialize();
+
+ // Finding wildcards in expected.
+ preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\r$|m', $expected, $matches, PREG_SET_ORDER);
+
+ foreach ($matches as $match) {
+
+ $actual = preg_replace(
+ '|^' . preg_quote($match[1], '|') . ':(.*)\r$|m',
+ $match[1] . ':**ANY**' . "\r",
+ $actual
+ );
+
+ }
+
+ $this->assertEquals(
+ $expected,
+ $actual,
+ $message
+ );
+
+ }
+
+
+}