diff options
author | Robin Appelman <robin@icewind.nl> | 2020-01-31 15:06:26 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2020-03-18 13:41:04 +0100 |
commit | ce398cf7bdfa1c4edeeee9b5259a415ef23031ac (patch) | |
tree | 3e2904a038c40a79e208c39f7c72e9632a257675 /apps/dav/tests/unit | |
parent | ca54813cbb8f4c6ab6395ef921f3de3d4a834bb3 (diff) | |
download | nextcloud-server-ce398cf7bdfa1c4edeeee9b5259a415ef23031ac.tar.gz nextcloud-server-ce398cf7bdfa1c4edeeee9b5259a415ef23031ac.zip |
merge the two almost identical custom property backends
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php | 4 | ||||
-rw-r--r-- | apps/dav/tests/unit/DAV/CustomPropertiesBackendTest.php | 36 |
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'); |