2016-07-20 08:08:45 -04:00
|
|
|
<?php
|
2025-05-24 17:00:05 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2017-11-06 09:56:42 -05:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-11-06 09:56:42 -05:00
|
|
|
*/
|
2016-07-20 08:08:45 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Publishing;
|
|
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\Calendar;
|
|
|
|
|
use OCA\DAV\CalDAV\Publishing\PublishPlugin;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IConfig;
|
2016-07-20 08:08:45 -04:00
|
|
|
use OCP\IRequest;
|
2016-07-20 08:26:24 -04:00
|
|
|
use OCP\IURLGenerator;
|
2025-05-24 17:00:05 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-07-20 08:08:45 -04:00
|
|
|
use Sabre\DAV\Server;
|
|
|
|
|
use Sabre\DAV\SimpleCollection;
|
|
|
|
|
use Sabre\HTTP\Request;
|
|
|
|
|
use Sabre\HTTP\Response;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
2022-03-31 09:32:51 -04:00
|
|
|
class PublishingTest extends TestCase {
|
2025-05-24 17:00:05 -04:00
|
|
|
private PublishPlugin $plugin;
|
|
|
|
|
private Server $server;
|
|
|
|
|
private Calendar&MockObject $book;
|
|
|
|
|
private IConfig&MockObject $config;
|
|
|
|
|
private IURLGenerator&MockObject $urlGenerator;
|
2016-07-20 08:08:45 -04:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2016-07-20 08:08:45 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2025-05-24 17:00:05 -04:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2016-07-20 08:26:24 -04:00
|
|
|
$this->config->expects($this->any())->method('getSystemValue')
|
|
|
|
|
->with($this->equalTo('secret'))
|
|
|
|
|
->willReturn('mysecret');
|
|
|
|
|
|
2025-05-24 17:00:05 -04:00
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
2016-07-20 08:26:24 -04:00
|
|
|
|
2016-07-20 08:08:45 -04:00
|
|
|
/** @var IRequest $request */
|
2016-07-20 08:26:24 -04:00
|
|
|
$this->plugin = new PublishPlugin($this->config, $this->urlGenerator);
|
2016-07-20 08:08:45 -04:00
|
|
|
|
|
|
|
|
$root = new SimpleCollection('calendars');
|
|
|
|
|
$this->server = new Server($root);
|
|
|
|
|
/** @var SimpleCollection $node */
|
2017-10-24 09:26:53 -04:00
|
|
|
$this->book = $this->getMockBuilder(Calendar::class)
|
2016-07-31 14:18:35 -04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
2016-07-20 08:08:45 -04:00
|
|
|
$this->book->method('getName')->willReturn('cal1');
|
|
|
|
|
$root->addChild($this->book);
|
|
|
|
|
$this->plugin->initialize($this->server);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testPublishing(): void {
|
2016-07-20 08:08:45 -04:00
|
|
|
$this->book->expects($this->once())->method('setPublishStatus')->with(true);
|
|
|
|
|
|
|
|
|
|
// setup request
|
2020-03-10 08:43:18 -04:00
|
|
|
$request = new Request('POST', 'cal1');
|
2016-07-20 08:08:45 -04:00
|
|
|
$request->addHeader('Content-Type', 'application/xml');
|
|
|
|
|
$request->setBody('<o:publish-calendar xmlns:o="http://calendarserver.org/ns/"/>');
|
|
|
|
|
$response = new Response();
|
|
|
|
|
$this->plugin->httpPost($request, $response);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testUnPublishing(): void {
|
2016-07-20 10:08:21 -04:00
|
|
|
$this->book->expects($this->once())->method('setPublishStatus')->with(false);
|
2016-07-20 08:08:45 -04:00
|
|
|
|
|
|
|
|
// setup request
|
2020-03-10 08:43:18 -04:00
|
|
|
$request = new Request('POST', 'cal1');
|
2016-07-20 08:08:45 -04:00
|
|
|
$request->addHeader('Content-Type', 'application/xml');
|
|
|
|
|
$request->setBody('<o:unpublish-calendar xmlns:o="http://calendarserver.org/ns/"/>');
|
|
|
|
|
$response = new Response();
|
|
|
|
|
$this->plugin->httpPost($request, $response);
|
|
|
|
|
}
|
|
|
|
|
}
|