2017-04-25 17:37:13 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Georg Ehrke <oc.list@georgehrke.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2017-11-06 17:56:42 +03:00
|
|
|
*
|
2017-04-25 17:37:13 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-04-25 17:37:13 +03:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-11-06 17:56:42 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-04-25 17:37:13 +03:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-25 17:37:13 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Search;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\CalendarHome;
|
|
|
|
use OCA\DAV\CalDAV\Search\SearchPlugin;
|
|
|
|
use OCA\DAV\CalDAV\Search\Xml\Request\CalendarSearchReport;
|
2019-11-22 11:52:58 +03:00
|
|
|
use Sabre\Xml\Service;
|
2017-04-25 17:37:13 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class SearchPluginTest extends TestCase {
|
|
|
|
|
|
|
|
protected $server;
|
|
|
|
|
|
|
|
/** @var \OCA\DAV\CalDAV\Search\SearchPlugin $plugin */
|
|
|
|
protected $plugin;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2017-04-25 17:37:13 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->server = $this->createMock(\Sabre\DAV\Server::class);
|
|
|
|
$this->server->tree = $this->createMock(\Sabre\DAV\Tree::class);
|
|
|
|
$this->server->httpResponse = $this->createMock(\Sabre\HTTP\Response::class);
|
2019-11-22 11:52:58 +03:00
|
|
|
$this->server->xml = new Service();
|
2017-04-25 17:37:13 +03:00
|
|
|
|
|
|
|
$this->plugin = new SearchPlugin();
|
|
|
|
$this->plugin->initialize($this->server);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFeatures() {
|
|
|
|
$this->assertEquals(['nc-calendar-search'], $this->plugin->getFeatures());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetName() {
|
|
|
|
$this->assertEquals('nc-calendar-search', $this->plugin->getPluginName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testInitialize() {
|
|
|
|
$server = $this->createMock(\Sabre\DAV\Server::class);
|
|
|
|
|
|
|
|
$plugin = new SearchPlugin();
|
|
|
|
|
|
|
|
$server->expects($this->at(0))
|
|
|
|
->method('on')
|
|
|
|
->with('report', [$plugin, 'report']);
|
2019-11-22 11:52:58 +03:00
|
|
|
$server->xml = new Service();
|
2017-04-25 17:37:13 +03:00
|
|
|
|
|
|
|
$plugin->initialize($server);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$server->xml->elementMap['{http://nextcloud.com/ns}calendar-search'],
|
|
|
|
'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReportUnknown() {
|
|
|
|
$result = $this->plugin->report('{urn:ietf:params:xml:ns:caldav}calendar-query', 'REPORT', null);
|
|
|
|
$this->assertEquals($result, null);
|
|
|
|
$this->assertNotEquals($this->server->transactionType, 'report-nc-calendar-search');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReport() {
|
|
|
|
$report = $this->createMock(CalendarSearchReport::class);
|
|
|
|
$report->filters = [];
|
|
|
|
$calendarHome = $this->createMock(CalendarHome::class);
|
|
|
|
$this->server->expects($this->at(0))
|
|
|
|
->method('getRequestUri')
|
|
|
|
->with()
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('/re/quest/u/r/i');
|
2017-04-25 17:37:13 +03:00
|
|
|
$this->server->tree->expects($this->at(0))
|
|
|
|
->method('getNodeForPath')
|
|
|
|
->with('/re/quest/u/r/i')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($calendarHome);
|
2017-04-25 17:37:13 +03:00
|
|
|
$this->server->expects($this->at(1))
|
|
|
|
->method('getHTTPDepth')
|
|
|
|
->with(2)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(2);
|
2019-11-22 11:52:58 +03:00
|
|
|
$this->server
|
|
|
|
->method('getHTTPPrefer')
|
|
|
|
->willReturn([
|
|
|
|
'return' => null
|
|
|
|
]);
|
2017-04-25 17:37:13 +03:00
|
|
|
$calendarHome->expects($this->at(0))
|
|
|
|
->method('calendarSearch')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([]);
|
2017-04-25 17:37:13 +03:00
|
|
|
|
|
|
|
$this->plugin->report('{http://nextcloud.com/ns}calendar-search', $report, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSupportedReportSetNoCalendarHome() {
|
|
|
|
$this->server->tree->expects($this->once())
|
|
|
|
->method('getNodeForPath')
|
|
|
|
->with('/foo/bar')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2017-04-25 17:37:13 +03:00
|
|
|
|
|
|
|
$reports = $this->plugin->getSupportedReportSet('/foo/bar');
|
|
|
|
$this->assertEquals([], $reports);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSupportedReportSet() {
|
|
|
|
$calendarHome = $this->createMock(CalendarHome::class);
|
|
|
|
|
|
|
|
$this->server->tree->expects($this->once())
|
|
|
|
->method('getNodeForPath')
|
|
|
|
->with('/bar/foo')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($calendarHome);
|
2017-04-25 17:37:13 +03:00
|
|
|
|
|
|
|
$reports = $this->plugin->getSupportedReportSet('/bar/foo');
|
|
|
|
$this->assertEquals([
|
|
|
|
'{http://nextcloud.com/ns}calendar-search'
|
|
|
|
], $reports);
|
|
|
|
}
|
|
|
|
}
|