@@ -17,172 +17,172 @@ |
||
| 17 | 17 | use Test\TestCase; |
| 18 | 18 | |
| 19 | 19 | class AccountPropertyCollectionTest extends TestCase { |
| 20 | - protected IAccountPropertyCollection $collection; |
|
| 21 | - |
|
| 22 | - protected const COLLECTION_NAME = 'my_multivalue_property'; |
|
| 23 | - |
|
| 24 | - public function setUp(): void { |
|
| 25 | - parent::setUp(); |
|
| 26 | - |
|
| 27 | - $this->collection = new AccountPropertyCollection(self::COLLECTION_NAME); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - protected function makePropertyMock(string $propertyName): IAccountProperty&MockObject { |
|
| 31 | - $mock = $this->createMock(IAccountProperty::class); |
|
| 32 | - $mock->expects($this->any()) |
|
| 33 | - ->method('getName') |
|
| 34 | - ->willReturn($propertyName); |
|
| 35 | - |
|
| 36 | - return $mock; |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function testSetAndGetProperties(): void { |
|
| 40 | - $propsBefore = $this->collection->getProperties(); |
|
| 41 | - $this->assertIsArray($propsBefore); |
|
| 42 | - $this->assertEmpty($propsBefore); |
|
| 43 | - |
|
| 44 | - $props = [ |
|
| 45 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 46 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 47 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 48 | - ]; |
|
| 49 | - |
|
| 50 | - $this->collection->setProperties($props); |
|
| 51 | - $propsAfter = $this->collection->getProperties(); |
|
| 52 | - $this->assertIsArray($propsAfter); |
|
| 53 | - $this->assertCount(count($props), $propsAfter); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - public function testSetPropertiesMixedInvalid(): void { |
|
| 57 | - $props = [ |
|
| 58 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 59 | - $this->makePropertyMock('sneaky_property'), |
|
| 60 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 61 | - ]; |
|
| 62 | - |
|
| 63 | - $this->expectException(InvalidArgumentException::class); |
|
| 64 | - $this->collection->setProperties($props); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - public function testAddProperty(): void { |
|
| 68 | - $props = [ |
|
| 69 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 70 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 71 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 72 | - ]; |
|
| 73 | - $this->collection->setProperties($props); |
|
| 74 | - |
|
| 75 | - $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 76 | - $this->collection->addProperty($additionalProperty); |
|
| 77 | - |
|
| 78 | - $propsAfter = $this->collection->getProperties(); |
|
| 79 | - $this->assertCount(count($props) + 1, $propsAfter); |
|
| 80 | - $this->assertNotFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - public function testAddPropertyInvalid(): void { |
|
| 84 | - $props = [ |
|
| 85 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 86 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 87 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 88 | - ]; |
|
| 89 | - $this->collection->setProperties($props); |
|
| 90 | - |
|
| 91 | - $additionalProperty = $this->makePropertyMock('sneaky_property'); |
|
| 92 | - $exceptionThrown = false; |
|
| 93 | - try { |
|
| 94 | - $this->collection->addProperty($additionalProperty); |
|
| 95 | - } catch (\InvalidArgumentException $e) { |
|
| 96 | - $exceptionThrown = true; |
|
| 97 | - } finally { |
|
| 98 | - $propsAfter = $this->collection->getProperties(); |
|
| 99 | - $this->assertCount(count($props), $propsAfter); |
|
| 100 | - $this->assertFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 101 | - $this->assertTrue($exceptionThrown); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function testRemoveProperty(): void { |
|
| 106 | - $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 107 | - $props = [ |
|
| 108 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 109 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 110 | - $additionalProperty, |
|
| 111 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 112 | - ]; |
|
| 113 | - $this->collection->setProperties($props); |
|
| 114 | - |
|
| 115 | - $propsBefore = $this->collection->getProperties(); |
|
| 116 | - $this->collection->removeProperty($additionalProperty); |
|
| 117 | - $propsAfter = $this->collection->getProperties(); |
|
| 118 | - |
|
| 119 | - $this->assertTrue(count($propsBefore) > count($propsAfter)); |
|
| 120 | - $this->assertCount(count($propsBefore) - 1, $propsAfter); |
|
| 121 | - $this->assertFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function testRemovePropertyNotFound(): void { |
|
| 125 | - $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 126 | - $props = [ |
|
| 127 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 128 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 129 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 130 | - ]; |
|
| 131 | - $this->collection->setProperties($props); |
|
| 132 | - |
|
| 133 | - $propsBefore = $this->collection->getProperties(); |
|
| 134 | - $this->collection->removeProperty($additionalProperty); |
|
| 135 | - $propsAfter = $this->collection->getProperties(); |
|
| 136 | - |
|
| 137 | - // no errors, gently |
|
| 138 | - $this->assertCount(count($propsBefore), $propsAfter); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function testRemovePropertyByValue(): void { |
|
| 142 | - $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 143 | - $additionalProperty->expects($this->any()) |
|
| 144 | - ->method('getValue') |
|
| 145 | - ->willReturn('Lorem ipsum'); |
|
| 146 | - |
|
| 147 | - $additionalPropertyTwo = clone $additionalProperty; |
|
| 148 | - |
|
| 149 | - $props = [ |
|
| 150 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 151 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 152 | - $additionalProperty, |
|
| 153 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 154 | - $additionalPropertyTwo |
|
| 155 | - ]; |
|
| 156 | - $this->collection->setProperties($props); |
|
| 157 | - |
|
| 158 | - $propsBefore = $this->collection->getProperties(); |
|
| 159 | - $this->collection->removePropertyByValue('Lorem ipsum'); |
|
| 160 | - $propsAfter = $this->collection->getProperties(); |
|
| 161 | - |
|
| 162 | - $this->assertTrue(count($propsBefore) > count($propsAfter)); |
|
| 163 | - $this->assertCount(count($propsBefore) - 2, $propsAfter); |
|
| 164 | - $this->assertFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 165 | - $this->assertFalse(array_search($additionalPropertyTwo, $propsAfter, true)); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - public function testRemovePropertyByValueNotFound(): void { |
|
| 169 | - $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 170 | - $additionalProperty->expects($this->any()) |
|
| 171 | - ->method('getValue') |
|
| 172 | - ->willReturn('Lorem ipsum'); |
|
| 173 | - |
|
| 174 | - $props = [ |
|
| 175 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 176 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 177 | - $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 178 | - ]; |
|
| 179 | - $this->collection->setProperties($props); |
|
| 180 | - |
|
| 181 | - $propsBefore = $this->collection->getProperties(); |
|
| 182 | - $this->collection->removePropertyByValue('Lorem ipsum'); |
|
| 183 | - $propsAfter = $this->collection->getProperties(); |
|
| 184 | - |
|
| 185 | - // no errors, gently |
|
| 186 | - $this->assertCount(count($propsBefore), $propsAfter); |
|
| 187 | - } |
|
| 20 | + protected IAccountPropertyCollection $collection; |
|
| 21 | + |
|
| 22 | + protected const COLLECTION_NAME = 'my_multivalue_property'; |
|
| 23 | + |
|
| 24 | + public function setUp(): void { |
|
| 25 | + parent::setUp(); |
|
| 26 | + |
|
| 27 | + $this->collection = new AccountPropertyCollection(self::COLLECTION_NAME); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + protected function makePropertyMock(string $propertyName): IAccountProperty&MockObject { |
|
| 31 | + $mock = $this->createMock(IAccountProperty::class); |
|
| 32 | + $mock->expects($this->any()) |
|
| 33 | + ->method('getName') |
|
| 34 | + ->willReturn($propertyName); |
|
| 35 | + |
|
| 36 | + return $mock; |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function testSetAndGetProperties(): void { |
|
| 40 | + $propsBefore = $this->collection->getProperties(); |
|
| 41 | + $this->assertIsArray($propsBefore); |
|
| 42 | + $this->assertEmpty($propsBefore); |
|
| 43 | + |
|
| 44 | + $props = [ |
|
| 45 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 46 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 47 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 48 | + ]; |
|
| 49 | + |
|
| 50 | + $this->collection->setProperties($props); |
|
| 51 | + $propsAfter = $this->collection->getProperties(); |
|
| 52 | + $this->assertIsArray($propsAfter); |
|
| 53 | + $this->assertCount(count($props), $propsAfter); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + public function testSetPropertiesMixedInvalid(): void { |
|
| 57 | + $props = [ |
|
| 58 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 59 | + $this->makePropertyMock('sneaky_property'), |
|
| 60 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 61 | + ]; |
|
| 62 | + |
|
| 63 | + $this->expectException(InvalidArgumentException::class); |
|
| 64 | + $this->collection->setProperties($props); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + public function testAddProperty(): void { |
|
| 68 | + $props = [ |
|
| 69 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 70 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 71 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 72 | + ]; |
|
| 73 | + $this->collection->setProperties($props); |
|
| 74 | + |
|
| 75 | + $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 76 | + $this->collection->addProperty($additionalProperty); |
|
| 77 | + |
|
| 78 | + $propsAfter = $this->collection->getProperties(); |
|
| 79 | + $this->assertCount(count($props) + 1, $propsAfter); |
|
| 80 | + $this->assertNotFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + public function testAddPropertyInvalid(): void { |
|
| 84 | + $props = [ |
|
| 85 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 86 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 87 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 88 | + ]; |
|
| 89 | + $this->collection->setProperties($props); |
|
| 90 | + |
|
| 91 | + $additionalProperty = $this->makePropertyMock('sneaky_property'); |
|
| 92 | + $exceptionThrown = false; |
|
| 93 | + try { |
|
| 94 | + $this->collection->addProperty($additionalProperty); |
|
| 95 | + } catch (\InvalidArgumentException $e) { |
|
| 96 | + $exceptionThrown = true; |
|
| 97 | + } finally { |
|
| 98 | + $propsAfter = $this->collection->getProperties(); |
|
| 99 | + $this->assertCount(count($props), $propsAfter); |
|
| 100 | + $this->assertFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 101 | + $this->assertTrue($exceptionThrown); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function testRemoveProperty(): void { |
|
| 106 | + $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 107 | + $props = [ |
|
| 108 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 109 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 110 | + $additionalProperty, |
|
| 111 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 112 | + ]; |
|
| 113 | + $this->collection->setProperties($props); |
|
| 114 | + |
|
| 115 | + $propsBefore = $this->collection->getProperties(); |
|
| 116 | + $this->collection->removeProperty($additionalProperty); |
|
| 117 | + $propsAfter = $this->collection->getProperties(); |
|
| 118 | + |
|
| 119 | + $this->assertTrue(count($propsBefore) > count($propsAfter)); |
|
| 120 | + $this->assertCount(count($propsBefore) - 1, $propsAfter); |
|
| 121 | + $this->assertFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function testRemovePropertyNotFound(): void { |
|
| 125 | + $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 126 | + $props = [ |
|
| 127 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 128 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 129 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 130 | + ]; |
|
| 131 | + $this->collection->setProperties($props); |
|
| 132 | + |
|
| 133 | + $propsBefore = $this->collection->getProperties(); |
|
| 134 | + $this->collection->removeProperty($additionalProperty); |
|
| 135 | + $propsAfter = $this->collection->getProperties(); |
|
| 136 | + |
|
| 137 | + // no errors, gently |
|
| 138 | + $this->assertCount(count($propsBefore), $propsAfter); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function testRemovePropertyByValue(): void { |
|
| 142 | + $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 143 | + $additionalProperty->expects($this->any()) |
|
| 144 | + ->method('getValue') |
|
| 145 | + ->willReturn('Lorem ipsum'); |
|
| 146 | + |
|
| 147 | + $additionalPropertyTwo = clone $additionalProperty; |
|
| 148 | + |
|
| 149 | + $props = [ |
|
| 150 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 151 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 152 | + $additionalProperty, |
|
| 153 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 154 | + $additionalPropertyTwo |
|
| 155 | + ]; |
|
| 156 | + $this->collection->setProperties($props); |
|
| 157 | + |
|
| 158 | + $propsBefore = $this->collection->getProperties(); |
|
| 159 | + $this->collection->removePropertyByValue('Lorem ipsum'); |
|
| 160 | + $propsAfter = $this->collection->getProperties(); |
|
| 161 | + |
|
| 162 | + $this->assertTrue(count($propsBefore) > count($propsAfter)); |
|
| 163 | + $this->assertCount(count($propsBefore) - 2, $propsAfter); |
|
| 164 | + $this->assertFalse(array_search($additionalProperty, $propsAfter, true)); |
|
| 165 | + $this->assertFalse(array_search($additionalPropertyTwo, $propsAfter, true)); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + public function testRemovePropertyByValueNotFound(): void { |
|
| 169 | + $additionalProperty = $this->makePropertyMock(self::COLLECTION_NAME); |
|
| 170 | + $additionalProperty->expects($this->any()) |
|
| 171 | + ->method('getValue') |
|
| 172 | + ->willReturn('Lorem ipsum'); |
|
| 173 | + |
|
| 174 | + $props = [ |
|
| 175 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 176 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 177 | + $this->makePropertyMock(self::COLLECTION_NAME), |
|
| 178 | + ]; |
|
| 179 | + $this->collection->setProperties($props); |
|
| 180 | + |
|
| 181 | + $propsBefore = $this->collection->getProperties(); |
|
| 182 | + $this->collection->removePropertyByValue('Lorem ipsum'); |
|
| 183 | + $propsAfter = $this->collection->getProperties(); |
|
| 184 | + |
|
| 185 | + // no errors, gently |
|
| 186 | + $this->assertCount(count($propsBefore), $propsAfter); |
|
| 187 | + } |
|
| 188 | 188 | } |
@@ -27,112 +27,112 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class HooksTest extends TestCase { |
| 29 | 29 | |
| 30 | - private LoggerInterface&MockObject $logger; |
|
| 31 | - private AccountManager&MockObject $accountManager; |
|
| 32 | - private Hooks $hooks; |
|
| 33 | - |
|
| 34 | - protected function setUp(): void { |
|
| 35 | - parent::setUp(); |
|
| 36 | - |
|
| 37 | - $this->logger = $this->createMock(LoggerInterface::class); |
|
| 38 | - $this->accountManager = $this->getMockBuilder(AccountManager::class) |
|
| 39 | - ->disableOriginalConstructor()->getMock(); |
|
| 40 | - |
|
| 41 | - $this->hooks = new Hooks($this->logger, $this->accountManager); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * @param $params |
|
| 47 | - * @param $data |
|
| 48 | - * @param $setEmail |
|
| 49 | - * @param $setDisplayName |
|
| 50 | - * @param $error |
|
| 51 | - */ |
|
| 52 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataTestChangeUserHook')] |
|
| 53 | - public function testChangeUserHook($params, $data, $setEmail, $setDisplayName, $error): void { |
|
| 54 | - if ($error) { |
|
| 55 | - $this->accountManager->expects($this->never())->method('updateAccount'); |
|
| 56 | - } else { |
|
| 57 | - $account = $this->createMock(IAccount::class); |
|
| 58 | - $this->accountManager->expects($this->atLeastOnce())->method('getAccount')->willReturn($account); |
|
| 59 | - if ($setEmail) { |
|
| 60 | - $property = $this->createMock(IAccountProperty::class); |
|
| 61 | - $property->expects($this->atLeastOnce()) |
|
| 62 | - ->method('getValue') |
|
| 63 | - ->willReturn($data[IAccountManager::PROPERTY_EMAIL]['value']); |
|
| 64 | - $property->expects($this->atLeastOnce()) |
|
| 65 | - ->method('setValue') |
|
| 66 | - ->with($params['value']); |
|
| 67 | - |
|
| 68 | - $account->expects($this->atLeastOnce()) |
|
| 69 | - ->method('getProperty') |
|
| 70 | - ->with(IAccountManager::PROPERTY_EMAIL) |
|
| 71 | - ->willReturn($property); |
|
| 72 | - |
|
| 73 | - $this->accountManager->expects($this->once()) |
|
| 74 | - ->method('updateAccount') |
|
| 75 | - ->with($account); |
|
| 76 | - } elseif ($setDisplayName) { |
|
| 77 | - $property = $this->createMock(IAccountProperty::class); |
|
| 78 | - $property->expects($this->atLeastOnce()) |
|
| 79 | - ->method('getValue') |
|
| 80 | - ->willReturn($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
| 81 | - $property->expects($this->atLeastOnce()) |
|
| 82 | - ->method('setValue') |
|
| 83 | - ->with($params['value']); |
|
| 84 | - |
|
| 85 | - $account->expects($this->atLeastOnce()) |
|
| 86 | - ->method('getProperty') |
|
| 87 | - ->with(IAccountManager::PROPERTY_DISPLAYNAME) |
|
| 88 | - ->willReturn($property); |
|
| 89 | - |
|
| 90 | - $this->accountManager->expects($this->once()) |
|
| 91 | - ->method('updateAccount') |
|
| 92 | - ->with($account); |
|
| 93 | - } else { |
|
| 94 | - $this->accountManager->expects($this->never())->method('updateAccount'); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $params['user'] = $this->createMock(IUser::class); |
|
| 99 | - $this->hooks->changeUserHook($params['user'], $params['feature'], $params['value']); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public static function dataTestChangeUserHook(): array { |
|
| 103 | - return [ |
|
| 104 | - [ |
|
| 105 | - ['feature' => '', 'value' => ''], |
|
| 106 | - [ |
|
| 107 | - IAccountManager::PROPERTY_EMAIL => ['value' => ''], |
|
| 108 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] |
|
| 109 | - ], |
|
| 110 | - false, false, true |
|
| 111 | - ], |
|
| 112 | - [ |
|
| 113 | - ['feature' => 'foo', 'value' => 'bar'], |
|
| 114 | - [ |
|
| 115 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
| 116 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |
|
| 117 | - ], |
|
| 118 | - false, false, false |
|
| 119 | - ], |
|
| 120 | - [ |
|
| 121 | - ['feature' => 'eMailAddress', 'value' => '[email protected]'], |
|
| 122 | - [ |
|
| 123 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
| 124 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |
|
| 125 | - ], |
|
| 126 | - true, false, false |
|
| 127 | - ], |
|
| 128 | - [ |
|
| 129 | - ['feature' => 'displayName', 'value' => 'newDisplayName'], |
|
| 130 | - [ |
|
| 131 | - IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
| 132 | - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |
|
| 133 | - ], |
|
| 134 | - false, true, false |
|
| 135 | - ], |
|
| 136 | - ]; |
|
| 137 | - } |
|
| 30 | + private LoggerInterface&MockObject $logger; |
|
| 31 | + private AccountManager&MockObject $accountManager; |
|
| 32 | + private Hooks $hooks; |
|
| 33 | + |
|
| 34 | + protected function setUp(): void { |
|
| 35 | + parent::setUp(); |
|
| 36 | + |
|
| 37 | + $this->logger = $this->createMock(LoggerInterface::class); |
|
| 38 | + $this->accountManager = $this->getMockBuilder(AccountManager::class) |
|
| 39 | + ->disableOriginalConstructor()->getMock(); |
|
| 40 | + |
|
| 41 | + $this->hooks = new Hooks($this->logger, $this->accountManager); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * @param $params |
|
| 47 | + * @param $data |
|
| 48 | + * @param $setEmail |
|
| 49 | + * @param $setDisplayName |
|
| 50 | + * @param $error |
|
| 51 | + */ |
|
| 52 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestChangeUserHook')] |
|
| 53 | + public function testChangeUserHook($params, $data, $setEmail, $setDisplayName, $error): void { |
|
| 54 | + if ($error) { |
|
| 55 | + $this->accountManager->expects($this->never())->method('updateAccount'); |
|
| 56 | + } else { |
|
| 57 | + $account = $this->createMock(IAccount::class); |
|
| 58 | + $this->accountManager->expects($this->atLeastOnce())->method('getAccount')->willReturn($account); |
|
| 59 | + if ($setEmail) { |
|
| 60 | + $property = $this->createMock(IAccountProperty::class); |
|
| 61 | + $property->expects($this->atLeastOnce()) |
|
| 62 | + ->method('getValue') |
|
| 63 | + ->willReturn($data[IAccountManager::PROPERTY_EMAIL]['value']); |
|
| 64 | + $property->expects($this->atLeastOnce()) |
|
| 65 | + ->method('setValue') |
|
| 66 | + ->with($params['value']); |
|
| 67 | + |
|
| 68 | + $account->expects($this->atLeastOnce()) |
|
| 69 | + ->method('getProperty') |
|
| 70 | + ->with(IAccountManager::PROPERTY_EMAIL) |
|
| 71 | + ->willReturn($property); |
|
| 72 | + |
|
| 73 | + $this->accountManager->expects($this->once()) |
|
| 74 | + ->method('updateAccount') |
|
| 75 | + ->with($account); |
|
| 76 | + } elseif ($setDisplayName) { |
|
| 77 | + $property = $this->createMock(IAccountProperty::class); |
|
| 78 | + $property->expects($this->atLeastOnce()) |
|
| 79 | + ->method('getValue') |
|
| 80 | + ->willReturn($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']); |
|
| 81 | + $property->expects($this->atLeastOnce()) |
|
| 82 | + ->method('setValue') |
|
| 83 | + ->with($params['value']); |
|
| 84 | + |
|
| 85 | + $account->expects($this->atLeastOnce()) |
|
| 86 | + ->method('getProperty') |
|
| 87 | + ->with(IAccountManager::PROPERTY_DISPLAYNAME) |
|
| 88 | + ->willReturn($property); |
|
| 89 | + |
|
| 90 | + $this->accountManager->expects($this->once()) |
|
| 91 | + ->method('updateAccount') |
|
| 92 | + ->with($account); |
|
| 93 | + } else { |
|
| 94 | + $this->accountManager->expects($this->never())->method('updateAccount'); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $params['user'] = $this->createMock(IUser::class); |
|
| 99 | + $this->hooks->changeUserHook($params['user'], $params['feature'], $params['value']); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public static function dataTestChangeUserHook(): array { |
|
| 103 | + return [ |
|
| 104 | + [ |
|
| 105 | + ['feature' => '', 'value' => ''], |
|
| 106 | + [ |
|
| 107 | + IAccountManager::PROPERTY_EMAIL => ['value' => ''], |
|
| 108 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] |
|
| 109 | + ], |
|
| 110 | + false, false, true |
|
| 111 | + ], |
|
| 112 | + [ |
|
| 113 | + ['feature' => 'foo', 'value' => 'bar'], |
|
| 114 | + [ |
|
| 115 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
| 116 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |
|
| 117 | + ], |
|
| 118 | + false, false, false |
|
| 119 | + ], |
|
| 120 | + [ |
|
| 121 | + ['feature' => 'eMailAddress', 'value' => '[email protected]'], |
|
| 122 | + [ |
|
| 123 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
| 124 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |
|
| 125 | + ], |
|
| 126 | + true, false, false |
|
| 127 | + ], |
|
| 128 | + [ |
|
| 129 | + ['feature' => 'displayName', 'value' => 'newDisplayName'], |
|
| 130 | + [ |
|
| 131 | + IAccountManager::PROPERTY_EMAIL => ['value' => '[email protected]'], |
|
| 132 | + IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName'] |
|
| 133 | + ], |
|
| 134 | + false, true, false |
|
| 135 | + ], |
|
| 136 | + ]; |
|
| 137 | + } |
|
| 138 | 138 | } |
@@ -26,274 +26,274 @@ |
||
| 26 | 26 | use Test\TestCase; |
| 27 | 27 | |
| 28 | 28 | class ManagerTest extends TestCase { |
| 29 | - private Manager $activityManager; |
|
| 30 | - |
|
| 31 | - protected IRequest&MockObject $request; |
|
| 32 | - protected IUserSession&MockObject $session; |
|
| 33 | - protected IConfig&MockObject $config; |
|
| 34 | - protected IValidator&MockObject $validator; |
|
| 35 | - protected IRichTextFormatter&MockObject $richTextFormatter; |
|
| 36 | - private ITimeFactory&MockObject $time; |
|
| 37 | - |
|
| 38 | - protected function setUp(): void { |
|
| 39 | - parent::setUp(); |
|
| 40 | - |
|
| 41 | - $this->request = $this->createMock(IRequest::class); |
|
| 42 | - $this->session = $this->createMock(IUserSession::class); |
|
| 43 | - $this->config = $this->createMock(IConfig::class); |
|
| 44 | - $this->validator = $this->createMock(IValidator::class); |
|
| 45 | - $this->richTextFormatter = $this->createMock(IRichTextFormatter::class); |
|
| 46 | - $this->time = $this->createMock(ITimeFactory::class); |
|
| 47 | - |
|
| 48 | - $this->activityManager = new Manager( |
|
| 49 | - $this->request, |
|
| 50 | - $this->session, |
|
| 51 | - $this->config, |
|
| 52 | - $this->validator, |
|
| 53 | - $this->richTextFormatter, |
|
| 54 | - $this->createMock(IL10N::class), |
|
| 55 | - $this->time, |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - $this->assertSame([], self::invokePrivate($this->activityManager, 'getConsumers')); |
|
| 59 | - |
|
| 60 | - $this->activityManager->registerConsumer(function () { |
|
| 61 | - return new NoOpConsumer(); |
|
| 62 | - }); |
|
| 63 | - |
|
| 64 | - $this->assertNotEmpty(self::invokePrivate($this->activityManager, 'getConsumers')); |
|
| 65 | - $this->assertNotEmpty(self::invokePrivate($this->activityManager, 'getConsumers')); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - public function testGetConsumers(): void { |
|
| 69 | - $consumers = self::invokePrivate($this->activityManager, 'getConsumers'); |
|
| 70 | - |
|
| 71 | - $this->assertNotEmpty($consumers); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - public function testGetConsumersInvalidConsumer(): void { |
|
| 76 | - $this->expectException(\InvalidArgumentException::class); |
|
| 77 | - |
|
| 78 | - $this->activityManager->registerConsumer(function () { |
|
| 79 | - return new \stdClass(); |
|
| 80 | - }); |
|
| 81 | - |
|
| 82 | - self::invokePrivate($this->activityManager, 'getConsumers'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public static function getUserFromTokenThrowInvalidTokenData(): array { |
|
| 86 | - return [ |
|
| 87 | - [null, []], |
|
| 88 | - ['', []], |
|
| 89 | - ['12345678901234567890123456789', []], |
|
| 90 | - ['1234567890123456789012345678901', []], |
|
| 91 | - ['123456789012345678901234567890', []], |
|
| 92 | - ['123456789012345678901234567890', ['user1', 'user2']], |
|
| 93 | - ]; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * |
|
| 98 | - * @param string $token |
|
| 99 | - * @param array $users |
|
| 100 | - */ |
|
| 101 | - #[\PHPUnit\Framework\Attributes\DataProvider('getUserFromTokenThrowInvalidTokenData')] |
|
| 102 | - public function testGetUserFromTokenThrowInvalidToken($token, $users): void { |
|
| 103 | - $this->expectException(\UnexpectedValueException::class); |
|
| 104 | - |
|
| 105 | - $this->mockRSSToken($token, $token, $users); |
|
| 106 | - self::invokePrivate($this->activityManager, 'getUserFromToken'); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public static function getUserFromTokenData(): array { |
|
| 110 | - return [ |
|
| 111 | - [null, '123456789012345678901234567890', 'user1'], |
|
| 112 | - ['user2', null, 'user2'], |
|
| 113 | - ['user2', '123456789012345678901234567890', 'user2'], |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * |
|
| 119 | - * @param string $userLoggedIn |
|
| 120 | - * @param string $token |
|
| 121 | - * @param string $expected |
|
| 122 | - */ |
|
| 123 | - #[\PHPUnit\Framework\Attributes\DataProvider('getUserFromTokenData')] |
|
| 124 | - public function testGetUserFromToken($userLoggedIn, $token, $expected): void { |
|
| 125 | - if ($userLoggedIn !== null) { |
|
| 126 | - $this->mockUserSession($userLoggedIn); |
|
| 127 | - } |
|
| 128 | - $this->mockRSSToken($token, '123456789012345678901234567890', ['user1']); |
|
| 129 | - |
|
| 130 | - $this->assertEquals($expected, $this->activityManager->getCurrentUserId()); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - protected function mockRSSToken($requestToken, $userToken, $users) { |
|
| 134 | - if ($requestToken !== null) { |
|
| 135 | - $this->request->expects($this->any()) |
|
| 136 | - ->method('getParam') |
|
| 137 | - ->with('token', '') |
|
| 138 | - ->willReturn($requestToken); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $this->config->expects($this->any()) |
|
| 142 | - ->method('getUsersForUserValue') |
|
| 143 | - ->with('activity', 'rsstoken', $userToken) |
|
| 144 | - ->willReturn($users); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - protected function mockUserSession($user) { |
|
| 148 | - $mockUser = $this->getMockBuilder(IUser::class) |
|
| 149 | - ->disableOriginalConstructor() |
|
| 150 | - ->getMock(); |
|
| 151 | - $mockUser->expects($this->any()) |
|
| 152 | - ->method('getUID') |
|
| 153 | - ->willReturn($user); |
|
| 154 | - |
|
| 155 | - $this->session->expects($this->any()) |
|
| 156 | - ->method('isLoggedIn') |
|
| 157 | - ->willReturn(true); |
|
| 158 | - $this->session->expects($this->any()) |
|
| 159 | - ->method('getUser') |
|
| 160 | - ->willReturn($mockUser); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - public function testPublishExceptionNoApp(): void { |
|
| 165 | - $this->expectException(IncompleteActivityException::class); |
|
| 166 | - |
|
| 167 | - $event = $this->activityManager->generateEvent(); |
|
| 168 | - $this->activityManager->publish($event); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - public function testPublishExceptionNoType(): void { |
|
| 173 | - $this->expectException(IncompleteActivityException::class); |
|
| 174 | - |
|
| 175 | - $event = $this->activityManager->generateEvent(); |
|
| 176 | - $event->setApp('test'); |
|
| 177 | - $this->activityManager->publish($event); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - public function testPublishExceptionNoAffectedUser(): void { |
|
| 182 | - $this->expectException(IncompleteActivityException::class); |
|
| 183 | - |
|
| 184 | - $event = $this->activityManager->generateEvent(); |
|
| 185 | - $event->setApp('test') |
|
| 186 | - ->setType('test_type'); |
|
| 187 | - $this->activityManager->publish($event); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - public function testPublishExceptionNoSubject(): void { |
|
| 192 | - $this->expectException(IncompleteActivityException::class); |
|
| 193 | - |
|
| 194 | - $event = $this->activityManager->generateEvent(); |
|
| 195 | - $event->setApp('test') |
|
| 196 | - ->setType('test_type') |
|
| 197 | - ->setAffectedUser('test_affected'); |
|
| 198 | - $this->activityManager->publish($event); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public static function dataPublish(): array { |
|
| 202 | - return [ |
|
| 203 | - [null, ''], |
|
| 204 | - ['test_author', 'test_author'], |
|
| 205 | - ]; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param string|null $author |
|
| 210 | - * @param string $expected |
|
| 211 | - */ |
|
| 212 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataPublish')] |
|
| 213 | - public function testPublish($author, $expected): void { |
|
| 214 | - if ($author !== null) { |
|
| 215 | - $authorObject = $this->getMockBuilder(IUser::class) |
|
| 216 | - ->disableOriginalConstructor() |
|
| 217 | - ->getMock(); |
|
| 218 | - $authorObject->expects($this->once()) |
|
| 219 | - ->method('getUID') |
|
| 220 | - ->willReturn($author); |
|
| 221 | - $this->session->expects($this->atLeastOnce()) |
|
| 222 | - ->method('getUser') |
|
| 223 | - ->willReturn($authorObject); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $time = time(); |
|
| 227 | - $this->time |
|
| 228 | - ->method('getTime') |
|
| 229 | - ->willReturn($time); |
|
| 230 | - |
|
| 231 | - $event = $this->activityManager->generateEvent(); |
|
| 232 | - $event->setApp('test') |
|
| 233 | - ->setType('test_type') |
|
| 234 | - ->setSubject('test_subject', []) |
|
| 235 | - ->setAffectedUser('test_affected') |
|
| 236 | - ->setObject('file', 123); |
|
| 237 | - |
|
| 238 | - $consumer = $this->getMockBuilder('OCP\Activity\IConsumer') |
|
| 239 | - ->disableOriginalConstructor() |
|
| 240 | - ->getMock(); |
|
| 241 | - $consumer->expects($this->once()) |
|
| 242 | - ->method('receive') |
|
| 243 | - ->with($event) |
|
| 244 | - ->willReturnCallback(function (IEvent $event) use ($expected, $time): void { |
|
| 245 | - $this->assertEquals($time, $event->getTimestamp(), 'Timestamp not set correctly'); |
|
| 246 | - $this->assertSame($expected, $event->getAuthor(), 'Author name not set correctly'); |
|
| 247 | - }); |
|
| 248 | - $this->activityManager->registerConsumer(function () use ($consumer) { |
|
| 249 | - return $consumer; |
|
| 250 | - }); |
|
| 251 | - |
|
| 252 | - $this->activityManager->publish($event); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - public function testPublishAllManually(): void { |
|
| 256 | - $event = $this->activityManager->generateEvent(); |
|
| 257 | - $event->setApp('test_app') |
|
| 258 | - ->setType('test_type') |
|
| 259 | - ->setAffectedUser('test_affected') |
|
| 260 | - ->setAuthor('test_author') |
|
| 261 | - ->setTimestamp(1337) |
|
| 262 | - ->setSubject('test_subject', ['test_subject_param']) |
|
| 263 | - ->setMessage('test_message', ['test_message_param']) |
|
| 264 | - ->setObject('test_object_type', 42, 'test_object_name') |
|
| 265 | - ->setLink('test_link') |
|
| 266 | - ; |
|
| 267 | - |
|
| 268 | - $consumer = $this->getMockBuilder('OCP\Activity\IConsumer') |
|
| 269 | - ->disableOriginalConstructor() |
|
| 270 | - ->getMock(); |
|
| 271 | - $consumer->expects($this->once()) |
|
| 272 | - ->method('receive') |
|
| 273 | - ->willReturnCallback(function (IEvent $event): void { |
|
| 274 | - $this->assertSame('test_app', $event->getApp(), 'App not set correctly'); |
|
| 275 | - $this->assertSame('test_type', $event->getType(), 'Type not set correctly'); |
|
| 276 | - $this->assertSame('test_affected', $event->getAffectedUser(), 'Affected user not set correctly'); |
|
| 277 | - $this->assertSame('test_author', $event->getAuthor(), 'Author not set correctly'); |
|
| 278 | - $this->assertSame(1337, $event->getTimestamp(), 'Timestamp not set correctly'); |
|
| 279 | - $this->assertSame('test_subject', $event->getSubject(), 'Subject not set correctly'); |
|
| 280 | - $this->assertSame(['test_subject_param'], $event->getSubjectParameters(), 'Subject parameter not set correctly'); |
|
| 281 | - $this->assertSame('test_message', $event->getMessage(), 'Message not set correctly'); |
|
| 282 | - $this->assertSame(['test_message_param'], $event->getMessageParameters(), 'Message parameter not set correctly'); |
|
| 283 | - $this->assertSame('test_object_type', $event->getObjectType(), 'Object type not set correctly'); |
|
| 284 | - $this->assertSame(42, $event->getObjectId(), 'Object ID not set correctly'); |
|
| 285 | - $this->assertSame('test_object_name', $event->getObjectName(), 'Object name not set correctly'); |
|
| 286 | - $this->assertSame('test_link', $event->getLink(), 'Link not set correctly'); |
|
| 287 | - }); |
|
| 288 | - $this->activityManager->registerConsumer(function () use ($consumer) { |
|
| 289 | - return $consumer; |
|
| 290 | - }); |
|
| 291 | - |
|
| 292 | - $this->activityManager->publish($event); |
|
| 293 | - } |
|
| 29 | + private Manager $activityManager; |
|
| 30 | + |
|
| 31 | + protected IRequest&MockObject $request; |
|
| 32 | + protected IUserSession&MockObject $session; |
|
| 33 | + protected IConfig&MockObject $config; |
|
| 34 | + protected IValidator&MockObject $validator; |
|
| 35 | + protected IRichTextFormatter&MockObject $richTextFormatter; |
|
| 36 | + private ITimeFactory&MockObject $time; |
|
| 37 | + |
|
| 38 | + protected function setUp(): void { |
|
| 39 | + parent::setUp(); |
|
| 40 | + |
|
| 41 | + $this->request = $this->createMock(IRequest::class); |
|
| 42 | + $this->session = $this->createMock(IUserSession::class); |
|
| 43 | + $this->config = $this->createMock(IConfig::class); |
|
| 44 | + $this->validator = $this->createMock(IValidator::class); |
|
| 45 | + $this->richTextFormatter = $this->createMock(IRichTextFormatter::class); |
|
| 46 | + $this->time = $this->createMock(ITimeFactory::class); |
|
| 47 | + |
|
| 48 | + $this->activityManager = new Manager( |
|
| 49 | + $this->request, |
|
| 50 | + $this->session, |
|
| 51 | + $this->config, |
|
| 52 | + $this->validator, |
|
| 53 | + $this->richTextFormatter, |
|
| 54 | + $this->createMock(IL10N::class), |
|
| 55 | + $this->time, |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + $this->assertSame([], self::invokePrivate($this->activityManager, 'getConsumers')); |
|
| 59 | + |
|
| 60 | + $this->activityManager->registerConsumer(function () { |
|
| 61 | + return new NoOpConsumer(); |
|
| 62 | + }); |
|
| 63 | + |
|
| 64 | + $this->assertNotEmpty(self::invokePrivate($this->activityManager, 'getConsumers')); |
|
| 65 | + $this->assertNotEmpty(self::invokePrivate($this->activityManager, 'getConsumers')); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + public function testGetConsumers(): void { |
|
| 69 | + $consumers = self::invokePrivate($this->activityManager, 'getConsumers'); |
|
| 70 | + |
|
| 71 | + $this->assertNotEmpty($consumers); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + public function testGetConsumersInvalidConsumer(): void { |
|
| 76 | + $this->expectException(\InvalidArgumentException::class); |
|
| 77 | + |
|
| 78 | + $this->activityManager->registerConsumer(function () { |
|
| 79 | + return new \stdClass(); |
|
| 80 | + }); |
|
| 81 | + |
|
| 82 | + self::invokePrivate($this->activityManager, 'getConsumers'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public static function getUserFromTokenThrowInvalidTokenData(): array { |
|
| 86 | + return [ |
|
| 87 | + [null, []], |
|
| 88 | + ['', []], |
|
| 89 | + ['12345678901234567890123456789', []], |
|
| 90 | + ['1234567890123456789012345678901', []], |
|
| 91 | + ['123456789012345678901234567890', []], |
|
| 92 | + ['123456789012345678901234567890', ['user1', 'user2']], |
|
| 93 | + ]; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * |
|
| 98 | + * @param string $token |
|
| 99 | + * @param array $users |
|
| 100 | + */ |
|
| 101 | + #[\PHPUnit\Framework\Attributes\DataProvider('getUserFromTokenThrowInvalidTokenData')] |
|
| 102 | + public function testGetUserFromTokenThrowInvalidToken($token, $users): void { |
|
| 103 | + $this->expectException(\UnexpectedValueException::class); |
|
| 104 | + |
|
| 105 | + $this->mockRSSToken($token, $token, $users); |
|
| 106 | + self::invokePrivate($this->activityManager, 'getUserFromToken'); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public static function getUserFromTokenData(): array { |
|
| 110 | + return [ |
|
| 111 | + [null, '123456789012345678901234567890', 'user1'], |
|
| 112 | + ['user2', null, 'user2'], |
|
| 113 | + ['user2', '123456789012345678901234567890', 'user2'], |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * |
|
| 119 | + * @param string $userLoggedIn |
|
| 120 | + * @param string $token |
|
| 121 | + * @param string $expected |
|
| 122 | + */ |
|
| 123 | + #[\PHPUnit\Framework\Attributes\DataProvider('getUserFromTokenData')] |
|
| 124 | + public function testGetUserFromToken($userLoggedIn, $token, $expected): void { |
|
| 125 | + if ($userLoggedIn !== null) { |
|
| 126 | + $this->mockUserSession($userLoggedIn); |
|
| 127 | + } |
|
| 128 | + $this->mockRSSToken($token, '123456789012345678901234567890', ['user1']); |
|
| 129 | + |
|
| 130 | + $this->assertEquals($expected, $this->activityManager->getCurrentUserId()); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + protected function mockRSSToken($requestToken, $userToken, $users) { |
|
| 134 | + if ($requestToken !== null) { |
|
| 135 | + $this->request->expects($this->any()) |
|
| 136 | + ->method('getParam') |
|
| 137 | + ->with('token', '') |
|
| 138 | + ->willReturn($requestToken); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $this->config->expects($this->any()) |
|
| 142 | + ->method('getUsersForUserValue') |
|
| 143 | + ->with('activity', 'rsstoken', $userToken) |
|
| 144 | + ->willReturn($users); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + protected function mockUserSession($user) { |
|
| 148 | + $mockUser = $this->getMockBuilder(IUser::class) |
|
| 149 | + ->disableOriginalConstructor() |
|
| 150 | + ->getMock(); |
|
| 151 | + $mockUser->expects($this->any()) |
|
| 152 | + ->method('getUID') |
|
| 153 | + ->willReturn($user); |
|
| 154 | + |
|
| 155 | + $this->session->expects($this->any()) |
|
| 156 | + ->method('isLoggedIn') |
|
| 157 | + ->willReturn(true); |
|
| 158 | + $this->session->expects($this->any()) |
|
| 159 | + ->method('getUser') |
|
| 160 | + ->willReturn($mockUser); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + public function testPublishExceptionNoApp(): void { |
|
| 165 | + $this->expectException(IncompleteActivityException::class); |
|
| 166 | + |
|
| 167 | + $event = $this->activityManager->generateEvent(); |
|
| 168 | + $this->activityManager->publish($event); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + public function testPublishExceptionNoType(): void { |
|
| 173 | + $this->expectException(IncompleteActivityException::class); |
|
| 174 | + |
|
| 175 | + $event = $this->activityManager->generateEvent(); |
|
| 176 | + $event->setApp('test'); |
|
| 177 | + $this->activityManager->publish($event); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + public function testPublishExceptionNoAffectedUser(): void { |
|
| 182 | + $this->expectException(IncompleteActivityException::class); |
|
| 183 | + |
|
| 184 | + $event = $this->activityManager->generateEvent(); |
|
| 185 | + $event->setApp('test') |
|
| 186 | + ->setType('test_type'); |
|
| 187 | + $this->activityManager->publish($event); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + public function testPublishExceptionNoSubject(): void { |
|
| 192 | + $this->expectException(IncompleteActivityException::class); |
|
| 193 | + |
|
| 194 | + $event = $this->activityManager->generateEvent(); |
|
| 195 | + $event->setApp('test') |
|
| 196 | + ->setType('test_type') |
|
| 197 | + ->setAffectedUser('test_affected'); |
|
| 198 | + $this->activityManager->publish($event); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public static function dataPublish(): array { |
|
| 202 | + return [ |
|
| 203 | + [null, ''], |
|
| 204 | + ['test_author', 'test_author'], |
|
| 205 | + ]; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param string|null $author |
|
| 210 | + * @param string $expected |
|
| 211 | + */ |
|
| 212 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataPublish')] |
|
| 213 | + public function testPublish($author, $expected): void { |
|
| 214 | + if ($author !== null) { |
|
| 215 | + $authorObject = $this->getMockBuilder(IUser::class) |
|
| 216 | + ->disableOriginalConstructor() |
|
| 217 | + ->getMock(); |
|
| 218 | + $authorObject->expects($this->once()) |
|
| 219 | + ->method('getUID') |
|
| 220 | + ->willReturn($author); |
|
| 221 | + $this->session->expects($this->atLeastOnce()) |
|
| 222 | + ->method('getUser') |
|
| 223 | + ->willReturn($authorObject); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $time = time(); |
|
| 227 | + $this->time |
|
| 228 | + ->method('getTime') |
|
| 229 | + ->willReturn($time); |
|
| 230 | + |
|
| 231 | + $event = $this->activityManager->generateEvent(); |
|
| 232 | + $event->setApp('test') |
|
| 233 | + ->setType('test_type') |
|
| 234 | + ->setSubject('test_subject', []) |
|
| 235 | + ->setAffectedUser('test_affected') |
|
| 236 | + ->setObject('file', 123); |
|
| 237 | + |
|
| 238 | + $consumer = $this->getMockBuilder('OCP\Activity\IConsumer') |
|
| 239 | + ->disableOriginalConstructor() |
|
| 240 | + ->getMock(); |
|
| 241 | + $consumer->expects($this->once()) |
|
| 242 | + ->method('receive') |
|
| 243 | + ->with($event) |
|
| 244 | + ->willReturnCallback(function (IEvent $event) use ($expected, $time): void { |
|
| 245 | + $this->assertEquals($time, $event->getTimestamp(), 'Timestamp not set correctly'); |
|
| 246 | + $this->assertSame($expected, $event->getAuthor(), 'Author name not set correctly'); |
|
| 247 | + }); |
|
| 248 | + $this->activityManager->registerConsumer(function () use ($consumer) { |
|
| 249 | + return $consumer; |
|
| 250 | + }); |
|
| 251 | + |
|
| 252 | + $this->activityManager->publish($event); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + public function testPublishAllManually(): void { |
|
| 256 | + $event = $this->activityManager->generateEvent(); |
|
| 257 | + $event->setApp('test_app') |
|
| 258 | + ->setType('test_type') |
|
| 259 | + ->setAffectedUser('test_affected') |
|
| 260 | + ->setAuthor('test_author') |
|
| 261 | + ->setTimestamp(1337) |
|
| 262 | + ->setSubject('test_subject', ['test_subject_param']) |
|
| 263 | + ->setMessage('test_message', ['test_message_param']) |
|
| 264 | + ->setObject('test_object_type', 42, 'test_object_name') |
|
| 265 | + ->setLink('test_link') |
|
| 266 | + ; |
|
| 267 | + |
|
| 268 | + $consumer = $this->getMockBuilder('OCP\Activity\IConsumer') |
|
| 269 | + ->disableOriginalConstructor() |
|
| 270 | + ->getMock(); |
|
| 271 | + $consumer->expects($this->once()) |
|
| 272 | + ->method('receive') |
|
| 273 | + ->willReturnCallback(function (IEvent $event): void { |
|
| 274 | + $this->assertSame('test_app', $event->getApp(), 'App not set correctly'); |
|
| 275 | + $this->assertSame('test_type', $event->getType(), 'Type not set correctly'); |
|
| 276 | + $this->assertSame('test_affected', $event->getAffectedUser(), 'Affected user not set correctly'); |
|
| 277 | + $this->assertSame('test_author', $event->getAuthor(), 'Author not set correctly'); |
|
| 278 | + $this->assertSame(1337, $event->getTimestamp(), 'Timestamp not set correctly'); |
|
| 279 | + $this->assertSame('test_subject', $event->getSubject(), 'Subject not set correctly'); |
|
| 280 | + $this->assertSame(['test_subject_param'], $event->getSubjectParameters(), 'Subject parameter not set correctly'); |
|
| 281 | + $this->assertSame('test_message', $event->getMessage(), 'Message not set correctly'); |
|
| 282 | + $this->assertSame(['test_message_param'], $event->getMessageParameters(), 'Message parameter not set correctly'); |
|
| 283 | + $this->assertSame('test_object_type', $event->getObjectType(), 'Object type not set correctly'); |
|
| 284 | + $this->assertSame(42, $event->getObjectId(), 'Object ID not set correctly'); |
|
| 285 | + $this->assertSame('test_object_name', $event->getObjectName(), 'Object name not set correctly'); |
|
| 286 | + $this->assertSame('test_link', $event->getLink(), 'Link not set correctly'); |
|
| 287 | + }); |
|
| 288 | + $this->activityManager->registerConsumer(function () use ($consumer) { |
|
| 289 | + return $consumer; |
|
| 290 | + }); |
|
| 291 | + |
|
| 292 | + $this->activityManager->publish($event); |
|
| 293 | + } |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | class NoOpConsumer implements IConsumer { |
| 297 | - public function receive(IEvent $event) { |
|
| 298 | - } |
|
| 297 | + public function receive(IEvent $event) { |
|
| 298 | + } |
|
| 299 | 299 | } |
@@ -22,97 +22,97 @@ |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | class ClassB { |
| 25 | - /** |
|
| 26 | - * ClassB constructor. |
|
| 27 | - * |
|
| 28 | - * @param Interface1 $interface1 |
|
| 29 | - */ |
|
| 30 | - public function __construct( |
|
| 31 | - public Interface1 $interface1, |
|
| 32 | - ) { |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * ClassB constructor. |
|
| 27 | + * |
|
| 28 | + * @param Interface1 $interface1 |
|
| 29 | + */ |
|
| 30 | + public function __construct( |
|
| 31 | + public Interface1 $interface1, |
|
| 32 | + ) { |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | class DIIntergrationTests extends TestCase { |
| 37 | - private DIContainer $container; |
|
| 38 | - private ServerContainer $server; |
|
| 39 | - |
|
| 40 | - protected function setUp(): void { |
|
| 41 | - parent::setUp(); |
|
| 42 | - |
|
| 43 | - $this->server = new ServerContainer(); |
|
| 44 | - $this->container = new DIContainer('App1', [], $this->server); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function testInjectFromServer(): void { |
|
| 48 | - $this->server->registerService(Interface1::class, function () { |
|
| 49 | - return new ClassA1(); |
|
| 50 | - }); |
|
| 51 | - |
|
| 52 | - $this->server->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 53 | - return new ClassB( |
|
| 54 | - $c->query(Interface1::class) |
|
| 55 | - ); |
|
| 56 | - }); |
|
| 57 | - |
|
| 58 | - /** @var ClassB $res */ |
|
| 59 | - $res = $this->container->query(ClassB::class); |
|
| 60 | - $this->assertSame(ClassA1::class, get_class($res->interface1)); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function testInjectDepFromServer(): void { |
|
| 64 | - $this->server->registerService(Interface1::class, function () { |
|
| 65 | - return new ClassA1(); |
|
| 66 | - }); |
|
| 67 | - |
|
| 68 | - $this->container->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 69 | - return new ClassB( |
|
| 70 | - $c->query(Interface1::class) |
|
| 71 | - ); |
|
| 72 | - }); |
|
| 73 | - |
|
| 74 | - /** @var ClassB $res */ |
|
| 75 | - $res = $this->container->query(ClassB::class); |
|
| 76 | - $this->assertSame(ClassA1::class, get_class($res->interface1)); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function testOverwriteDepFromServer(): void { |
|
| 80 | - $this->server->registerService(Interface1::class, function () { |
|
| 81 | - return new ClassA1(); |
|
| 82 | - }); |
|
| 83 | - |
|
| 84 | - $this->container->registerService(Interface1::class, function () { |
|
| 85 | - return new ClassA2(); |
|
| 86 | - }); |
|
| 87 | - |
|
| 88 | - $this->container->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 89 | - return new ClassB( |
|
| 90 | - $c->query(Interface1::class) |
|
| 91 | - ); |
|
| 92 | - }); |
|
| 93 | - |
|
| 94 | - /** @var ClassB $res */ |
|
| 95 | - $res = $this->container->query(ClassB::class); |
|
| 96 | - $this->assertSame(ClassA2::class, get_class($res->interface1)); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function testIgnoreOverwriteInServerClass(): void { |
|
| 100 | - $this->server->registerService(Interface1::class, function () { |
|
| 101 | - return new ClassA1(); |
|
| 102 | - }); |
|
| 103 | - |
|
| 104 | - $this->container->registerService(Interface1::class, function () { |
|
| 105 | - return new ClassA2(); |
|
| 106 | - }); |
|
| 107 | - |
|
| 108 | - $this->server->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 109 | - return new ClassB( |
|
| 110 | - $c->query(Interface1::class) |
|
| 111 | - ); |
|
| 112 | - }); |
|
| 113 | - |
|
| 114 | - /** @var ClassB $res */ |
|
| 115 | - $res = $this->container->query(ClassB::class); |
|
| 116 | - $this->assertSame(ClassA1::class, get_class($res->interface1)); |
|
| 117 | - } |
|
| 37 | + private DIContainer $container; |
|
| 38 | + private ServerContainer $server; |
|
| 39 | + |
|
| 40 | + protected function setUp(): void { |
|
| 41 | + parent::setUp(); |
|
| 42 | + |
|
| 43 | + $this->server = new ServerContainer(); |
|
| 44 | + $this->container = new DIContainer('App1', [], $this->server); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function testInjectFromServer(): void { |
|
| 48 | + $this->server->registerService(Interface1::class, function () { |
|
| 49 | + return new ClassA1(); |
|
| 50 | + }); |
|
| 51 | + |
|
| 52 | + $this->server->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 53 | + return new ClassB( |
|
| 54 | + $c->query(Interface1::class) |
|
| 55 | + ); |
|
| 56 | + }); |
|
| 57 | + |
|
| 58 | + /** @var ClassB $res */ |
|
| 59 | + $res = $this->container->query(ClassB::class); |
|
| 60 | + $this->assertSame(ClassA1::class, get_class($res->interface1)); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function testInjectDepFromServer(): void { |
|
| 64 | + $this->server->registerService(Interface1::class, function () { |
|
| 65 | + return new ClassA1(); |
|
| 66 | + }); |
|
| 67 | + |
|
| 68 | + $this->container->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 69 | + return new ClassB( |
|
| 70 | + $c->query(Interface1::class) |
|
| 71 | + ); |
|
| 72 | + }); |
|
| 73 | + |
|
| 74 | + /** @var ClassB $res */ |
|
| 75 | + $res = $this->container->query(ClassB::class); |
|
| 76 | + $this->assertSame(ClassA1::class, get_class($res->interface1)); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function testOverwriteDepFromServer(): void { |
|
| 80 | + $this->server->registerService(Interface1::class, function () { |
|
| 81 | + return new ClassA1(); |
|
| 82 | + }); |
|
| 83 | + |
|
| 84 | + $this->container->registerService(Interface1::class, function () { |
|
| 85 | + return new ClassA2(); |
|
| 86 | + }); |
|
| 87 | + |
|
| 88 | + $this->container->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 89 | + return new ClassB( |
|
| 90 | + $c->query(Interface1::class) |
|
| 91 | + ); |
|
| 92 | + }); |
|
| 93 | + |
|
| 94 | + /** @var ClassB $res */ |
|
| 95 | + $res = $this->container->query(ClassB::class); |
|
| 96 | + $this->assertSame(ClassA2::class, get_class($res->interface1)); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function testIgnoreOverwriteInServerClass(): void { |
|
| 100 | + $this->server->registerService(Interface1::class, function () { |
|
| 101 | + return new ClassA1(); |
|
| 102 | + }); |
|
| 103 | + |
|
| 104 | + $this->container->registerService(Interface1::class, function () { |
|
| 105 | + return new ClassA2(); |
|
| 106 | + }); |
|
| 107 | + |
|
| 108 | + $this->server->registerService(ClassB::class, function (SimpleContainer $c) { |
|
| 109 | + return new ClassB( |
|
| 110 | + $c->query(Interface1::class) |
|
| 111 | + ); |
|
| 112 | + }); |
|
| 113 | + |
|
| 114 | + /** @var ClassB $res */ |
|
| 115 | + $res = $this->container->query(ClassB::class); |
|
| 116 | + $this->assertSame(ClassA1::class, get_class($res->interface1)); |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -36,285 +36,285 @@ |
||
| 36 | 36 | * @method void setDatetime(\DateTimeImmutable $datetime) |
| 37 | 37 | */ |
| 38 | 38 | class TestEntity extends Entity { |
| 39 | - protected $email; |
|
| 40 | - protected $testId; |
|
| 41 | - protected $smallInt; |
|
| 42 | - protected $bigInt; |
|
| 43 | - protected $preName; |
|
| 44 | - protected $trueOrFalse; |
|
| 45 | - protected $anotherBool; |
|
| 46 | - protected $text; |
|
| 47 | - protected $longText; |
|
| 48 | - protected $time; |
|
| 49 | - protected $datetime; |
|
| 50 | - |
|
| 51 | - public function __construct( |
|
| 52 | - protected $name = null, |
|
| 53 | - ) { |
|
| 54 | - $this->addType('testId', Types::INTEGER); |
|
| 55 | - $this->addType('smallInt', Types::SMALLINT); |
|
| 56 | - $this->addType('bigInt', Types::BIGINT); |
|
| 57 | - $this->addType('anotherBool', Types::BOOLEAN); |
|
| 58 | - $this->addType('text', Types::TEXT); |
|
| 59 | - $this->addType('longText', Types::BLOB); |
|
| 60 | - $this->addType('time', Types::TIME); |
|
| 61 | - $this->addType('datetime', Types::DATETIME_IMMUTABLE); |
|
| 62 | - |
|
| 63 | - // Legacy types |
|
| 64 | - $this->addType('trueOrFalse', 'bool'); |
|
| 65 | - $this->addType('legacyInt', 'int'); |
|
| 66 | - $this->addType('doubleNowFloat', 'double'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function setAnotherBool(bool $anotherBool): void { |
|
| 70 | - parent::setAnotherBool($anotherBool); |
|
| 71 | - } |
|
| 39 | + protected $email; |
|
| 40 | + protected $testId; |
|
| 41 | + protected $smallInt; |
|
| 42 | + protected $bigInt; |
|
| 43 | + protected $preName; |
|
| 44 | + protected $trueOrFalse; |
|
| 45 | + protected $anotherBool; |
|
| 46 | + protected $text; |
|
| 47 | + protected $longText; |
|
| 48 | + protected $time; |
|
| 49 | + protected $datetime; |
|
| 50 | + |
|
| 51 | + public function __construct( |
|
| 52 | + protected $name = null, |
|
| 53 | + ) { |
|
| 54 | + $this->addType('testId', Types::INTEGER); |
|
| 55 | + $this->addType('smallInt', Types::SMALLINT); |
|
| 56 | + $this->addType('bigInt', Types::BIGINT); |
|
| 57 | + $this->addType('anotherBool', Types::BOOLEAN); |
|
| 58 | + $this->addType('text', Types::TEXT); |
|
| 59 | + $this->addType('longText', Types::BLOB); |
|
| 60 | + $this->addType('time', Types::TIME); |
|
| 61 | + $this->addType('datetime', Types::DATETIME_IMMUTABLE); |
|
| 62 | + |
|
| 63 | + // Legacy types |
|
| 64 | + $this->addType('trueOrFalse', 'bool'); |
|
| 65 | + $this->addType('legacyInt', 'int'); |
|
| 66 | + $this->addType('doubleNowFloat', 'double'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function setAnotherBool(bool $anotherBool): void { |
|
| 70 | + parent::setAnotherBool($anotherBool); |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | class EntityTest extends \Test\TestCase { |
| 76 | - private TestEntity $entity; |
|
| 76 | + private TestEntity $entity; |
|
| 77 | 77 | |
| 78 | - protected function setUp(): void { |
|
| 79 | - parent::setUp(); |
|
| 80 | - $this->entity = new TestEntity(); |
|
| 81 | - } |
|
| 78 | + protected function setUp(): void { |
|
| 79 | + parent::setUp(); |
|
| 80 | + $this->entity = new TestEntity(); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | 83 | |
| 84 | - public function testResetUpdatedFields(): void { |
|
| 85 | - $entity = new TestEntity(); |
|
| 86 | - $entity->setId(3); |
|
| 87 | - $entity->resetUpdatedFields(); |
|
| 84 | + public function testResetUpdatedFields(): void { |
|
| 85 | + $entity = new TestEntity(); |
|
| 86 | + $entity->setId(3); |
|
| 87 | + $entity->resetUpdatedFields(); |
|
| 88 | 88 | |
| 89 | - $this->assertEquals([], $entity->getUpdatedFields()); |
|
| 90 | - } |
|
| 89 | + $this->assertEquals([], $entity->getUpdatedFields()); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | |
| 93 | - public function testFromRow(): void { |
|
| 94 | - $row = [ |
|
| 95 | - 'pre_name' => 'john', |
|
| 96 | - 'email' => '[email protected]', |
|
| 97 | - 'another_bool' => 1, |
|
| 98 | - ]; |
|
| 99 | - $this->entity = TestEntity::fromRow($row); |
|
| 93 | + public function testFromRow(): void { |
|
| 94 | + $row = [ |
|
| 95 | + 'pre_name' => 'john', |
|
| 96 | + 'email' => '[email protected]', |
|
| 97 | + 'another_bool' => 1, |
|
| 98 | + ]; |
|
| 99 | + $this->entity = TestEntity::fromRow($row); |
|
| 100 | 100 | |
| 101 | - $this->assertEquals($row['pre_name'], $this->entity->getPreName()); |
|
| 102 | - $this->assertEquals($row['email'], $this->entity->getEmail()); |
|
| 103 | - $this->assertEquals($row['another_bool'], $this->entity->getAnotherBool()); |
|
| 104 | - } |
|
| 101 | + $this->assertEquals($row['pre_name'], $this->entity->getPreName()); |
|
| 102 | + $this->assertEquals($row['email'], $this->entity->getEmail()); |
|
| 103 | + $this->assertEquals($row['another_bool'], $this->entity->getAnotherBool()); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | - public function testGetSetId(): void { |
|
| 108 | - $id = 3; |
|
| 109 | - $this->entity->setId(3); |
|
| 107 | + public function testGetSetId(): void { |
|
| 108 | + $id = 3; |
|
| 109 | + $this->entity->setId(3); |
|
| 110 | 110 | |
| 111 | - $this->assertEquals($id, $this->entity->getId()); |
|
| 112 | - } |
|
| 111 | + $this->assertEquals($id, $this->entity->getId()); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - public function testColumnToPropertyNoReplacement(): void { |
|
| 116 | - $column = 'my'; |
|
| 117 | - $this->assertEquals('my', |
|
| 118 | - $this->entity->columnToProperty($column)); |
|
| 119 | - } |
|
| 115 | + public function testColumnToPropertyNoReplacement(): void { |
|
| 116 | + $column = 'my'; |
|
| 117 | + $this->assertEquals('my', |
|
| 118 | + $this->entity->columnToProperty($column)); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - public function testColumnToProperty(): void { |
|
| 123 | - $column = 'my_attribute'; |
|
| 124 | - $this->assertEquals('myAttribute', |
|
| 125 | - $this->entity->columnToProperty($column)); |
|
| 126 | - } |
|
| 122 | + public function testColumnToProperty(): void { |
|
| 123 | + $column = 'my_attribute'; |
|
| 124 | + $this->assertEquals('myAttribute', |
|
| 125 | + $this->entity->columnToProperty($column)); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | |
| 129 | - public function testPropertyToColumnNoReplacement(): void { |
|
| 130 | - $property = 'my'; |
|
| 131 | - $this->assertEquals('my', |
|
| 132 | - $this->entity->propertyToColumn($property)); |
|
| 133 | - } |
|
| 129 | + public function testPropertyToColumnNoReplacement(): void { |
|
| 130 | + $property = 'my'; |
|
| 131 | + $this->assertEquals('my', |
|
| 132 | + $this->entity->propertyToColumn($property)); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - public function testSetterMarksFieldUpdated(): void { |
|
| 137 | - $this->entity->setId(3); |
|
| 136 | + public function testSetterMarksFieldUpdated(): void { |
|
| 137 | + $this->entity->setId(3); |
|
| 138 | 138 | |
| 139 | - $this->assertContains('id', array_keys($this->entity->getUpdatedFields())); |
|
| 140 | - } |
|
| 139 | + $this->assertContains('id', array_keys($this->entity->getUpdatedFields())); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | |
| 144 | - public function testCallShouldOnlyWorkForGetterSetter(): void { |
|
| 145 | - $this->expectException(\BadFunctionCallException::class); |
|
| 144 | + public function testCallShouldOnlyWorkForGetterSetter(): void { |
|
| 145 | + $this->expectException(\BadFunctionCallException::class); |
|
| 146 | 146 | |
| 147 | - $this->entity->something(); |
|
| 148 | - } |
|
| 147 | + $this->entity->something(); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | 150 | |
| 151 | 151 | |
| 152 | - public function testGetterShouldFailIfAttributeNotDefined(): void { |
|
| 153 | - $this->expectException(\BadFunctionCallException::class); |
|
| 152 | + public function testGetterShouldFailIfAttributeNotDefined(): void { |
|
| 153 | + $this->expectException(\BadFunctionCallException::class); |
|
| 154 | 154 | |
| 155 | - $this->entity->getTest(); |
|
| 156 | - } |
|
| 155 | + $this->entity->getTest(); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | - public function testSetterShouldFailIfAttributeNotDefined(): void { |
|
| 160 | - $this->expectException(\BadFunctionCallException::class); |
|
| 159 | + public function testSetterShouldFailIfAttributeNotDefined(): void { |
|
| 160 | + $this->expectException(\BadFunctionCallException::class); |
|
| 161 | 161 | |
| 162 | - $this->entity->setTest(); |
|
| 163 | - } |
|
| 162 | + $this->entity->setTest(); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | 165 | |
| 166 | - public function testFromRowShouldNotAssignEmptyArray(): void { |
|
| 167 | - $row = []; |
|
| 168 | - $entity2 = new TestEntity(); |
|
| 166 | + public function testFromRowShouldNotAssignEmptyArray(): void { |
|
| 167 | + $row = []; |
|
| 168 | + $entity2 = new TestEntity(); |
|
| 169 | 169 | |
| 170 | - $this->entity = TestEntity::fromRow($row); |
|
| 171 | - $this->assertEquals($entity2, $this->entity); |
|
| 172 | - } |
|
| 170 | + $this->entity = TestEntity::fromRow($row); |
|
| 171 | + $this->assertEquals($entity2, $this->entity); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | |
| 175 | - public function testIdGetsConvertedToInt(): void { |
|
| 176 | - $row = ['id' => '4']; |
|
| 175 | + public function testIdGetsConvertedToInt(): void { |
|
| 176 | + $row = ['id' => '4']; |
|
| 177 | 177 | |
| 178 | - $this->entity = TestEntity::fromRow($row); |
|
| 179 | - $this->assertSame(4, $this->entity->getId()); |
|
| 180 | - } |
|
| 178 | + $this->entity = TestEntity::fromRow($row); |
|
| 179 | + $this->assertSame(4, $this->entity->getId()); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | 182 | |
| 183 | - public function testSetType(): void { |
|
| 184 | - $row = ['testId' => '4']; |
|
| 183 | + public function testSetType(): void { |
|
| 184 | + $row = ['testId' => '4']; |
|
| 185 | 185 | |
| 186 | - $this->entity = TestEntity::fromRow($row); |
|
| 187 | - $this->assertSame(4, $this->entity->getTestId()); |
|
| 188 | - } |
|
| 186 | + $this->entity = TestEntity::fromRow($row); |
|
| 187 | + $this->assertSame(4, $this->entity->getTestId()); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | - public function testFromParams(): void { |
|
| 192 | - $params = [ |
|
| 193 | - 'testId' => 4, |
|
| 194 | - 'email' => 'john@doe' |
|
| 195 | - ]; |
|
| 191 | + public function testFromParams(): void { |
|
| 192 | + $params = [ |
|
| 193 | + 'testId' => 4, |
|
| 194 | + 'email' => 'john@doe' |
|
| 195 | + ]; |
|
| 196 | 196 | |
| 197 | - $entity = TestEntity::fromParams($params); |
|
| 197 | + $entity = TestEntity::fromParams($params); |
|
| 198 | 198 | |
| 199 | - $this->assertEquals($params['testId'], $entity->getTestId()); |
|
| 200 | - $this->assertEquals($params['email'], $entity->getEmail()); |
|
| 201 | - $this->assertTrue($entity instanceof TestEntity); |
|
| 202 | - } |
|
| 199 | + $this->assertEquals($params['testId'], $entity->getTestId()); |
|
| 200 | + $this->assertEquals($params['email'], $entity->getEmail()); |
|
| 201 | + $this->assertTrue($entity instanceof TestEntity); |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - public function testSlugify(): void { |
|
| 205 | - $entity = new TestEntity(); |
|
| 206 | - $entity->setName('Slugify this!'); |
|
| 207 | - $this->assertEquals('slugify-this', $entity->slugify('name')); |
|
| 208 | - $entity->setName('°!"§$%&/()=?`´ß\}][{³²#\'+~*-_.:,;<>|äöüÄÖÜSlugify this!'); |
|
| 209 | - $this->assertEquals('slugify-this', $entity->slugify('name')); |
|
| 210 | - } |
|
| 204 | + public function testSlugify(): void { |
|
| 205 | + $entity = new TestEntity(); |
|
| 206 | + $entity->setName('Slugify this!'); |
|
| 207 | + $this->assertEquals('slugify-this', $entity->slugify('name')); |
|
| 208 | + $entity->setName('°!"§$%&/()=?`´ß\}][{³²#\'+~*-_.:,;<>|äöüÄÖÜSlugify this!'); |
|
| 209 | + $this->assertEquals('slugify-this', $entity->slugify('name')); |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | 212 | |
| 213 | - public static function dataSetterCasts(): array { |
|
| 214 | - return [ |
|
| 215 | - ['Id', '3', 3], |
|
| 216 | - ['smallInt', '3', 3], |
|
| 217 | - ['bigInt', '' . PHP_INT_MAX, PHP_INT_MAX], |
|
| 218 | - ['trueOrFalse', 0, false], |
|
| 219 | - ['trueOrFalse', 1, true], |
|
| 220 | - ['anotherBool', 0, false], |
|
| 221 | - ['anotherBool', 1, true], |
|
| 222 | - ['text', 33, '33'], |
|
| 223 | - ['longText', PHP_INT_MAX, '' . PHP_INT_MAX], |
|
| 224 | - ]; |
|
| 225 | - } |
|
| 213 | + public static function dataSetterCasts(): array { |
|
| 214 | + return [ |
|
| 215 | + ['Id', '3', 3], |
|
| 216 | + ['smallInt', '3', 3], |
|
| 217 | + ['bigInt', '' . PHP_INT_MAX, PHP_INT_MAX], |
|
| 218 | + ['trueOrFalse', 0, false], |
|
| 219 | + ['trueOrFalse', 1, true], |
|
| 220 | + ['anotherBool', 0, false], |
|
| 221 | + ['anotherBool', 1, true], |
|
| 222 | + ['text', 33, '33'], |
|
| 223 | + ['longText', PHP_INT_MAX, '' . PHP_INT_MAX], |
|
| 224 | + ]; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | 227 | |
| 228 | - #[\PHPUnit\Framework\Attributes\DataProvider('dataSetterCasts')] |
|
| 229 | - public function testSetterCasts(string $field, mixed $in, mixed $out): void { |
|
| 230 | - $entity = new TestEntity(); |
|
| 231 | - $entity->{'set' . $field}($in); |
|
| 232 | - $this->assertSame($out, $entity->{'get' . $field}()); |
|
| 233 | - } |
|
| 228 | + #[\PHPUnit\Framework\Attributes\DataProvider('dataSetterCasts')] |
|
| 229 | + public function testSetterCasts(string $field, mixed $in, mixed $out): void { |
|
| 230 | + $entity = new TestEntity(); |
|
| 231 | + $entity->{'set' . $field}($in); |
|
| 232 | + $this->assertSame($out, $entity->{'get' . $field}()); |
|
| 233 | + } |
|
| 234 | 234 | |
| 235 | 235 | |
| 236 | - public function testSetterDoesNotCastOnNull(): void { |
|
| 237 | - $entity = new TestEntity(); |
|
| 238 | - $entity->setId(null); |
|
| 239 | - $this->assertSame(null, $entity->getId()); |
|
| 240 | - } |
|
| 236 | + public function testSetterDoesNotCastOnNull(): void { |
|
| 237 | + $entity = new TestEntity(); |
|
| 238 | + $entity->setId(null); |
|
| 239 | + $this->assertSame(null, $entity->getId()); |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - public function testSetterConvertsResourcesToStringProperly(): void { |
|
| 243 | - $string = 'Definitely a string'; |
|
| 244 | - $stream = fopen('php://memory', 'r+'); |
|
| 245 | - fwrite($stream, $string); |
|
| 246 | - rewind($stream); |
|
| 247 | - |
|
| 248 | - $entity = new TestEntity(); |
|
| 249 | - $entity->setLongText($stream); |
|
| 250 | - fclose($stream); |
|
| 251 | - $this->assertSame($string, $entity->getLongText()); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - public function testSetterConvertsDatetime() { |
|
| 255 | - $entity = new TestEntity(); |
|
| 256 | - $entity->setDatetime('2024-08-19 15:26:00'); |
|
| 257 | - $this->assertEquals(new \DateTimeImmutable('2024-08-19 15:26:00'), $entity->getDatetime()); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - public function testSetterDoesNotConvertNullOnDatetime() { |
|
| 261 | - $entity = new TestEntity(); |
|
| 262 | - $entity->setDatetime(null); |
|
| 263 | - $this->assertNull($entity->getDatetime()); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - public function testSetterConvertsTime() { |
|
| 267 | - $entity = new TestEntity(); |
|
| 268 | - $entity->setTime('15:26:00'); |
|
| 269 | - $this->assertEquals(new \DateTime('15:26:00'), $entity->getTime()); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - public function testGetFieldTypes(): void { |
|
| 273 | - $entity = new TestEntity(); |
|
| 274 | - $this->assertEquals([ |
|
| 275 | - 'id' => Types::INTEGER, |
|
| 276 | - 'testId' => Types::INTEGER, |
|
| 277 | - 'smallInt' => Types::SMALLINT, |
|
| 278 | - 'bigInt' => Types::BIGINT, |
|
| 279 | - 'anotherBool' => Types::BOOLEAN, |
|
| 280 | - 'text' => Types::TEXT, |
|
| 281 | - 'longText' => Types::BLOB, |
|
| 282 | - 'time' => Types::TIME, |
|
| 283 | - 'datetime' => Types::DATETIME_IMMUTABLE, |
|
| 284 | - 'trueOrFalse' => Types::BOOLEAN, |
|
| 285 | - 'legacyInt' => Types::INTEGER, |
|
| 286 | - 'doubleNowFloat' => Types::FLOAT, |
|
| 287 | - ], $entity->getFieldTypes()); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - public function testGetItInt(): void { |
|
| 292 | - $entity = new TestEntity(); |
|
| 293 | - $entity->setId(3); |
|
| 294 | - $this->assertEquals(Types::INTEGER, gettype($entity->getId())); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - public function testFieldsNotMarkedUpdatedIfNothingChanges(): void { |
|
| 299 | - $entity = new TestEntity('hey'); |
|
| 300 | - $entity->setName('hey'); |
|
| 301 | - $this->assertEquals(0, count($entity->getUpdatedFields())); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - public function testIsGetter(): void { |
|
| 305 | - $entity = new TestEntity(); |
|
| 306 | - $entity->setTrueOrFalse(false); |
|
| 307 | - $entity->setAnotherBool(false); |
|
| 308 | - $this->assertThat($entity->isTrueOrFalse(), new IsType(IsType::TYPE_BOOL)); |
|
| 309 | - $this->assertThat($entity->isAnotherBool(), new IsType(IsType::TYPE_BOOL)); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - public function testIsGetterShoudFailForOtherType(): void { |
|
| 314 | - $this->expectException(\BadFunctionCallException::class); |
|
| 315 | - |
|
| 316 | - $entity = new TestEntity(); |
|
| 317 | - $entity->setName('hello'); |
|
| 318 | - $this->assertThat($entity->isName(), new IsType(IsType::TYPE_BOOL)); |
|
| 319 | - } |
|
| 242 | + public function testSetterConvertsResourcesToStringProperly(): void { |
|
| 243 | + $string = 'Definitely a string'; |
|
| 244 | + $stream = fopen('php://memory', 'r+'); |
|
| 245 | + fwrite($stream, $string); |
|
| 246 | + rewind($stream); |
|
| 247 | + |
|
| 248 | + $entity = new TestEntity(); |
|
| 249 | + $entity->setLongText($stream); |
|
| 250 | + fclose($stream); |
|
| 251 | + $this->assertSame($string, $entity->getLongText()); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + public function testSetterConvertsDatetime() { |
|
| 255 | + $entity = new TestEntity(); |
|
| 256 | + $entity->setDatetime('2024-08-19 15:26:00'); |
|
| 257 | + $this->assertEquals(new \DateTimeImmutable('2024-08-19 15:26:00'), $entity->getDatetime()); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + public function testSetterDoesNotConvertNullOnDatetime() { |
|
| 261 | + $entity = new TestEntity(); |
|
| 262 | + $entity->setDatetime(null); |
|
| 263 | + $this->assertNull($entity->getDatetime()); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + public function testSetterConvertsTime() { |
|
| 267 | + $entity = new TestEntity(); |
|
| 268 | + $entity->setTime('15:26:00'); |
|
| 269 | + $this->assertEquals(new \DateTime('15:26:00'), $entity->getTime()); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + public function testGetFieldTypes(): void { |
|
| 273 | + $entity = new TestEntity(); |
|
| 274 | + $this->assertEquals([ |
|
| 275 | + 'id' => Types::INTEGER, |
|
| 276 | + 'testId' => Types::INTEGER, |
|
| 277 | + 'smallInt' => Types::SMALLINT, |
|
| 278 | + 'bigInt' => Types::BIGINT, |
|
| 279 | + 'anotherBool' => Types::BOOLEAN, |
|
| 280 | + 'text' => Types::TEXT, |
|
| 281 | + 'longText' => Types::BLOB, |
|
| 282 | + 'time' => Types::TIME, |
|
| 283 | + 'datetime' => Types::DATETIME_IMMUTABLE, |
|
| 284 | + 'trueOrFalse' => Types::BOOLEAN, |
|
| 285 | + 'legacyInt' => Types::INTEGER, |
|
| 286 | + 'doubleNowFloat' => Types::FLOAT, |
|
| 287 | + ], $entity->getFieldTypes()); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + public function testGetItInt(): void { |
|
| 292 | + $entity = new TestEntity(); |
|
| 293 | + $entity->setId(3); |
|
| 294 | + $this->assertEquals(Types::INTEGER, gettype($entity->getId())); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + public function testFieldsNotMarkedUpdatedIfNothingChanges(): void { |
|
| 299 | + $entity = new TestEntity('hey'); |
|
| 300 | + $entity->setName('hey'); |
|
| 301 | + $this->assertEquals(0, count($entity->getUpdatedFields())); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + public function testIsGetter(): void { |
|
| 305 | + $entity = new TestEntity(); |
|
| 306 | + $entity->setTrueOrFalse(false); |
|
| 307 | + $entity->setAnotherBool(false); |
|
| 308 | + $this->assertThat($entity->isTrueOrFalse(), new IsType(IsType::TYPE_BOOL)); |
|
| 309 | + $this->assertThat($entity->isAnotherBool(), new IsType(IsType::TYPE_BOOL)); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + public function testIsGetterShoudFailForOtherType(): void { |
|
| 314 | + $this->expectException(\BadFunctionCallException::class); |
|
| 315 | + |
|
| 316 | + $entity = new TestEntity(); |
|
| 317 | + $entity->setName('hello'); |
|
| 318 | + $this->assertThat($entity->isName(), new IsType(IsType::TYPE_BOOL)); |
|
| 319 | + } |
|
| 320 | 320 | } |
@@ -24,13 +24,13 @@ discard block |
||
| 24 | 24 | * @method ?\DateTimeImmutable getDatetime() |
| 25 | 25 | */ |
| 26 | 26 | class QBDBTestEntity extends Entity { |
| 27 | - protected ?\DateTime $time = null; |
|
| 28 | - protected ?\DateTimeImmutable $datetime = null; |
|
| 27 | + protected ?\DateTime $time = null; |
|
| 28 | + protected ?\DateTimeImmutable $datetime = null; |
|
| 29 | 29 | |
| 30 | - public function __construct() { |
|
| 31 | - $this->addType('time', Types::TIME); |
|
| 32 | - $this->addType('datetime', Types::DATETIME_IMMUTABLE); |
|
| 33 | - } |
|
| 30 | + public function __construct() { |
|
| 31 | + $this->addType('time', Types::TIME); |
|
| 32 | + $this->addType('datetime', Types::DATETIME_IMMUTABLE); |
|
| 33 | + } |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
@@ -39,24 +39,24 @@ discard block |
||
| 39 | 39 | * @package Test\AppFramework\Db |
| 40 | 40 | */ |
| 41 | 41 | class QBDBTestMapper extends QBMapper { |
| 42 | - public function __construct(IDBConnection $db) { |
|
| 43 | - parent::__construct($db, 'testing', QBDBTestEntity::class); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function getParameterTypeForPropertyForTest(Entity $entity, string $property) { |
|
| 47 | - return parent::getParameterTypeForProperty($entity, $property); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function getById(int $id): QBDBTestEntity { |
|
| 51 | - $qb = $this->db->getQueryBuilder(); |
|
| 52 | - $query = $qb |
|
| 53 | - ->select('*') |
|
| 54 | - ->from($this->tableName) |
|
| 55 | - ->where( |
|
| 56 | - $qb->expr()->eq('id', $qb->createPositionalParameter($id, IQueryBuilder::PARAM_INT)), |
|
| 57 | - ); |
|
| 58 | - return $this->findEntity($query); |
|
| 59 | - } |
|
| 42 | + public function __construct(IDBConnection $db) { |
|
| 43 | + parent::__construct($db, 'testing', QBDBTestEntity::class); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function getParameterTypeForPropertyForTest(Entity $entity, string $property) { |
|
| 47 | + return parent::getParameterTypeForProperty($entity, $property); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function getById(int $id): QBDBTestEntity { |
|
| 51 | + $qb = $this->db->getQueryBuilder(); |
|
| 52 | + $query = $qb |
|
| 53 | + ->select('*') |
|
| 54 | + ->from($this->tableName) |
|
| 55 | + ->where( |
|
| 56 | + $qb->expr()->eq('id', $qb->createPositionalParameter($id, IQueryBuilder::PARAM_INT)), |
|
| 57 | + ); |
|
| 58 | + return $this->findEntity($query); |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -64,96 +64,96 @@ discard block |
||
| 64 | 64 | * @group DB |
| 65 | 65 | */ |
| 66 | 66 | class QBMapperDBTest extends TestCase { |
| 67 | - protected IDBConnection $connection; |
|
| 68 | - protected bool $schemaSetup = false; |
|
| 69 | - |
|
| 70 | - protected function setUp(): void { |
|
| 71 | - parent::setUp(); |
|
| 72 | - |
|
| 73 | - $this->connection = Server::get(IDBConnection::class); |
|
| 74 | - $this->prepareTestingTable(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function testInsertDateTime(): void { |
|
| 78 | - $mapper = new QBDBTestMapper($this->connection); |
|
| 79 | - $entity = new QBDBTestEntity(); |
|
| 80 | - $entity->setTime(new \DateTime('2003-01-01 12:34:00')); |
|
| 81 | - $entity->setDatetime(new \DateTimeImmutable('2000-01-01 23:45:00')); |
|
| 82 | - |
|
| 83 | - $result = $mapper->insert($entity); |
|
| 84 | - $this->assertNotNull($result->getId()); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - public function testRetrieveDateTime(): void { |
|
| 88 | - $time = new \DateTime('2000-01-01 01:01:00'); |
|
| 89 | - $datetime = new \DateTimeImmutable('2000-01-01 02:02:00'); |
|
| 90 | - |
|
| 91 | - $mapper = new QBDBTestMapper($this->connection); |
|
| 92 | - $entity = new QBDBTestEntity(); |
|
| 93 | - $entity->setTime($time); |
|
| 94 | - $entity->setDatetime($datetime); |
|
| 95 | - |
|
| 96 | - $result = $mapper->insert($entity); |
|
| 97 | - $this->assertNotNull($result->getId()); |
|
| 98 | - |
|
| 99 | - $dbEntity = $mapper->getById($result->getId()); |
|
| 100 | - $this->assertEquals($time->format('H:i:s'), $dbEntity->getTime()->format('H:i:s')); |
|
| 101 | - $this->assertEquals($datetime->format('Y-m-d H:i:s'), $dbEntity->getDatetime()->format('Y-m-d H:i:s')); |
|
| 102 | - // The date is not saved for "time" |
|
| 103 | - $this->assertNotEquals($time->format('Y'), $dbEntity->getTime()->format('Y')); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function testUpdateDateTime(): void { |
|
| 107 | - $time = new \DateTime('2000-01-01 01:01:00'); |
|
| 108 | - $datetime = new \DateTimeImmutable('2000-01-01 02:02:00'); |
|
| 109 | - |
|
| 110 | - $mapper = new QBDBTestMapper($this->connection); |
|
| 111 | - $entity = new QBDBTestEntity(); |
|
| 112 | - $entity->setTime('now'); |
|
| 113 | - $entity->setDatetime('now'); |
|
| 114 | - |
|
| 115 | - /** @var QBDBTestEntity */ |
|
| 116 | - $entity = $mapper->insert($entity); |
|
| 117 | - $this->assertNotNull($entity->getId()); |
|
| 118 | - |
|
| 119 | - // Update the values |
|
| 120 | - $entity->setTime($time); |
|
| 121 | - $entity->setDatetime($datetime); |
|
| 122 | - $mapper->update($entity); |
|
| 123 | - |
|
| 124 | - $dbEntity = $mapper->getById($entity->getId()); |
|
| 125 | - $this->assertEquals($time->format('H:i:s'), $dbEntity->getTime()->format('H:i:s')); |
|
| 126 | - $this->assertEquals($datetime->format('Y-m-d H:i:s'), $dbEntity->getDatetime()->format('Y-m-d H:i:s')); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - protected function prepareTestingTable(): void { |
|
| 130 | - if ($this->schemaSetup) { |
|
| 131 | - $this->connection->getQueryBuilder()->delete('testing')->executeStatement(); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $prefix = Server::get(IConfig::class)->getSystemValueString('dbtableprefix', 'oc_'); |
|
| 135 | - $schema = $this->connection->createSchema(); |
|
| 136 | - try { |
|
| 137 | - $schema->getTable($prefix . 'testing'); |
|
| 138 | - $this->connection->getQueryBuilder()->delete('testing')->executeStatement(); |
|
| 139 | - } catch (SchemaException $e) { |
|
| 140 | - $this->schemaSetup = true; |
|
| 141 | - $table = $schema->createTable($prefix . 'testing'); |
|
| 142 | - $table->addColumn('id', Types::BIGINT, [ |
|
| 143 | - 'autoincrement' => true, |
|
| 144 | - 'notnull' => true, |
|
| 145 | - ]); |
|
| 146 | - |
|
| 147 | - $table->addColumn('time', Types::TIME, [ |
|
| 148 | - 'notnull' => false, |
|
| 149 | - ]); |
|
| 150 | - |
|
| 151 | - $table->addColumn('datetime', Types::DATETIME_IMMUTABLE, [ |
|
| 152 | - 'notnull' => false, |
|
| 153 | - ]); |
|
| 154 | - |
|
| 155 | - $table->setPrimaryKey(['id']); |
|
| 156 | - $this->connection->migrateToSchema($schema); |
|
| 157 | - } |
|
| 158 | - } |
|
| 67 | + protected IDBConnection $connection; |
|
| 68 | + protected bool $schemaSetup = false; |
|
| 69 | + |
|
| 70 | + protected function setUp(): void { |
|
| 71 | + parent::setUp(); |
|
| 72 | + |
|
| 73 | + $this->connection = Server::get(IDBConnection::class); |
|
| 74 | + $this->prepareTestingTable(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function testInsertDateTime(): void { |
|
| 78 | + $mapper = new QBDBTestMapper($this->connection); |
|
| 79 | + $entity = new QBDBTestEntity(); |
|
| 80 | + $entity->setTime(new \DateTime('2003-01-01 12:34:00')); |
|
| 81 | + $entity->setDatetime(new \DateTimeImmutable('2000-01-01 23:45:00')); |
|
| 82 | + |
|
| 83 | + $result = $mapper->insert($entity); |
|
| 84 | + $this->assertNotNull($result->getId()); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + public function testRetrieveDateTime(): void { |
|
| 88 | + $time = new \DateTime('2000-01-01 01:01:00'); |
|
| 89 | + $datetime = new \DateTimeImmutable('2000-01-01 02:02:00'); |
|
| 90 | + |
|
| 91 | + $mapper = new QBDBTestMapper($this->connection); |
|
| 92 | + $entity = new QBDBTestEntity(); |
|
| 93 | + $entity->setTime($time); |
|
| 94 | + $entity->setDatetime($datetime); |
|
| 95 | + |
|
| 96 | + $result = $mapper->insert($entity); |
|
| 97 | + $this->assertNotNull($result->getId()); |
|
| 98 | + |
|
| 99 | + $dbEntity = $mapper->getById($result->getId()); |
|
| 100 | + $this->assertEquals($time->format('H:i:s'), $dbEntity->getTime()->format('H:i:s')); |
|
| 101 | + $this->assertEquals($datetime->format('Y-m-d H:i:s'), $dbEntity->getDatetime()->format('Y-m-d H:i:s')); |
|
| 102 | + // The date is not saved for "time" |
|
| 103 | + $this->assertNotEquals($time->format('Y'), $dbEntity->getTime()->format('Y')); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function testUpdateDateTime(): void { |
|
| 107 | + $time = new \DateTime('2000-01-01 01:01:00'); |
|
| 108 | + $datetime = new \DateTimeImmutable('2000-01-01 02:02:00'); |
|
| 109 | + |
|
| 110 | + $mapper = new QBDBTestMapper($this->connection); |
|
| 111 | + $entity = new QBDBTestEntity(); |
|
| 112 | + $entity->setTime('now'); |
|
| 113 | + $entity->setDatetime('now'); |
|
| 114 | + |
|
| 115 | + /** @var QBDBTestEntity */ |
|
| 116 | + $entity = $mapper->insert($entity); |
|
| 117 | + $this->assertNotNull($entity->getId()); |
|
| 118 | + |
|
| 119 | + // Update the values |
|
| 120 | + $entity->setTime($time); |
|
| 121 | + $entity->setDatetime($datetime); |
|
| 122 | + $mapper->update($entity); |
|
| 123 | + |
|
| 124 | + $dbEntity = $mapper->getById($entity->getId()); |
|
| 125 | + $this->assertEquals($time->format('H:i:s'), $dbEntity->getTime()->format('H:i:s')); |
|
| 126 | + $this->assertEquals($datetime->format('Y-m-d H:i:s'), $dbEntity->getDatetime()->format('Y-m-d H:i:s')); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + protected function prepareTestingTable(): void { |
|
| 130 | + if ($this->schemaSetup) { |
|
| 131 | + $this->connection->getQueryBuilder()->delete('testing')->executeStatement(); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $prefix = Server::get(IConfig::class)->getSystemValueString('dbtableprefix', 'oc_'); |
|
| 135 | + $schema = $this->connection->createSchema(); |
|
| 136 | + try { |
|
| 137 | + $schema->getTable($prefix . 'testing'); |
|
| 138 | + $this->connection->getQueryBuilder()->delete('testing')->executeStatement(); |
|
| 139 | + } catch (SchemaException $e) { |
|
| 140 | + $this->schemaSetup = true; |
|
| 141 | + $table = $schema->createTable($prefix . 'testing'); |
|
| 142 | + $table->addColumn('id', Types::BIGINT, [ |
|
| 143 | + 'autoincrement' => true, |
|
| 144 | + 'notnull' => true, |
|
| 145 | + ]); |
|
| 146 | + |
|
| 147 | + $table->addColumn('time', Types::TIME, [ |
|
| 148 | + 'notnull' => false, |
|
| 149 | + ]); |
|
| 150 | + |
|
| 151 | + $table->addColumn('datetime', Types::DATETIME_IMMUTABLE, [ |
|
| 152 | + 'notnull' => false, |
|
| 153 | + ]); |
|
| 154 | + |
|
| 155 | + $table->setPrimaryKey(['id']); |
|
| 156 | + $this->connection->migrateToSchema($schema); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -15,64 +15,64 @@ |
||
| 15 | 15 | use Test\TestCase; |
| 16 | 16 | |
| 17 | 17 | class TransactionalTest extends TestCase { |
| 18 | - private IDBConnection&MockObject $db; |
|
| 18 | + private IDBConnection&MockObject $db; |
|
| 19 | 19 | |
| 20 | - protected function setUp(): void { |
|
| 21 | - parent::setUp(); |
|
| 20 | + protected function setUp(): void { |
|
| 21 | + parent::setUp(); |
|
| 22 | 22 | |
| 23 | - $this->db = $this->createMock(IDBConnection::class); |
|
| 24 | - } |
|
| 23 | + $this->db = $this->createMock(IDBConnection::class); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function testAtomicRollback(): void { |
|
| 27 | - $test = new class($this->db) { |
|
| 28 | - use TTransactional; |
|
| 26 | + public function testAtomicRollback(): void { |
|
| 27 | + $test = new class($this->db) { |
|
| 28 | + use TTransactional; |
|
| 29 | 29 | |
| 30 | - public function __construct( |
|
| 31 | - private IDBConnection $db, |
|
| 32 | - ) { |
|
| 33 | - } |
|
| 30 | + public function __construct( |
|
| 31 | + private IDBConnection $db, |
|
| 32 | + ) { |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function fail(): void { |
|
| 36 | - $this->atomic(function (): void { |
|
| 37 | - throw new RuntimeException('nope'); |
|
| 38 | - }, $this->db); |
|
| 39 | - } |
|
| 40 | - }; |
|
| 41 | - $this->db->expects(self::once()) |
|
| 42 | - ->method('beginTransaction'); |
|
| 43 | - $this->db->expects(self::once()) |
|
| 44 | - ->method('rollback'); |
|
| 45 | - $this->db->expects(self::never()) |
|
| 46 | - ->method('commit'); |
|
| 47 | - $this->expectException(RuntimeException::class); |
|
| 35 | + public function fail(): void { |
|
| 36 | + $this->atomic(function (): void { |
|
| 37 | + throw new RuntimeException('nope'); |
|
| 38 | + }, $this->db); |
|
| 39 | + } |
|
| 40 | + }; |
|
| 41 | + $this->db->expects(self::once()) |
|
| 42 | + ->method('beginTransaction'); |
|
| 43 | + $this->db->expects(self::once()) |
|
| 44 | + ->method('rollback'); |
|
| 45 | + $this->db->expects(self::never()) |
|
| 46 | + ->method('commit'); |
|
| 47 | + $this->expectException(RuntimeException::class); |
|
| 48 | 48 | |
| 49 | - $test->fail(); |
|
| 50 | - } |
|
| 49 | + $test->fail(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function testAtomicCommit(): void { |
|
| 53 | - $test = new class($this->db) { |
|
| 54 | - use TTransactional; |
|
| 52 | + public function testAtomicCommit(): void { |
|
| 53 | + $test = new class($this->db) { |
|
| 54 | + use TTransactional; |
|
| 55 | 55 | |
| 56 | - public function __construct( |
|
| 57 | - private IDBConnection $db, |
|
| 58 | - ) { |
|
| 59 | - } |
|
| 56 | + public function __construct( |
|
| 57 | + private IDBConnection $db, |
|
| 58 | + ) { |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function succeed(): int { |
|
| 62 | - return $this->atomic(function () { |
|
| 63 | - return 3; |
|
| 64 | - }, $this->db); |
|
| 65 | - } |
|
| 66 | - }; |
|
| 67 | - $this->db->expects(self::once()) |
|
| 68 | - ->method('beginTransaction'); |
|
| 69 | - $this->db->expects(self::never()) |
|
| 70 | - ->method('rollback'); |
|
| 71 | - $this->db->expects(self::once()) |
|
| 72 | - ->method('commit'); |
|
| 61 | + public function succeed(): int { |
|
| 62 | + return $this->atomic(function () { |
|
| 63 | + return 3; |
|
| 64 | + }, $this->db); |
|
| 65 | + } |
|
| 66 | + }; |
|
| 67 | + $this->db->expects(self::once()) |
|
| 68 | + ->method('beginTransaction'); |
|
| 69 | + $this->db->expects(self::never()) |
|
| 70 | + ->method('rollback'); |
|
| 71 | + $this->db->expects(self::once()) |
|
| 72 | + ->method('commit'); |
|
| 73 | 73 | |
| 74 | - $result = $test->succeed(); |
|
| 74 | + $result = $test->succeed(); |
|
| 75 | 75 | |
| 76 | - self::assertEquals(3, $result); |
|
| 77 | - } |
|
| 76 | + self::assertEquals(3, $result); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -16,59 +16,59 @@ |
||
| 16 | 16 | use OCP\Server; |
| 17 | 17 | |
| 18 | 18 | class DataResponseTest extends \Test\TestCase { |
| 19 | - private DataResponse $response; |
|
| 19 | + private DataResponse $response; |
|
| 20 | 20 | |
| 21 | - protected function setUp(): void { |
|
| 22 | - parent::setUp(); |
|
| 23 | - $this->response = new DataResponse(); |
|
| 24 | - } |
|
| 21 | + protected function setUp(): void { |
|
| 22 | + parent::setUp(); |
|
| 23 | + $this->response = new DataResponse(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - public function testSetData(): void { |
|
| 28 | - $params = ['hi', 'yo']; |
|
| 29 | - $this->response->setData($params); |
|
| 27 | + public function testSetData(): void { |
|
| 28 | + $params = ['hi', 'yo']; |
|
| 29 | + $this->response->setData($params); |
|
| 30 | 30 | |
| 31 | - $this->assertEquals(['hi', 'yo'], $this->response->getData()); |
|
| 32 | - } |
|
| 31 | + $this->assertEquals(['hi', 'yo'], $this->response->getData()); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | - public function testConstructorAllowsToSetData(): void { |
|
| 36 | - $data = ['hi']; |
|
| 37 | - $code = 300; |
|
| 38 | - $response = new DataResponse($data, $code); |
|
| 35 | + public function testConstructorAllowsToSetData(): void { |
|
| 36 | + $data = ['hi']; |
|
| 37 | + $code = 300; |
|
| 38 | + $response = new DataResponse($data, $code); |
|
| 39 | 39 | |
| 40 | - $this->assertEquals($data, $response->getData()); |
|
| 41 | - $this->assertEquals($code, $response->getStatus()); |
|
| 42 | - } |
|
| 40 | + $this->assertEquals($data, $response->getData()); |
|
| 41 | + $this->assertEquals($code, $response->getStatus()); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | - public function testConstructorAllowsToSetHeaders(): void { |
|
| 46 | - $data = ['hi']; |
|
| 47 | - $code = 300; |
|
| 48 | - $headers = ['test' => 'something']; |
|
| 49 | - $response = new DataResponse($data, $code, $headers); |
|
| 45 | + public function testConstructorAllowsToSetHeaders(): void { |
|
| 46 | + $data = ['hi']; |
|
| 47 | + $code = 300; |
|
| 48 | + $headers = ['test' => 'something']; |
|
| 49 | + $response = new DataResponse($data, $code, $headers); |
|
| 50 | 50 | |
| 51 | - $expectedHeaders = [ |
|
| 52 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate', |
|
| 53 | - 'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'", |
|
| 54 | - 'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'", |
|
| 55 | - 'X-Robots-Tag' => 'noindex, nofollow', |
|
| 56 | - 'X-Request-Id' => Server::get(IRequest::class)->getId(), |
|
| 57 | - ]; |
|
| 58 | - $expectedHeaders = array_merge($expectedHeaders, $headers); |
|
| 51 | + $expectedHeaders = [ |
|
| 52 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate', |
|
| 53 | + 'Content-Security-Policy' => "default-src 'none';base-uri 'none';manifest-src 'self';frame-ancestors 'none'", |
|
| 54 | + 'Feature-Policy' => "autoplay 'none';camera 'none';fullscreen 'none';geolocation 'none';microphone 'none';payment 'none'", |
|
| 55 | + 'X-Robots-Tag' => 'noindex, nofollow', |
|
| 56 | + 'X-Request-Id' => Server::get(IRequest::class)->getId(), |
|
| 57 | + ]; |
|
| 58 | + $expectedHeaders = array_merge($expectedHeaders, $headers); |
|
| 59 | 59 | |
| 60 | - $this->assertEquals($data, $response->getData()); |
|
| 61 | - $this->assertEquals($code, $response->getStatus()); |
|
| 62 | - $this->assertEquals($expectedHeaders, $response->getHeaders()); |
|
| 63 | - } |
|
| 60 | + $this->assertEquals($data, $response->getData()); |
|
| 61 | + $this->assertEquals($code, $response->getStatus()); |
|
| 62 | + $this->assertEquals($expectedHeaders, $response->getHeaders()); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - public function testChainability(): void { |
|
| 67 | - $params = ['hi', 'yo']; |
|
| 68 | - $this->response->setData($params) |
|
| 69 | - ->setStatus(Http::STATUS_NOT_FOUND); |
|
| 66 | + public function testChainability(): void { |
|
| 67 | + $params = ['hi', 'yo']; |
|
| 68 | + $this->response->setData($params) |
|
| 69 | + ->setStatus(Http::STATUS_NOT_FOUND); |
|
| 70 | 70 | |
| 71 | - $this->assertEquals(Http::STATUS_NOT_FOUND, $this->response->getStatus()); |
|
| 72 | - $this->assertEquals(['hi', 'yo'], $this->response->getData()); |
|
| 73 | - } |
|
| 71 | + $this->assertEquals(Http::STATUS_NOT_FOUND, $this->response->getStatus()); |
|
| 72 | + $this->assertEquals(['hi', 'yo'], $this->response->getData()); |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -18,500 +18,500 @@ |
||
| 18 | 18 | * @package OC\AppFramework\Http |
| 19 | 19 | */ |
| 20 | 20 | class ContentSecurityPolicyTest extends \Test\TestCase { |
| 21 | - private ContentSecurityPolicy $contentSecurityPolicy; |
|
| 21 | + private ContentSecurityPolicy $contentSecurityPolicy; |
|
| 22 | 22 | |
| 23 | - protected function setUp(): void { |
|
| 24 | - parent::setUp(); |
|
| 25 | - $this->contentSecurityPolicy = new ContentSecurityPolicy(); |
|
| 26 | - } |
|
| 23 | + protected function setUp(): void { |
|
| 24 | + parent::setUp(); |
|
| 25 | + $this->contentSecurityPolicy = new ContentSecurityPolicy(); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function testGetPolicyDefault(): void { |
|
| 29 | - $defaultPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 30 | - $this->assertSame($defaultPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 31 | - } |
|
| 28 | + public function testGetPolicyDefault(): void { |
|
| 29 | + $defaultPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 30 | + $this->assertSame($defaultPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - public function testGetPolicyScriptDomainValid(): void { |
|
| 34 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.nextcloud.com;style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 33 | + public function testGetPolicyScriptDomainValid(): void { |
|
| 34 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.nextcloud.com;style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 35 | 35 | |
| 36 | - $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 37 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 38 | - } |
|
| 36 | + $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 37 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function testGetPolicyScriptDomainValidMultiple(): void { |
|
| 41 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.nextcloud.com www.nextcloud.org;style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 40 | + public function testGetPolicyScriptDomainValidMultiple(): void { |
|
| 41 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.nextcloud.com www.nextcloud.org;style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 42 | 42 | |
| 43 | - $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 44 | - $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.org'); |
|
| 45 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 46 | - } |
|
| 43 | + $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 44 | + $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.org'); |
|
| 45 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function testGetPolicyDisallowScriptDomain(): void { |
|
| 49 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 48 | + public function testGetPolicyDisallowScriptDomain(): void { |
|
| 49 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 50 | 50 | |
| 51 | - $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 52 | - $this->contentSecurityPolicy->disallowScriptDomain('www.nextcloud.com'); |
|
| 53 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 54 | - } |
|
| 51 | + $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 52 | + $this->contentSecurityPolicy->disallowScriptDomain('www.nextcloud.com'); |
|
| 53 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function testGetPolicyDisallowScriptDomainMultiple(): void { |
|
| 57 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.nextcloud.com;style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 56 | + public function testGetPolicyDisallowScriptDomainMultiple(): void { |
|
| 57 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' www.nextcloud.com;style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 58 | 58 | |
| 59 | - $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 60 | - $this->contentSecurityPolicy->disallowScriptDomain('www.nextcloud.org'); |
|
| 61 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 62 | - } |
|
| 59 | + $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 60 | + $this->contentSecurityPolicy->disallowScriptDomain('www.nextcloud.org'); |
|
| 61 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function testGetPolicyDisallowScriptDomainMultipleStacked(): void { |
|
| 65 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 64 | + public function testGetPolicyDisallowScriptDomainMultipleStacked(): void { |
|
| 65 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 66 | 66 | |
| 67 | - $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 68 | - $this->contentSecurityPolicy->disallowScriptDomain('www.nextcloud.org')->disallowScriptDomain('www.nextcloud.com'); |
|
| 69 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 70 | - } |
|
| 67 | + $this->contentSecurityPolicy->addAllowedScriptDomain('www.nextcloud.com'); |
|
| 68 | + $this->contentSecurityPolicy->disallowScriptDomain('www.nextcloud.org')->disallowScriptDomain('www.nextcloud.com'); |
|
| 69 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function testGetPolicyScriptDisallowEval(): void { |
|
| 73 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 72 | + public function testGetPolicyScriptDisallowEval(): void { |
|
| 73 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 74 | 74 | |
| 75 | - $this->contentSecurityPolicy->allowEvalScript(false); |
|
| 76 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 77 | - } |
|
| 75 | + $this->contentSecurityPolicy->allowEvalScript(false); |
|
| 76 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - public function testGetPolicyStyleDomainValid(): void { |
|
| 80 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 79 | + public function testGetPolicyStyleDomainValid(): void { |
|
| 80 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 81 | 81 | |
| 82 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 83 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 84 | - } |
|
| 82 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 83 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function testGetPolicyStyleDomainValidMultiple(): void { |
|
| 87 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com www.nextcloud.org 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 86 | + public function testGetPolicyStyleDomainValidMultiple(): void { |
|
| 87 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com www.nextcloud.org 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 88 | 88 | |
| 89 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 90 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.org'); |
|
| 91 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 92 | - } |
|
| 89 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 90 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.org'); |
|
| 91 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function testGetPolicyDisallowStyleDomain(): void { |
|
| 95 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 94 | + public function testGetPolicyDisallowStyleDomain(): void { |
|
| 95 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 96 | 96 | |
| 97 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 98 | - $this->contentSecurityPolicy->disallowStyleDomain('www.nextcloud.com'); |
|
| 99 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 100 | - } |
|
| 97 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 98 | + $this->contentSecurityPolicy->disallowStyleDomain('www.nextcloud.com'); |
|
| 99 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - public function testGetPolicyDisallowStyleDomainMultiple(): void { |
|
| 103 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 102 | + public function testGetPolicyDisallowStyleDomainMultiple(): void { |
|
| 103 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 104 | 104 | |
| 105 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 106 | - $this->contentSecurityPolicy->disallowStyleDomain('www.nextcloud.org'); |
|
| 107 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 108 | - } |
|
| 105 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 106 | + $this->contentSecurityPolicy->disallowStyleDomain('www.nextcloud.org'); |
|
| 107 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - public function testGetPolicyDisallowStyleDomainMultipleStacked(): void { |
|
| 111 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 110 | + public function testGetPolicyDisallowStyleDomainMultipleStacked(): void { |
|
| 111 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 112 | 112 | |
| 113 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 114 | - $this->contentSecurityPolicy->disallowStyleDomain('www.nextcloud.org')->disallowStyleDomain('www.nextcloud.com'); |
|
| 115 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 116 | - } |
|
| 113 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 114 | + $this->contentSecurityPolicy->disallowStyleDomain('www.nextcloud.org')->disallowStyleDomain('www.nextcloud.com'); |
|
| 115 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - public function testGetPolicyStyleAllowInline(): void { |
|
| 119 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 118 | + public function testGetPolicyStyleAllowInline(): void { |
|
| 119 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 120 | 120 | |
| 121 | - $this->contentSecurityPolicy->allowInlineStyle(true); |
|
| 122 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 123 | - } |
|
| 121 | + $this->contentSecurityPolicy->allowInlineStyle(true); |
|
| 122 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - public function testGetPolicyStyleAllowInlineWithDomain(): void { |
|
| 126 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 125 | + public function testGetPolicyStyleAllowInlineWithDomain(): void { |
|
| 126 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' www.nextcloud.com 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 127 | 127 | |
| 128 | - $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 129 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 130 | - } |
|
| 128 | + $this->contentSecurityPolicy->addAllowedStyleDomain('www.nextcloud.com'); |
|
| 129 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - public function testGetPolicyStyleDisallowInline(): void { |
|
| 133 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 132 | + public function testGetPolicyStyleDisallowInline(): void { |
|
| 133 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 134 | 134 | |
| 135 | - $this->contentSecurityPolicy->allowInlineStyle(false); |
|
| 136 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 137 | - } |
|
| 135 | + $this->contentSecurityPolicy->allowInlineStyle(false); |
|
| 136 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - public function testGetPolicyImageDomainValid(): void { |
|
| 140 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.nextcloud.com;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 139 | + public function testGetPolicyImageDomainValid(): void { |
|
| 140 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.nextcloud.com;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 141 | 141 | |
| 142 | - $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 143 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 144 | - } |
|
| 142 | + $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 143 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - public function testGetPolicyImageDomainValidMultiple(): void { |
|
| 147 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.nextcloud.com www.nextcloud.org;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 146 | + public function testGetPolicyImageDomainValidMultiple(): void { |
|
| 147 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.nextcloud.com www.nextcloud.org;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 148 | 148 | |
| 149 | - $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 150 | - $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.org'); |
|
| 151 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 152 | - } |
|
| 149 | + $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 150 | + $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.org'); |
|
| 151 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - public function testGetPolicyDisallowImageDomain(): void { |
|
| 155 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 154 | + public function testGetPolicyDisallowImageDomain(): void { |
|
| 155 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 156 | 156 | |
| 157 | - $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 158 | - $this->contentSecurityPolicy->disallowImageDomain('www.nextcloud.com'); |
|
| 159 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 160 | - } |
|
| 157 | + $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 158 | + $this->contentSecurityPolicy->disallowImageDomain('www.nextcloud.com'); |
|
| 159 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - public function testGetPolicyDisallowImageDomainMultiple(): void { |
|
| 163 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.nextcloud.com;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 162 | + public function testGetPolicyDisallowImageDomainMultiple(): void { |
|
| 163 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob: www.nextcloud.com;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 164 | 164 | |
| 165 | - $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 166 | - $this->contentSecurityPolicy->disallowImageDomain('www.nextcloud.org'); |
|
| 167 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 168 | - } |
|
| 165 | + $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 166 | + $this->contentSecurityPolicy->disallowImageDomain('www.nextcloud.org'); |
|
| 167 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - public function testGetPolicyDisallowImageDomainMultipleStakes(): void { |
|
| 171 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 170 | + public function testGetPolicyDisallowImageDomainMultipleStakes(): void { |
|
| 171 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 172 | 172 | |
| 173 | - $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 174 | - $this->contentSecurityPolicy->disallowImageDomain('www.nextcloud.org')->disallowImageDomain('www.nextcloud.com'); |
|
| 175 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 176 | - } |
|
| 173 | + $this->contentSecurityPolicy->addAllowedImageDomain('www.nextcloud.com'); |
|
| 174 | + $this->contentSecurityPolicy->disallowImageDomain('www.nextcloud.org')->disallowImageDomain('www.nextcloud.com'); |
|
| 175 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - public function testGetPolicyFontDomainValid(): void { |
|
| 179 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data: www.nextcloud.com;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 178 | + public function testGetPolicyFontDomainValid(): void { |
|
| 179 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data: www.nextcloud.com;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 180 | 180 | |
| 181 | - $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 182 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 183 | - } |
|
| 181 | + $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 182 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - public function testGetPolicyFontDomainValidMultiple(): void { |
|
| 186 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data: www.nextcloud.com www.nextcloud.org;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 185 | + public function testGetPolicyFontDomainValidMultiple(): void { |
|
| 186 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data: www.nextcloud.com www.nextcloud.org;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 187 | 187 | |
| 188 | - $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 189 | - $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.org'); |
|
| 190 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 191 | - } |
|
| 188 | + $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 189 | + $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.org'); |
|
| 190 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - public function testGetPolicyDisallowFontDomain(): void { |
|
| 194 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 193 | + public function testGetPolicyDisallowFontDomain(): void { |
|
| 194 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 195 | 195 | |
| 196 | - $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 197 | - $this->contentSecurityPolicy->disallowFontDomain('www.nextcloud.com'); |
|
| 198 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 199 | - } |
|
| 196 | + $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 197 | + $this->contentSecurityPolicy->disallowFontDomain('www.nextcloud.com'); |
|
| 198 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - public function testGetPolicyDisallowFontDomainMultiple(): void { |
|
| 202 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data: www.nextcloud.com;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 201 | + public function testGetPolicyDisallowFontDomainMultiple(): void { |
|
| 202 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data: www.nextcloud.com;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 203 | 203 | |
| 204 | - $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 205 | - $this->contentSecurityPolicy->disallowFontDomain('www.nextcloud.org'); |
|
| 206 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 207 | - } |
|
| 204 | + $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 205 | + $this->contentSecurityPolicy->disallowFontDomain('www.nextcloud.org'); |
|
| 206 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - public function testGetPolicyDisallowFontDomainMultipleStakes(): void { |
|
| 210 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 209 | + public function testGetPolicyDisallowFontDomainMultipleStakes(): void { |
|
| 210 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 211 | 211 | |
| 212 | - $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 213 | - $this->contentSecurityPolicy->disallowFontDomain('www.nextcloud.org')->disallowFontDomain('www.nextcloud.com'); |
|
| 214 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 215 | - } |
|
| 212 | + $this->contentSecurityPolicy->addAllowedFontDomain('www.nextcloud.com'); |
|
| 213 | + $this->contentSecurityPolicy->disallowFontDomain('www.nextcloud.org')->disallowFontDomain('www.nextcloud.com'); |
|
| 214 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - public function testGetPolicyConnectDomainValid(): void { |
|
| 218 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self' www.nextcloud.com;media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 217 | + public function testGetPolicyConnectDomainValid(): void { |
|
| 218 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self' www.nextcloud.com;media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 219 | 219 | |
| 220 | - $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 221 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 222 | - } |
|
| 220 | + $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 221 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - public function testGetPolicyConnectDomainValidMultiple(): void { |
|
| 225 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self' www.nextcloud.com www.nextcloud.org;media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 224 | + public function testGetPolicyConnectDomainValidMultiple(): void { |
|
| 225 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self' www.nextcloud.com www.nextcloud.org;media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 226 | 226 | |
| 227 | - $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 228 | - $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.org'); |
|
| 229 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 230 | - } |
|
| 227 | + $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 228 | + $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.org'); |
|
| 229 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - public function testGetPolicyDisallowConnectDomain(): void { |
|
| 233 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 232 | + public function testGetPolicyDisallowConnectDomain(): void { |
|
| 233 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 234 | 234 | |
| 235 | - $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 236 | - $this->contentSecurityPolicy->disallowConnectDomain('www.nextcloud.com'); |
|
| 237 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 238 | - } |
|
| 235 | + $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 236 | + $this->contentSecurityPolicy->disallowConnectDomain('www.nextcloud.com'); |
|
| 237 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - public function testGetPolicyDisallowConnectDomainMultiple(): void { |
|
| 241 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self' www.nextcloud.com;media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 240 | + public function testGetPolicyDisallowConnectDomainMultiple(): void { |
|
| 241 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self' www.nextcloud.com;media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 242 | 242 | |
| 243 | - $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 244 | - $this->contentSecurityPolicy->disallowConnectDomain('www.nextcloud.org'); |
|
| 245 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 246 | - } |
|
| 243 | + $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 244 | + $this->contentSecurityPolicy->disallowConnectDomain('www.nextcloud.org'); |
|
| 245 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - public function testGetPolicyDisallowConnectDomainMultipleStakes(): void { |
|
| 249 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 248 | + public function testGetPolicyDisallowConnectDomainMultipleStakes(): void { |
|
| 249 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 250 | 250 | |
| 251 | - $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 252 | - $this->contentSecurityPolicy->disallowConnectDomain('www.nextcloud.org')->disallowConnectDomain('www.nextcloud.com'); |
|
| 253 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 254 | - } |
|
| 251 | + $this->contentSecurityPolicy->addAllowedConnectDomain('www.nextcloud.com'); |
|
| 252 | + $this->contentSecurityPolicy->disallowConnectDomain('www.nextcloud.org')->disallowConnectDomain('www.nextcloud.com'); |
|
| 253 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - public function testGetPolicyMediaDomainValid(): void { |
|
| 257 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self' www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 256 | + public function testGetPolicyMediaDomainValid(): void { |
|
| 257 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self' www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 258 | 258 | |
| 259 | - $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 260 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 261 | - } |
|
| 259 | + $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 260 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - public function testGetPolicyMediaDomainValidMultiple(): void { |
|
| 264 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self' www.nextcloud.com www.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 263 | + public function testGetPolicyMediaDomainValidMultiple(): void { |
|
| 264 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self' www.nextcloud.com www.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 265 | 265 | |
| 266 | - $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 267 | - $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.org'); |
|
| 268 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 269 | - } |
|
| 266 | + $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 267 | + $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.org'); |
|
| 268 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - public function testGetPolicyDisallowMediaDomain(): void { |
|
| 272 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 271 | + public function testGetPolicyDisallowMediaDomain(): void { |
|
| 272 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 273 | 273 | |
| 274 | - $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 275 | - $this->contentSecurityPolicy->disallowMediaDomain('www.nextcloud.com'); |
|
| 276 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 277 | - } |
|
| 274 | + $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 275 | + $this->contentSecurityPolicy->disallowMediaDomain('www.nextcloud.com'); |
|
| 276 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - public function testGetPolicyDisallowMediaDomainMultiple(): void { |
|
| 280 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self' www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 279 | + public function testGetPolicyDisallowMediaDomainMultiple(): void { |
|
| 280 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self' www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 281 | 281 | |
| 282 | - $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 283 | - $this->contentSecurityPolicy->disallowMediaDomain('www.nextcloud.org'); |
|
| 284 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 285 | - } |
|
| 282 | + $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 283 | + $this->contentSecurityPolicy->disallowMediaDomain('www.nextcloud.org'); |
|
| 284 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - public function testGetPolicyDisallowMediaDomainMultipleStakes(): void { |
|
| 288 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 287 | + public function testGetPolicyDisallowMediaDomainMultipleStakes(): void { |
|
| 288 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 289 | 289 | |
| 290 | - $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 291 | - $this->contentSecurityPolicy->disallowMediaDomain('www.nextcloud.org')->disallowMediaDomain('www.nextcloud.com'); |
|
| 292 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 293 | - } |
|
| 290 | + $this->contentSecurityPolicy->addAllowedMediaDomain('www.nextcloud.com'); |
|
| 291 | + $this->contentSecurityPolicy->disallowMediaDomain('www.nextcloud.org')->disallowMediaDomain('www.nextcloud.com'); |
|
| 292 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - public function testGetPolicyObjectDomainValid(): void { |
|
| 296 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';object-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 295 | + public function testGetPolicyObjectDomainValid(): void { |
|
| 296 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';object-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 297 | 297 | |
| 298 | - $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 299 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 300 | - } |
|
| 298 | + $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 299 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - public function testGetPolicyObjectDomainValidMultiple(): void { |
|
| 303 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';object-src www.nextcloud.com www.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 302 | + public function testGetPolicyObjectDomainValidMultiple(): void { |
|
| 303 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';object-src www.nextcloud.com www.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 304 | 304 | |
| 305 | - $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 306 | - $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.org'); |
|
| 307 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 308 | - } |
|
| 305 | + $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 306 | + $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.org'); |
|
| 307 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - public function testGetPolicyDisallowObjectDomain(): void { |
|
| 311 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 310 | + public function testGetPolicyDisallowObjectDomain(): void { |
|
| 311 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 312 | 312 | |
| 313 | - $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 314 | - $this->contentSecurityPolicy->disallowObjectDomain('www.nextcloud.com'); |
|
| 315 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 316 | - } |
|
| 313 | + $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 314 | + $this->contentSecurityPolicy->disallowObjectDomain('www.nextcloud.com'); |
|
| 315 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - public function testGetPolicyDisallowObjectDomainMultiple(): void { |
|
| 319 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';object-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 318 | + public function testGetPolicyDisallowObjectDomainMultiple(): void { |
|
| 319 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';object-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 320 | 320 | |
| 321 | - $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 322 | - $this->contentSecurityPolicy->disallowObjectDomain('www.nextcloud.org'); |
|
| 323 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 324 | - } |
|
| 321 | + $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 322 | + $this->contentSecurityPolicy->disallowObjectDomain('www.nextcloud.org'); |
|
| 323 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 324 | + } |
|
| 325 | 325 | |
| 326 | - public function testGetPolicyDisallowObjectDomainMultipleStakes(): void { |
|
| 327 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 326 | + public function testGetPolicyDisallowObjectDomainMultipleStakes(): void { |
|
| 327 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 328 | 328 | |
| 329 | - $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 330 | - $this->contentSecurityPolicy->disallowObjectDomain('www.nextcloud.org')->disallowObjectDomain('www.nextcloud.com'); |
|
| 331 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 332 | - } |
|
| 329 | + $this->contentSecurityPolicy->addAllowedObjectDomain('www.nextcloud.com'); |
|
| 330 | + $this->contentSecurityPolicy->disallowObjectDomain('www.nextcloud.org')->disallowObjectDomain('www.nextcloud.com'); |
|
| 331 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - public function testGetAllowedFrameDomain(): void { |
|
| 335 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 334 | + public function testGetAllowedFrameDomain(): void { |
|
| 335 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 336 | 336 | |
| 337 | - $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 338 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 339 | - } |
|
| 337 | + $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 338 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - public function testGetPolicyFrameDomainValidMultiple(): void { |
|
| 342 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src www.nextcloud.com www.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 341 | + public function testGetPolicyFrameDomainValidMultiple(): void { |
|
| 342 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src www.nextcloud.com www.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 343 | 343 | |
| 344 | - $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 345 | - $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.org'); |
|
| 346 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 347 | - } |
|
| 344 | + $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 345 | + $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.org'); |
|
| 346 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 347 | + } |
|
| 348 | 348 | |
| 349 | - public function testGetPolicyDisallowFrameDomain(): void { |
|
| 350 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 349 | + public function testGetPolicyDisallowFrameDomain(): void { |
|
| 350 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 351 | 351 | |
| 352 | - $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 353 | - $this->contentSecurityPolicy->disallowFrameDomain('www.nextcloud.com'); |
|
| 354 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 355 | - } |
|
| 352 | + $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 353 | + $this->contentSecurityPolicy->disallowFrameDomain('www.nextcloud.com'); |
|
| 354 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - public function testGetPolicyDisallowFrameDomainMultiple(): void { |
|
| 358 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 357 | + public function testGetPolicyDisallowFrameDomainMultiple(): void { |
|
| 358 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 359 | 359 | |
| 360 | - $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 361 | - $this->contentSecurityPolicy->disallowFrameDomain('www.nextcloud.org'); |
|
| 362 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 363 | - } |
|
| 360 | + $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 361 | + $this->contentSecurityPolicy->disallowFrameDomain('www.nextcloud.org'); |
|
| 362 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - public function testGetPolicyDisallowFrameDomainMultipleStakes(): void { |
|
| 366 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 365 | + public function testGetPolicyDisallowFrameDomainMultipleStakes(): void { |
|
| 366 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 367 | 367 | |
| 368 | - $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 369 | - $this->contentSecurityPolicy->disallowFrameDomain('www.nextcloud.org')->disallowFrameDomain('www.nextcloud.com'); |
|
| 370 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 371 | - } |
|
| 368 | + $this->contentSecurityPolicy->addAllowedFrameDomain('www.nextcloud.com'); |
|
| 369 | + $this->contentSecurityPolicy->disallowFrameDomain('www.nextcloud.org')->disallowFrameDomain('www.nextcloud.com'); |
|
| 370 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - public function testGetAllowedChildSrcDomain(): void { |
|
| 374 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';child-src child.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 373 | + public function testGetAllowedChildSrcDomain(): void { |
|
| 374 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';child-src child.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 375 | 375 | |
| 376 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.nextcloud.com'); |
|
| 377 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 378 | - } |
|
| 376 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.nextcloud.com'); |
|
| 377 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - public function testGetPolicyChildSrcValidMultiple(): void { |
|
| 381 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';child-src child.nextcloud.com child.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 380 | + public function testGetPolicyChildSrcValidMultiple(): void { |
|
| 381 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';child-src child.nextcloud.com child.nextcloud.org;frame-ancestors 'self';form-action 'self'"; |
|
| 382 | 382 | |
| 383 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.nextcloud.com'); |
|
| 384 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.nextcloud.org'); |
|
| 385 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 386 | - } |
|
| 383 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.nextcloud.com'); |
|
| 384 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.nextcloud.org'); |
|
| 385 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - public function testGetPolicyDisallowChildSrcDomain(): void { |
|
| 389 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 388 | + public function testGetPolicyDisallowChildSrcDomain(): void { |
|
| 389 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 390 | 390 | |
| 391 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 392 | - $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.com'); |
|
| 393 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 394 | - } |
|
| 391 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 392 | + $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.com'); |
|
| 393 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 394 | + } |
|
| 395 | 395 | |
| 396 | - public function testGetPolicyDisallowChildSrcDomainMultiple(): void { |
|
| 397 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';child-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 396 | + public function testGetPolicyDisallowChildSrcDomainMultiple(): void { |
|
| 397 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';child-src www.nextcloud.com;frame-ancestors 'self';form-action 'self'"; |
|
| 398 | 398 | |
| 399 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 400 | - $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.org'); |
|
| 401 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 402 | - } |
|
| 399 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 400 | + $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.org'); |
|
| 401 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - public function testGetPolicyDisallowChildSrcDomainMultipleStakes(): void { |
|
| 405 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 404 | + public function testGetPolicyDisallowChildSrcDomainMultipleStakes(): void { |
|
| 405 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 406 | 406 | |
| 407 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 408 | - $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.org')->disallowChildSrcDomain('www.nextcloud.com'); |
|
| 409 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 410 | - } |
|
| 407 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 408 | + $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.org')->disallowChildSrcDomain('www.nextcloud.com'); |
|
| 409 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | 412 | |
| 413 | 413 | |
| 414 | - public function testGetAllowedFrameAncestorDomain(): void { |
|
| 415 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self' sub.nextcloud.com;form-action 'self'"; |
|
| 414 | + public function testGetAllowedFrameAncestorDomain(): void { |
|
| 415 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self' sub.nextcloud.com;form-action 'self'"; |
|
| 416 | 416 | |
| 417 | - $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('sub.nextcloud.com'); |
|
| 418 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 419 | - } |
|
| 417 | + $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('sub.nextcloud.com'); |
|
| 418 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - public function testGetPolicyFrameAncestorValidMultiple(): void { |
|
| 422 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self' sub.nextcloud.com foo.nextcloud.com;form-action 'self'"; |
|
| 421 | + public function testGetPolicyFrameAncestorValidMultiple(): void { |
|
| 422 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self' sub.nextcloud.com foo.nextcloud.com;form-action 'self'"; |
|
| 423 | 423 | |
| 424 | - $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('sub.nextcloud.com'); |
|
| 425 | - $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('foo.nextcloud.com'); |
|
| 426 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 427 | - } |
|
| 424 | + $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('sub.nextcloud.com'); |
|
| 425 | + $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('foo.nextcloud.com'); |
|
| 426 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - public function testGetPolicyDisallowFrameAncestorDomain(): void { |
|
| 430 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 429 | + public function testGetPolicyDisallowFrameAncestorDomain(): void { |
|
| 430 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 431 | 431 | |
| 432 | - $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('www.nextcloud.com'); |
|
| 433 | - $this->contentSecurityPolicy->disallowFrameAncestorDomain('www.nextcloud.com'); |
|
| 434 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 435 | - } |
|
| 432 | + $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('www.nextcloud.com'); |
|
| 433 | + $this->contentSecurityPolicy->disallowFrameAncestorDomain('www.nextcloud.com'); |
|
| 434 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - public function testGetPolicyDisallowFrameAncestorDomainMultiple(): void { |
|
| 438 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self' www.nextcloud.com;form-action 'self'"; |
|
| 437 | + public function testGetPolicyDisallowFrameAncestorDomainMultiple(): void { |
|
| 438 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self' www.nextcloud.com;form-action 'self'"; |
|
| 439 | 439 | |
| 440 | - $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('www.nextcloud.com'); |
|
| 441 | - $this->contentSecurityPolicy->disallowFrameAncestorDomain('www.nextcloud.org'); |
|
| 442 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 443 | - } |
|
| 440 | + $this->contentSecurityPolicy->addAllowedFrameAncestorDomain('www.nextcloud.com'); |
|
| 441 | + $this->contentSecurityPolicy->disallowFrameAncestorDomain('www.nextcloud.org'); |
|
| 442 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 443 | + } |
|
| 444 | 444 | |
| 445 | - public function testGetPolicyDisallowFrameAncestorDomainMultipleStakes(): void { |
|
| 446 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 445 | + public function testGetPolicyDisallowFrameAncestorDomainMultipleStakes(): void { |
|
| 446 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 447 | 447 | |
| 448 | - $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 449 | - $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.org')->disallowChildSrcDomain('www.nextcloud.com'); |
|
| 450 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 451 | - } |
|
| 448 | + $this->contentSecurityPolicy->addAllowedChildSrcDomain('www.nextcloud.com'); |
|
| 449 | + $this->contentSecurityPolicy->disallowChildSrcDomain('www.nextcloud.org')->disallowChildSrcDomain('www.nextcloud.com'); |
|
| 450 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | - public function testGetPolicyUnsafeEval(): void { |
|
| 454 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 453 | + public function testGetPolicyUnsafeEval(): void { |
|
| 454 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 455 | 455 | |
| 456 | - $this->contentSecurityPolicy->allowEvalScript(true); |
|
| 457 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 458 | - } |
|
| 456 | + $this->contentSecurityPolicy->allowEvalScript(true); |
|
| 457 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 458 | + } |
|
| 459 | 459 | |
| 460 | - public function testGetPolicyUnsafeWasmEval(): void { |
|
| 461 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'wasm-unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 460 | + public function testGetPolicyUnsafeWasmEval(): void { |
|
| 461 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self' 'wasm-unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 462 | 462 | |
| 463 | - $this->contentSecurityPolicy->allowEvalWasm(true); |
|
| 464 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 465 | - } |
|
| 463 | + $this->contentSecurityPolicy->allowEvalWasm(true); |
|
| 464 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 465 | + } |
|
| 466 | 466 | |
| 467 | - public function testGetPolicyNonce(): void { |
|
| 468 | - $nonce = base64_encode('my-nonce'); |
|
| 469 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 467 | + public function testGetPolicyNonce(): void { |
|
| 468 | + $nonce = base64_encode('my-nonce'); |
|
| 469 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 470 | 470 | |
| 471 | - $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 472 | - $this->contentSecurityPolicy->useStrictDynamicOnScripts(false); |
|
| 473 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 474 | - } |
|
| 471 | + $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 472 | + $this->contentSecurityPolicy->useStrictDynamicOnScripts(false); |
|
| 473 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 474 | + } |
|
| 475 | 475 | |
| 476 | - public function testGetPolicyNonceDefault(): void { |
|
| 477 | - $nonce = base64_encode('my-nonce'); |
|
| 478 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-$nonce';script-src-elem 'strict-dynamic' 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 476 | + public function testGetPolicyNonceDefault(): void { |
|
| 477 | + $nonce = base64_encode('my-nonce'); |
|
| 478 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'nonce-$nonce';script-src-elem 'strict-dynamic' 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 479 | 479 | |
| 480 | - $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 481 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 482 | - } |
|
| 480 | + $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 481 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | - public function testGetPolicyNonceStrictDynamic(): void { |
|
| 485 | - $nonce = base64_encode('my-nonce'); |
|
| 486 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'strict-dynamic' 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 484 | + public function testGetPolicyNonceStrictDynamic(): void { |
|
| 485 | + $nonce = base64_encode('my-nonce'); |
|
| 486 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'strict-dynamic' 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 487 | 487 | |
| 488 | - $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 489 | - $this->contentSecurityPolicy->useStrictDynamic(true); |
|
| 490 | - $this->contentSecurityPolicy->useStrictDynamicOnScripts(false); |
|
| 491 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 492 | - } |
|
| 488 | + $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 489 | + $this->contentSecurityPolicy->useStrictDynamic(true); |
|
| 490 | + $this->contentSecurityPolicy->useStrictDynamicOnScripts(false); |
|
| 491 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 492 | + } |
|
| 493 | 493 | |
| 494 | - public function testGetPolicyNonceStrictDynamicDefault(): void { |
|
| 495 | - $nonce = base64_encode('my-nonce'); |
|
| 496 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'strict-dynamic' 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 494 | + public function testGetPolicyNonceStrictDynamicDefault(): void { |
|
| 495 | + $nonce = base64_encode('my-nonce'); |
|
| 496 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'strict-dynamic' 'nonce-$nonce';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 497 | 497 | |
| 498 | - $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 499 | - $this->contentSecurityPolicy->useStrictDynamic(true); |
|
| 500 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 501 | - } |
|
| 498 | + $this->contentSecurityPolicy->useJsNonce($nonce); |
|
| 499 | + $this->contentSecurityPolicy->useStrictDynamic(true); |
|
| 500 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 501 | + } |
|
| 502 | 502 | |
| 503 | - public function testGetPolicyStrictDynamicOnScriptsOff(): void { |
|
| 504 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 503 | + public function testGetPolicyStrictDynamicOnScriptsOff(): void { |
|
| 504 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 505 | 505 | |
| 506 | - $this->contentSecurityPolicy->useStrictDynamicOnScripts(false); |
|
| 507 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 508 | - } |
|
| 506 | + $this->contentSecurityPolicy->useStrictDynamicOnScripts(false); |
|
| 507 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | - public function testGetPolicyStrictDynamicAndStrictDynamicOnScripts(): void { |
|
| 511 | - $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 510 | + public function testGetPolicyStrictDynamicAndStrictDynamicOnScripts(): void { |
|
| 511 | + $expectedPolicy = "default-src 'none';base-uri 'none';manifest-src 'self';script-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src 'self' data:;connect-src 'self';media-src 'self';frame-ancestors 'self';form-action 'self'"; |
|
| 512 | 512 | |
| 513 | - $this->contentSecurityPolicy->useStrictDynamic(true); |
|
| 514 | - $this->contentSecurityPolicy->useStrictDynamicOnScripts(true); |
|
| 515 | - $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 516 | - } |
|
| 513 | + $this->contentSecurityPolicy->useStrictDynamic(true); |
|
| 514 | + $this->contentSecurityPolicy->useStrictDynamicOnScripts(true); |
|
| 515 | + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); |
|
| 516 | + } |
|
| 517 | 517 | } |