summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2020-01-31 15:06:26 +0100
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>2020-03-19 12:44:23 +0000
commitb3fd76689a51e4c1040d552e8b50b6b5b2388535 (patch)
treed82d93a8fe97bca1fcefec2d5a2fbc14fb1d5f49 /apps/dav/tests
parent8a82c4fe77f2674bd5604268af83df518c14995c (diff)
downloadnextcloud-server-b3fd76689a51e4c1040d552e8b50b6b5b2388535.tar.gz
nextcloud-server-b3fd76689a51e4c1040d552e8b50b6b5b2388535.zip
merge the two almost identical custom property backends
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php4
-rw-r--r--apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php36
2 files changed, 34 insertions, 6 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php
index 495efefa79b..855f7276502 100644
--- a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php
@@ -58,7 +58,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase {
private $tree;
/**
- * @var \OCA\DAV\Connector\Sabre\CustomPropertiesBackend
+ * @var \OCA\DAV\DAV\CustomPropertiesBackend
*/
private $plugin;
@@ -83,7 +83,7 @@ class CustomPropertiesBackendTest extends \Test\TestCase {
->method('getUID')
->will($this->returnValue($userId));
- $this->plugin = new \OCA\DAV\Connector\Sabre\CustomPropertiesBackend(
+ $this->plugin = new \OCA\DAV\DAV\CustomPropertiesBackend(
$this->tree,
\OC::$server->getDatabaseConnection(),
$this->user
diff --git a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php
index 44e5c6464a2..bbe3dcbd036 100644
--- a/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php
+++ b/apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php
@@ -24,9 +24,11 @@
namespace OCA\DAV\Tests\DAV;
+use OCA\DAV\Connector\Sabre\Node;
use OCA\DAV\DAV\CustomPropertiesBackend;
use OCP\IDBConnection;
use OCP\IUser;
+use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
use Sabre\DAV\Tree;
@@ -46,19 +48,42 @@ class CustomPropertiesBackendTest extends TestCase {
/** @var CustomPropertiesBackend | \PHPUnit_Framework_MockObject_MockObject */
private $backend;
+ /** @var (Node | \PHPUnit_Framework_MockObject_MockObject)[] */
+ private $nodes = [];
+
protected function setUp(): void {
parent::setUp();
$this->tree = $this->createMock(Tree::class);
$this->dbConnection = $this->createMock(IDBConnection::class);
$this->user = $this->createMock(IUser::class);
- $this->user->expects($this->once())
- ->method('getUID')
+ $this->user->method('getUID')
->with()
->will($this->returnValue('dummy_user_42'));
$this->backend = new CustomPropertiesBackend($this->tree,
$this->dbConnection, $this->user);
+
+ $this->tree->method('getNodeForPath')
+ ->willReturnCallback(function ($path) {
+ if (isset($this->nodes[$path])) {
+ return $this->nodes[$path];
+ } else {
+ throw new NotFound();
+ }
+ });
+ }
+
+ /**
+ * @param string $path
+ * @return Node|\PHPUnit\Framework\MockObject\MockObject
+ */
+ private function addNode($path) {
+ $node = $this->createMock(Node::class);
+ $node->method('getPath')
+ ->willReturn($path);
+ $this->nodes[$path] = $node;
+ return $node;
}
public function testPropFindNoDbCalls() {
@@ -76,6 +101,7 @@ class CustomPropertiesBackendTest extends TestCase {
$this->dbConnection->expects($this->never())
->method($this->anything());
+ $this->addNode('foo_bar_path_1337_0');
$this->backend->propFind('foo_bar_path_1337_0', $propFind);
}
@@ -88,7 +114,7 @@ class CustomPropertiesBackendTest extends TestCase {
'{DAV:}getcontentlength',
'{DAV:}getcontenttype',
'{DAV:}getetag',
- '{abc}def'
+ '{abc}def',
]));
$propFind->expects($this->at(1))
@@ -101,7 +127,7 @@ class CustomPropertiesBackendTest extends TestCase {
'{DAV:}displayname',
'{urn:ietf:params:xml:ns:caldav}calendar-description',
'{urn:ietf:params:xml:ns:caldav}calendar-timezone',
- '{abc}def'
+ '{abc}def',
]));
$statement = $this->createMock('\Doctrine\DBAL\Driver\Statement');
@@ -116,6 +142,7 @@ class CustomPropertiesBackendTest extends TestCase {
[null, null, 102])
->will($this->returnValue($statement));
+ $this->addNode('calendars/foo/bar_path_1337_0');
$this->backend->propFind('calendars/foo/bar_path_1337_0', $propFind);
}
@@ -123,6 +150,7 @@ class CustomPropertiesBackendTest extends TestCase {
* @dataProvider propPatchProvider
*/
public function testPropPatch($path, $propPatch) {
+ $this->addNode($path);
$propPatch->expects($this->once())
->method('handleRemaining');