AppleProvisioningNodeTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\Tests\unit\Provisioning\Apple;
  26. use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
  27. use OCP\AppFramework\Utility\ITimeFactory;
  28. use Sabre\DAV\PropPatch;
  29. use Test\TestCase;
  30. class AppleProvisioningNodeTest extends TestCase {
  31. /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
  32. private $timeFactory;
  33. /** @var AppleProvisioningNode */
  34. private $node;
  35. protected function setUp(): void {
  36. parent::setUp();
  37. $this->timeFactory = $this->createMock(ITimeFactory::class);
  38. $this->node = new AppleProvisioningNode($this->timeFactory);
  39. }
  40. public function testGetName(): void {
  41. $this->assertEquals('apple-provisioning.mobileconfig', $this->node->getName());
  42. }
  43. public function testSetName(): void {
  44. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  45. $this->expectExceptionMessage('Renaming apple-provisioning.mobileconfig is forbidden');
  46. $this->node->setName('foo');
  47. }
  48. public function testGetLastModified(): void {
  49. $this->assertEquals(null, $this->node->getLastModified());
  50. }
  51. public function testDelete(): void {
  52. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  53. $this->expectExceptionMessage('apple-provisioning.mobileconfig may not be deleted');
  54. $this->node->delete();
  55. }
  56. public function testGetProperties(): void {
  57. $this->timeFactory->expects($this->once())
  58. ->method('getDateTime')
  59. ->willReturn(new \DateTime('2000-01-01'));
  60. $this->assertEquals([
  61. '{DAV:}getcontentlength' => 42,
  62. '{DAV:}getlastmodified' => 'Sat, 01 Jan 2000 00:00:00 +0000',
  63. ], $this->node->getProperties([]));
  64. }
  65. public function testGetPropPatch(): void {
  66. $this->expectException(\Sabre\DAV\Exception\Forbidden::class);
  67. $this->expectExceptionMessage('apple-provisioning.mobileconfig\'s properties may not be altered.');
  68. $propPatch = $this->createMock(PropPatch::class);
  69. $this->node->propPatch($propPatch);
  70. }
  71. }