[Pkg-owncloud-commits] [php-sabredav] 43/66: Added unittests and fixed a few bugs.
David Prévot
taffit at moszumanska.debian.org
Wed May 27 13:56:51 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to tag 3.0.0-alpha1
in repository php-sabredav.
commit 1b338053c5316c348440473a9aa294dea9df60b9
Author: Evert Pot <me at evertpot.com>
Date: Wed Apr 29 00:35:02 2015 -0400
Added unittests and fixed a few bugs.
---
lib/DAV/Browser/HtmlOutputHelper.php | 2 +
lib/DAVACL/Xml/Property/Acl.php | 4 +-
tests/Sabre/DAV/Xml/Property/HrefTest.php | 28 +++++++++--
tests/Sabre/DAVACL/Xml/Property/ACLTest.php | 56 +++++++++++++++++-----
.../Xml/Property/CurrentUserPrivilegeSetTest.php | 21 +++++++-
.../Xml/Property/SupportedPrivilegeSetTest.php | 35 ++++++++++++++
6 files changed, 129 insertions(+), 17 deletions(-)
diff --git a/lib/DAV/Browser/HtmlOutputHelper.php b/lib/DAV/Browser/HtmlOutputHelper.php
index ffb1277..45f4fd3 100644
--- a/lib/DAV/Browser/HtmlOutputHelper.php
+++ b/lib/DAV/Browser/HtmlOutputHelper.php
@@ -107,6 +107,8 @@ class HtmlOutputHelper {
list($ns, $localName) = XmlService::parseClarkNotation($element);
if (isset($this->namespaceMap[$ns])) {
$propName = $this->namespaceMap[$ns] . ':' . $localName;
+ } else {
+ $propName = $element;
}
return "<span title=\"" . $this->h($element) . "\">" . $this->h($propName) . "</span>";
diff --git a/lib/DAVACL/Xml/Property/Acl.php b/lib/DAVACL/Xml/Property/Acl.php
index d0f19e3..0f65292 100644
--- a/lib/DAVACL/Xml/Property/Acl.php
+++ b/lib/DAVACL/Xml/Property/Acl.php
@@ -124,7 +124,7 @@ class Acl implements Element, HtmlOutput {
ob_start();
echo "<table>";
- echo "<tr><th>Principal</th><th>Privilege</th><th></th>";
+ echo "<tr><th>Principal</th><th>Privilege</th><th></th></tr>";
foreach($this->privileges as $privilege) {
echo '<tr>';
@@ -136,7 +136,7 @@ class Acl implements Element, HtmlOutput {
}
echo '<td>', $html->xmlName($privilege['privilege']), '</td>';
echo '<td>';
- if ($privilege['protected']) echo '(protected)';
+ if (!empty($privilege['protected'])) echo '(protected)';
echo '</td>';
echo '</tr>';
diff --git a/tests/Sabre/DAV/Xml/Property/HrefTest.php b/tests/Sabre/DAV/Xml/Property/HrefTest.php
index ef96f6d..e3a3bae 100644
--- a/tests/Sabre/DAV/Xml/Property/HrefTest.php
+++ b/tests/Sabre/DAV/Xml/Property/HrefTest.php
@@ -3,6 +3,7 @@
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV;
+use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\DAV\Xml\XmlTest;
class HrefTest extends XmlTest {
@@ -52,10 +53,10 @@ class HrefTest extends XmlTest {
$result = $this->parse($xml, ['{DAV:}anything' => 'Sabre\\DAV\\Xml\\Property\\Href']);
- $href = $result['value'];
+ $href = $result['value'];
$this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $href);
-
+
$this->assertEquals('/bla/path',$href->getHref());
}
@@ -66,7 +67,7 @@ class HrefTest extends XmlTest {
<d:anything xmlns:d="DAV:"><d:href2>/bla/path</d:href2></d:anything>
';
$result = $this->parse($xml, ['{DAV:}anything' => 'Sabre\\DAV\\Xml\\Property\\Href']);
- $href = $result['value'];
+ $href = $result['value'];
$this->assertNull($href);
}
@@ -88,4 +89,25 @@ class HrefTest extends XmlTest {
}
+ function testToHtml() {
+
+ $href = new Href([
+ '/foo/bar',
+ 'foo/bar',
+ 'http://example.org/bar'
+ ]);
+
+ $html = new HtmlOutputHelper(
+ '/base/',
+ []
+ );
+
+ $expected =
+ '<a href="/foo/bar">/foo/bar</a><br />' .
+ '<a href="/base/foo/bar">/base/foo/bar</a><br />' .
+ '<a href="http://example.org/bar">http://example.org/bar</a>';
+ $this->assertEquals($expected, $href->toHtml($html));
+
+ }
+
}
diff --git a/tests/Sabre/DAVACL/Xml/Property/ACLTest.php b/tests/Sabre/DAVACL/Xml/Property/ACLTest.php
index 559114f..2375857 100644
--- a/tests/Sabre/DAVACL/Xml/Property/ACLTest.php
+++ b/tests/Sabre/DAVACL/Xml/Property/ACLTest.php
@@ -4,6 +4,7 @@ namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV;
use Sabre\HTTP;
+use Sabre\DAV\Browser\HtmlOutputHelper;
class ACLTest extends \PHPUnit_Framework_TestCase {
@@ -28,16 +29,14 @@ class ACLTest extends \PHPUnit_Framework_TestCase {
function testSerialize() {
- $privileges = [
- [
+ $privileges = [
+ [
'principal' => 'principals/evert',
'privilege' => '{DAV:}write',
- 'uri' => 'articles',
],
- [
+ [
'principal' => 'principals/foo',
'privilege' => '{DAV:}read',
- 'uri' => 'articles',
'protected' => true,
],
];
@@ -80,17 +79,14 @@ class ACLTest extends \PHPUnit_Framework_TestCase {
array(
'principal' => '{DAV:}authenticated',
'privilege' => '{DAV:}write',
- 'uri' => 'articles',
),
array(
'principal' => '{DAV:}unauthenticated',
'privilege' => '{DAV:}write',
- 'uri' => 'articles',
),
array(
'principal' => '{DAV:}all',
'privilege' => '{DAV:}write',
- 'uri' => 'articles',
),
);
@@ -231,6 +227,7 @@ class ACLTest extends \PHPUnit_Framework_TestCase {
</d:ace>
<d:ace>
<d:grant>
+ <d:ignoreme />
<d:privilege>
<d:write/>
</d:privilege>
@@ -257,18 +254,18 @@ class ACLTest extends \PHPUnit_Framework_TestCase {
$this->assertInstanceOf('Sabre\\DAVACL\\Xml\\Property\\Acl', $result);
- $expected = [
+ $expected = [
[
'principal' => '{DAV:}authenticated',
'protected' => false,
'privilege' => '{DAV:}write',
],
- [
+ [
'principal' => '{DAV:}unauthenticated',
'protected' => false,
'privilege' => '{DAV:}write',
],
- [
+ [
'principal' => '{DAV:}all',
'protected' => false,
'privilege' => '{DAV:}write',
@@ -286,6 +283,7 @@ class ACLTest extends \PHPUnit_Framework_TestCase {
$source = '<?xml version="1.0"?>
<d:root xmlns:d="DAV:">
+ <d:ignore-me />
<d:ace>
<d:deny>
<d:privilege>
@@ -305,4 +303,40 @@ class ACLTest extends \PHPUnit_Framework_TestCase {
}
+ function testToHtml() {
+
+ $privileges = [
+ [
+ 'principal' => 'principals/evert',
+ 'privilege' => '{DAV:}write',
+ ],
+ [
+ 'principal' => 'principals/foo',
+ 'privilege' => '{http://example.org/ns}read',
+ 'protected' => true,
+ ],
+ [
+ 'principal' => '{DAV:}authenticated',
+ 'privilege' => '{DAV:}write',
+ ],
+ ];
+
+ $acl = new Acl($privileges);
+ $html = new HtmlOutputHelper(
+ '/base/',
+ ['DAV:' => 'd']
+ );
+
+ $expected =
+ '<table>' .
+ '<tr><th>Principal</th><th>Privilege</th><th></th></tr>' .
+ '<tr><td><a href="/base/principals/evert">/base/principals/evert</a></td><td><span title="{DAV:}write">d:write</span></td><td></td></tr>' .
+ '<tr><td><a href="/base/principals/foo">/base/principals/foo</a></td><td><span title="{http://example.org/ns}read">{http://example.org/ns}read</span></td><td>(protected)</td></tr>' .
+ '<tr><td><span title="{DAV:}authenticated">d:authenticated</span></td><td><span title="{DAV:}write">d:write</span></td><td></td></tr>' .
+ '</table>';
+
+ $this->assertEquals($expected, $acl->toHtml($html));
+
+ }
+
}
diff --git a/tests/Sabre/DAVACL/Xml/Property/CurrentUserPrivilegeSetTest.php b/tests/Sabre/DAVACL/Xml/Property/CurrentUserPrivilegeSetTest.php
index dd299ec..7a7141d 100644
--- a/tests/Sabre/DAVACL/Xml/Property/CurrentUserPrivilegeSetTest.php
+++ b/tests/Sabre/DAVACL/Xml/Property/CurrentUserPrivilegeSetTest.php
@@ -3,7 +3,7 @@
namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV;
-use Sabre\DAV\XMLUtil;
+use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\HTTP;
use Sabre\Xml\Reader;
@@ -42,6 +42,7 @@ XML;
<d:privilege>
<d:write-properties />
</d:privilege>
+ <d:ignoreme />
<d:privilege>
<d:read />
</d:privilege>
@@ -65,4 +66,22 @@ XML;
}
+ function testToHtml() {
+
+ $privileges = ['{DAV:}read', '{DAV:}write'];
+
+ $prop = new CurrentUserPrivilegeSet($privileges);
+ $html = new HtmlOutputHelper(
+ '/base/',
+ ['DAV:' => 'd']
+ );
+
+ $expected =
+ '<span title="{DAV:}read">d:read</span>, ' .
+ '<span title="{DAV:}write">d:write</span>';
+
+ $this->assertEquals($expected, $prop->toHtml($html));
+
+ }
+
}
diff --git a/tests/Sabre/DAVACL/Xml/Property/SupportedPrivilegeSetTest.php b/tests/Sabre/DAVACL/Xml/Property/SupportedPrivilegeSetTest.php
index acacda5..46b8ba6 100644
--- a/tests/Sabre/DAVACL/Xml/Property/SupportedPrivilegeSetTest.php
+++ b/tests/Sabre/DAVACL/Xml/Property/SupportedPrivilegeSetTest.php
@@ -4,6 +4,7 @@ namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV;
use Sabre\HTTP;
+use Sabre\DAV\Browser\HtmlOutputHelper;
class SupportedPrivilegeSetTest extends \PHPUnit_Framework_TestCase {
@@ -82,4 +83,38 @@ class SupportedPrivilegeSetTest extends \PHPUnit_Framework_TestCase {
</d:supported-privilege-set>', $xml);
}
+
+ function testToHtml() {
+
+ $prop = new SupportedPrivilegeSet([
+ 'privilege' => '{DAV:}all',
+ 'abstract' => true,
+ 'aggregates' => [
+ [
+ 'privilege' => '{DAV:}read',
+ ],
+ [
+ 'privilege' => '{DAV:}write',
+ 'description' => 'booh',
+ ],
+ ],
+ ]);
+ $html = new HtmlOutputHelper(
+ '/base/',
+ ['DAV:' => 'd']
+ );
+
+ $expected = <<<HTML
+<ul class="tree"><li><span title="{DAV:}all">d:all</span> <i>(abstract)</i>
+<ul>
+<li><span title="{DAV:}read">d:read</span></li>
+<li><span title="{DAV:}write">d:write</span> booh</li>
+</ul></li>
+</ul>
+
+HTML;
+
+ $this->assertEquals($expected, $prop->toHtml($html));
+
+ }
}
--
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