This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Wikibase\DataModel\Tests\Term; |
||
| 4 | |||
| 5 | use OutOfBoundsException; |
||
| 6 | use Wikibase\DataModel\Term\AliasGroup; |
||
| 7 | use Wikibase\DataModel\Term\AliasGroupList; |
||
| 8 | use Wikibase\DataModel\Term\Fingerprint; |
||
| 9 | use Wikibase\DataModel\Term\Term; |
||
| 10 | use Wikibase\DataModel\Term\TermList; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @covers \Wikibase\DataModel\Term\Fingerprint |
||
| 14 | * @uses \Wikibase\DataModel\Term\AliasGroup |
||
| 15 | * @uses \Wikibase\DataModel\Term\AliasGroupList |
||
| 16 | * @uses \Wikibase\DataModel\Term\Fingerprint |
||
| 17 | * @uses \Wikibase\DataModel\Term\Term |
||
| 18 | * @uses \Wikibase\DataModel\Term\TermList |
||
| 19 | * |
||
| 20 | * @license GPL-2.0-or-later |
||
| 21 | * @author Jeroen De Dauw < [email protected] > |
||
| 22 | * @author Thiemo Kreuz |
||
| 23 | */ |
||
| 24 | class FingerprintTest extends \PHPUnit\Framework\TestCase { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var TermList |
||
| 28 | */ |
||
| 29 | private $labels; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var TermList |
||
| 33 | */ |
||
| 34 | private $descriptions; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var AliasGroupList |
||
| 38 | */ |
||
| 39 | private $aliasGroups; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var Fingerprint |
||
| 43 | */ |
||
| 44 | private $fingerprint; |
||
| 45 | |||
| 46 | protected function setUp() : void { |
||
| 47 | $this->labels = $this->createMock( TermList::class ); |
||
|
0 ignored issues
–
show
|
|||
| 48 | $this->descriptions = $this->createMock( TermList::class ); |
||
|
0 ignored issues
–
show
It seems like
$this->createMock(\Wikib...l\Term\TermList::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Wikibase\DataModel\Term\TermList> of property $descriptions.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 49 | $this->aliasGroups = $this->createMock( AliasGroupList::class ); |
||
|
0 ignored issues
–
show
It seems like
$this->createMock(\Wikib...\AliasGroupList::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Wikibase\DataModel\Term\AliasGroupList> of property $aliasGroups.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 50 | |||
| 51 | $this->fingerprint = new Fingerprint( |
||
| 52 | new TermList( [ |
||
| 53 | new Term( 'en', 'enlabel' ), |
||
| 54 | new Term( 'de', 'delabel' ), |
||
| 55 | ] ), |
||
| 56 | new TermList( [ |
||
| 57 | new Term( 'en', 'endescription' ), |
||
| 58 | new Term( 'de', 'dedescription' ), |
||
| 59 | ] ), |
||
| 60 | new AliasGroupList( [ |
||
| 61 | new AliasGroup( 'en', [ 'enalias' ] ), |
||
| 62 | new AliasGroup( 'de', [ 'dealias' ] ), |
||
| 63 | ] ) |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function testEmptyConstructor() { |
||
| 68 | $fingerprint = new Fingerprint(); |
||
| 69 | |||
| 70 | $this->assertTrue( $fingerprint->getLabels()->isEmpty() ); |
||
| 71 | $this->assertTrue( $fingerprint->getDescriptions()->isEmpty() ); |
||
| 72 | $this->assertTrue( $fingerprint->getAliasGroups()->isEmpty() ); |
||
| 73 | } |
||
| 74 | |||
| 75 | public function testConstructorSetsValues() { |
||
| 76 | $fingerprint = new Fingerprint( $this->labels, $this->descriptions, $this->aliasGroups ); |
||
| 77 | |||
| 78 | $this->assertEquals( $this->labels, $fingerprint->getLabels() ); |
||
| 79 | $this->assertEquals( $this->descriptions, $fingerprint->getDescriptions() ); |
||
| 80 | $this->assertEquals( $this->aliasGroups, $fingerprint->getAliasGroups() ); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testGetLabel() { |
||
| 84 | $term = new Term( 'en', 'enlabel' ); |
||
| 85 | $this->assertEquals( $term, $this->fingerprint->getLabel( 'en' ) ); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function testSetLabel() { |
||
| 89 | $term = new Term( 'en', 'changed' ); |
||
| 90 | $this->fingerprint->setLabel( 'en', 'changed' ); |
||
| 91 | $this->assertEquals( $term, $this->fingerprint->getLabel( 'en' ) ); |
||
| 92 | } |
||
| 93 | |||
| 94 | public function testRemoveLabel() { |
||
| 95 | $labels = new TermList( [ |
||
| 96 | new Term( 'de', 'delabel' ), |
||
| 97 | ] ); |
||
| 98 | $this->fingerprint->removeLabel( 'en' ); |
||
| 99 | $this->assertEquals( $labels, $this->fingerprint->getLabels() ); |
||
| 100 | } |
||
| 101 | |||
| 102 | public function testRemoveLabelMakesGetterThrowException() { |
||
| 103 | $this->expectException( OutOfBoundsException::class ); |
||
| 104 | $this->fingerprint->removeLabel( 'en' ); |
||
| 105 | $this->fingerprint->getLabel( 'en' ); |
||
| 106 | } |
||
| 107 | |||
| 108 | public function testGetDescription() { |
||
| 109 | $term = new Term( 'en', 'endescription' ); |
||
| 110 | $this->assertEquals( $term, $this->fingerprint->getDescription( 'en' ) ); |
||
| 111 | } |
||
| 112 | |||
| 113 | public function testSetDescription() { |
||
| 114 | $description = new Term( 'en', 'changed' ); |
||
| 115 | $this->fingerprint->setDescription( 'en', 'changed' ); |
||
| 116 | $this->assertEquals( $description, $this->fingerprint->getDescription( 'en' ) ); |
||
| 117 | } |
||
| 118 | |||
| 119 | public function testRemoveDescription() { |
||
| 120 | $descriptions = new TermList( [ |
||
| 121 | new Term( 'de', 'dedescription' ), |
||
| 122 | ] ); |
||
| 123 | $this->fingerprint->removeDescription( 'en' ); |
||
| 124 | $this->assertEquals( $descriptions, $this->fingerprint->getDescriptions() ); |
||
| 125 | } |
||
| 126 | |||
| 127 | public function testRemoveDescriptionMakesGetterThrowException() { |
||
| 128 | $this->expectException( OutOfBoundsException::class ); |
||
| 129 | $this->fingerprint->removeDescription( 'en' ); |
||
| 130 | $this->fingerprint->getDescription( 'en' ); |
||
| 131 | } |
||
| 132 | |||
| 133 | public function testGetAliasGroup() { |
||
| 134 | $aliasGroup = new AliasGroup( 'en', [ 'enalias' ] ); |
||
| 135 | $this->assertEquals( $aliasGroup, $this->fingerprint->getAliasGroup( 'en' ) ); |
||
| 136 | } |
||
| 137 | |||
| 138 | public function testSetAliasGroup() { |
||
| 139 | $aliasGroup = new AliasGroup( 'en', [ 'changed' ] ); |
||
| 140 | $this->fingerprint->setAliasGroup( 'en', [ 'changed' ] ); |
||
| 141 | $this->assertEquals( $aliasGroup, $this->fingerprint->getAliasGroup( 'en' ) ); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function testRemoveAliasGroup() { |
||
| 145 | $aliasGroups = new AliasGroupList( [ |
||
| 146 | new AliasGroup( 'de', [ 'dealias' ] ), |
||
| 147 | ] ); |
||
| 148 | $this->fingerprint->removeAliasGroup( 'en' ); |
||
| 149 | $this->assertEquals( $aliasGroups, $this->fingerprint->getAliasGroups() ); |
||
| 150 | } |
||
| 151 | |||
| 152 | public function testRemoveAliasGroupMakesGetterThrowException() { |
||
| 153 | $this->expectException( OutOfBoundsException::class ); |
||
| 154 | $this->fingerprint->removeAliasGroup( 'en' ); |
||
| 155 | $this->fingerprint->getAliasGroup( 'en' ); |
||
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @dataProvider fingerprintProvider |
||
| 160 | */ |
||
| 161 | public function testFingerprintsEqualThemselves( Fingerprint $fingerprint ) { |
||
| 162 | $this->assertTrue( $fingerprint->equals( $fingerprint ) ); |
||
| 163 | $this->assertTrue( $fingerprint->equals( clone $fingerprint ) ); |
||
| 164 | } |
||
| 165 | |||
| 166 | public function fingerprintProvider() { |
||
| 167 | return [ |
||
| 168 | [ |
||
| 169 | new Fingerprint() |
||
| 170 | ], |
||
| 171 | [ |
||
| 172 | new Fingerprint( |
||
| 173 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 174 | ) |
||
| 175 | ], |
||
| 176 | [ |
||
| 177 | new Fingerprint( |
||
| 178 | new TermList(), |
||
| 179 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 180 | ) |
||
| 181 | ], |
||
| 182 | [ |
||
| 183 | new Fingerprint( |
||
| 184 | new TermList(), |
||
| 185 | new TermList(), |
||
| 186 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 187 | ) |
||
| 188 | ], |
||
| 189 | [ |
||
| 190 | new Fingerprint( |
||
| 191 | new TermList( [ new Term( 'nl', 'bar' ), new Term( 'fr', 'le' ) ] ), |
||
| 192 | new TermList( [ new Term( 'de', 'baz' ) ] ), |
||
| 193 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 194 | ) |
||
| 195 | ], |
||
| 196 | ]; |
||
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @dataProvider differentFingerprintsProvider |
||
| 201 | */ |
||
| 202 | public function testDifferentFingerprintsDoNotEqual( Fingerprint $one, Fingerprint $two ) { |
||
| 203 | $this->assertFalse( $one->equals( $two ) ); |
||
| 204 | } |
||
| 205 | |||
| 206 | public function differentFingerprintsProvider() { |
||
| 207 | return [ |
||
| 208 | [ |
||
| 209 | new Fingerprint(), |
||
| 210 | new Fingerprint( |
||
| 211 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 212 | ) |
||
| 213 | ], |
||
| 214 | [ |
||
| 215 | new Fingerprint( |
||
| 216 | new TermList( [ new Term( 'en', 'foo' ), new Term( 'de', 'bar' ) ] ) |
||
| 217 | ), |
||
| 218 | new Fingerprint( |
||
| 219 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 220 | ) |
||
| 221 | ], |
||
| 222 | [ |
||
| 223 | new Fingerprint(), |
||
| 224 | new Fingerprint( |
||
| 225 | new TermList(), |
||
| 226 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 227 | ) |
||
| 228 | ], |
||
| 229 | [ |
||
| 230 | new Fingerprint(), |
||
| 231 | new Fingerprint( |
||
| 232 | new TermList(), |
||
| 233 | new TermList(), |
||
| 234 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 235 | ) |
||
| 236 | ], |
||
| 237 | [ |
||
| 238 | new Fingerprint( |
||
| 239 | new TermList( [ new Term( 'nl', 'bar' ), new Term( 'fr', 'le' ) ] ), |
||
| 240 | new TermList( [ new Term( 'de', 'HAX' ) ] ), |
||
| 241 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 242 | ), |
||
| 243 | new Fingerprint( |
||
| 244 | new TermList( [ new Term( 'nl', 'bar' ), new Term( 'fr', 'le' ) ] ), |
||
| 245 | new TermList( [ new Term( 'de', 'baz' ) ] ), |
||
| 246 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 247 | ) |
||
| 248 | ], |
||
| 249 | ]; |
||
| 250 | } |
||
| 251 | |||
| 252 | public function testEmptyFingerprintIsEmpty() { |
||
| 253 | $fingerprint = new Fingerprint(); |
||
| 254 | $this->assertTrue( $fingerprint->isEmpty() ); |
||
| 255 | } |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @dataProvider nonEmptyFingerprintProvider |
||
| 259 | */ |
||
| 260 | public function testNonEmptyFingerprintIsNotEmpty( Fingerprint $nonEmptyFingerprint ) { |
||
| 261 | $this->assertFalse( $nonEmptyFingerprint->isEmpty() ); |
||
| 262 | } |
||
| 263 | |||
| 264 | public function nonEmptyFingerprintProvider() { |
||
| 265 | return [ |
||
| 266 | [ |
||
| 267 | new Fingerprint( |
||
| 268 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 269 | ) |
||
| 270 | ], |
||
| 271 | |||
| 272 | [ |
||
| 273 | new Fingerprint( |
||
| 274 | new TermList(), |
||
| 275 | new TermList( [ new Term( 'en', 'foo' ) ] ) |
||
| 276 | ) |
||
| 277 | ], |
||
| 278 | |||
| 279 | [ |
||
| 280 | new Fingerprint( |
||
| 281 | new TermList(), |
||
| 282 | new TermList(), |
||
| 283 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 284 | ) |
||
| 285 | ], |
||
| 286 | |||
| 287 | [ |
||
| 288 | new Fingerprint( |
||
| 289 | new TermList( [ new Term( 'nl', 'bar' ), new Term( 'fr', 'le' ) ] ), |
||
| 290 | new TermList( [ new Term( 'de', 'baz' ) ] ), |
||
| 291 | new AliasGroupList( [ new AliasGroup( 'en', [ 'foo' ] ) ] ) |
||
| 292 | ) |
||
| 293 | ], |
||
| 294 | ]; |
||
| 295 | } |
||
| 296 | |||
| 297 | public function testSetLabels() { |
||
| 298 | $fingerprint = new Fingerprint(); |
||
| 299 | $fingerprint->setLabel( 'en', 'foo' ); |
||
| 300 | |||
| 301 | $labels = new TermList( [ |
||
| 302 | new Term( 'de', 'bar' ) |
||
| 303 | ] ); |
||
| 304 | |||
| 305 | $fingerprint->setLabels( $labels ); |
||
| 306 | |||
| 307 | $this->assertEquals( $labels, $fingerprint->getLabels() ); |
||
| 308 | } |
||
| 309 | |||
| 310 | public function testSetDescriptions() { |
||
| 311 | $fingerprint = new Fingerprint(); |
||
| 312 | $fingerprint->setDescription( 'en', 'foo' ); |
||
| 313 | |||
| 314 | $descriptions = new TermList( [ |
||
| 315 | new Term( 'de', 'bar' ) |
||
| 316 | ] ); |
||
| 317 | |||
| 318 | $fingerprint->setDescriptions( $descriptions ); |
||
| 319 | |||
| 320 | $this->assertEquals( $descriptions, $fingerprint->getDescriptions() ); |
||
| 321 | } |
||
| 322 | |||
| 323 | public function testSetAliasGroups() { |
||
| 324 | $fingerprint = new Fingerprint(); |
||
| 325 | $fingerprint->setAliasGroup( 'en', [ 'foo' ] ); |
||
| 326 | |||
| 327 | $groups = new AliasGroupList( [ |
||
| 328 | new AliasGroup( 'de', [ 'bar' ] ) |
||
| 329 | ] ); |
||
| 330 | |||
| 331 | $fingerprint->setAliasGroups( $groups ); |
||
| 332 | |||
| 333 | $this->assertEquals( $groups, $fingerprint->getAliasGroups() ); |
||
| 334 | } |
||
| 335 | |||
| 336 | public function testEmptyFingerprintDoesNotHaveLabel() { |
||
| 337 | $fingerprint = new Fingerprint(); |
||
| 338 | $this->assertFalse( $fingerprint->hasLabel( 'en' ) ); |
||
| 339 | } |
||
| 340 | |||
| 341 | public function testEmptyFingerprintDoesNotHaveDescription() { |
||
| 342 | $fingerprint = new Fingerprint(); |
||
| 343 | $this->assertFalse( $fingerprint->hasDescription( 'en' ) ); |
||
| 344 | } |
||
| 345 | |||
| 346 | public function testEmptyFingerprintDoesNotHaveAliasGroup() { |
||
| 347 | $fingerprint = new Fingerprint(); |
||
| 348 | $this->assertFalse( $fingerprint->hasAliasGroup( 'en' ) ); |
||
| 349 | } |
||
| 350 | |||
| 351 | public function testHasLabelReturnsTrueOnlyWhenLabelExists() { |
||
| 352 | $fingerprint = new Fingerprint(); |
||
| 353 | $fingerprint->setLabel( 'en', 'foo' ); |
||
| 354 | |||
| 355 | $this->assertTrue( $fingerprint->hasLabel( 'en' ) ); |
||
| 356 | $this->assertFalse( $fingerprint->hasLabel( 'de' ) ); |
||
| 357 | } |
||
| 358 | |||
| 359 | public function testHasDescriptionReturnsTrueOnlyWhenDescriptionExists() { |
||
| 360 | $fingerprint = new Fingerprint(); |
||
| 361 | $fingerprint->setDescription( 'en', 'foo' ); |
||
| 362 | |||
| 363 | $this->assertTrue( $fingerprint->hasDescription( 'en' ) ); |
||
| 364 | $this->assertFalse( $fingerprint->hasDescription( 'de' ) ); |
||
| 365 | } |
||
| 366 | |||
| 367 | public function testHasAliasGroupReturnsTrueOnlyWhenAliasGroupExists() { |
||
| 368 | $fingerprint = new Fingerprint(); |
||
| 369 | $fingerprint->setAliasGroup( 'en', [ 'foo' ] ); |
||
| 370 | |||
| 371 | $this->assertTrue( $fingerprint->hasAliasGroup( 'en' ) ); |
||
| 372 | $this->assertFalse( $fingerprint->hasAliasGroup( 'de' ) ); |
||
| 373 | } |
||
| 374 | |||
| 375 | } |
||
| 376 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..