AppleProvisioningNodeTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Tests\unit\Provisioning\Apple;
  7. use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use Sabre\DAV\PropPatch;
  10. use Test\TestCase;
  11. class AppleProvisioningNodeTest extends TestCase {
  12. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  13. private $timeFactory;
  14. /** @var AppleProvisioningNode */
  15. private $node;
  16. protected function setUp(): void {
  17. parent::setUp();
  18. $this->timeFactory = $this->createMock(ITimeFactory::class);
  19. $this->node = new AppleProvisioningNode($this->timeFactory);
  20. }
  21. public function testGetName(): void {
  22. $this->assertEquals('apple-provisioning.mobileconfig', $this->node->getName());
  23. }
  24. public function testSetName(): void {
  25. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  26. $this->expectExceptionMessage('Renaming apple-provisioning.mobileconfig is forbidden');
  27. $this->node->setName('foo');
  28. }
  29. public function testGetLastModified(): void {
  30. $this->assertEquals(null, $this->node->getLastModified());
  31. }
  32. public function testDelete(): void {
  33. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  34. $this->expectExceptionMessage('apple-provisioning.mobileconfig may not be deleted');
  35. $this->node->delete();
  36. }
  37. public function testGetProperties(): void {
  38. $this->timeFactory->expects($this->once())
  39. ->method('getDateTime')
  40. ->willReturn(new \DateTime('2000-01-01'));
  41. $this->assertEquals([
  42. '{DAV:}getcontentlength' => 42,
  43. '{DAV:}getlastmodified' => 'Sat, 01 Jan 2000 00:00:00 +0000',
  44. ], $this->node->getProperties([]));
  45. }
  46. public function testGetPropPatch(): void {
  47. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  48. $this->expectExceptionMessage('apple-provisioning.mobileconfig\'s properties may not be altered.');
  49. $propPatch = $this->createMock(PropPatch::class);
  50. $this->node->propPatch($propPatch);
  51. }
  52. }