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; |
||
4 | |||
5 | use InvalidArgumentException; |
||
6 | use Wikibase\DataModel\Entity\ItemId; |
||
7 | use Wikibase\DataModel\Entity\ItemIdSet; |
||
8 | use Wikibase\DataModel\Entity\PropertyId; |
||
9 | use Wikibase\DataModel\SiteLink; |
||
10 | |||
11 | /** |
||
12 | * @covers \Wikibase\DataModel\SiteLink |
||
13 | * |
||
14 | * @group Wikibase |
||
15 | * @group WikibaseDataModel |
||
16 | * |
||
17 | * @license GPL-2.0-or-later |
||
18 | * @author Jeroen De Dauw < [email protected] > |
||
19 | * @author Michał Łazowik |
||
20 | * @author Thiemo Kreuz |
||
21 | */ |
||
22 | class SiteLinkTest extends \PHPUnit\Framework\TestCase { |
||
23 | |||
24 | public function testCanConstruct() { |
||
25 | new SiteLink( 'enwiki', 'Wikidata' ); |
||
26 | $this->assertTrue( true ); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @dataProvider siteIdProvider |
||
31 | */ |
||
32 | public function testGetSiteId( $siteId ) { |
||
33 | $siteLink = new SiteLink( $siteId, 'Wikidata' ); |
||
34 | $this->assertSame( $siteId, $siteLink->getSiteId() ); |
||
35 | } |
||
36 | |||
37 | public function siteIdProvider() { |
||
38 | $argLists = []; |
||
39 | |||
40 | $argLists[] = [ 'enwiki' ]; |
||
41 | $argLists[] = [ 'nlwiki' ]; |
||
42 | $argLists[] = [ 'Nyan!' ]; |
||
43 | |||
44 | return $argLists; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @dataProvider invalidStringIdentifierProvider |
||
49 | */ |
||
50 | public function testCannotConstructWithNonStringSiteId( $invalidSiteId ) { |
||
51 | $this->expectException( InvalidArgumentException::class ); |
||
52 | new SiteLink( $invalidSiteId, 'Wikidata' ); |
||
53 | } |
||
54 | |||
55 | public function invalidStringIdentifierProvider() { |
||
56 | return [ |
||
57 | [ null ], |
||
58 | [ true ], |
||
59 | [ 42 ], |
||
60 | [ '' ], |
||
61 | [ [] ], |
||
62 | ]; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @dataProvider pageNameProvider |
||
67 | */ |
||
68 | public function testGetPageName( $pageName ) { |
||
69 | $siteLink = new SiteLink( 'enwiki', $pageName ); |
||
70 | $this->assertSame( $pageName, $siteLink->getPageName() ); |
||
71 | } |
||
72 | |||
73 | public function pageNameProvider() { |
||
74 | $argLists = []; |
||
75 | |||
76 | $argLists[] = [ 'Wikidata' ]; |
||
77 | $argLists[] = [ 'Nyan_Cat' ]; |
||
78 | $argLists[] = [ 'NYAN DATA ALL ACROSS THE SKY ~=[,,_,,]:3' ]; |
||
79 | |||
80 | return $argLists; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @dataProvider invalidStringIdentifierProvider |
||
85 | */ |
||
86 | public function testCannotConstructWithNonStringPageName( $invalidPageName ) { |
||
87 | $this->expectException( InvalidArgumentException::class ); |
||
88 | new SiteLink( 'enwiki', $invalidPageName ); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @dataProvider badgesProvider |
||
93 | */ |
||
94 | public function testGetBadges( $badges, $expected ) { |
||
95 | $siteLink = new SiteLink( 'enwiki', 'Wikidata', $badges ); |
||
96 | $this->assertEquals( $expected, $siteLink->getBadges() ); |
||
97 | } |
||
98 | |||
99 | public function badgesProvider() { |
||
100 | $argLists = []; |
||
101 | |||
102 | $argLists[] = [ null, [] ]; |
||
103 | |||
104 | $badges = []; |
||
105 | $expected = array_values( $badges ); |
||
106 | |||
107 | $argLists[] = [ $badges, $expected ]; |
||
108 | |||
109 | $badges = [ |
||
110 | new ItemId( 'Q149' ) |
||
111 | ]; |
||
112 | $expected = array_values( $badges ); |
||
113 | |||
114 | $argLists[] = [ $badges, $expected ]; |
||
115 | |||
116 | // removing from the middle of array |
||
117 | $badges = [ |
||
118 | new ItemId( 'Q36' ), |
||
119 | new ItemId( 'Q149' ), |
||
120 | new ItemId( 'Q7' ) |
||
121 | ]; |
||
122 | |||
123 | $key = array_search( |
||
124 | new ItemId( 'Q149' ), |
||
125 | $badges |
||
126 | ); |
||
127 | unset( $badges[$key] ); |
||
128 | |||
129 | $expected = array_values( $badges ); |
||
130 | |||
131 | $argLists[] = [ $badges, $expected ]; |
||
132 | |||
133 | return $argLists; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * @dataProvider invalidBadgesProvider |
||
138 | */ |
||
139 | public function testCannotConstructWithInvalidBadges( $invalidBadges ) { |
||
140 | $this->expectException( InvalidArgumentException::class ); |
||
141 | new SiteLink( 'enwiki', 'Wikidata', $invalidBadges ); |
||
142 | } |
||
143 | |||
144 | public function invalidBadgesProvider() { |
||
145 | return [ |
||
146 | // Stuff that's not an array |
||
147 | [ true ], |
||
148 | [ 42 ], |
||
149 | [ 'nyan nyan' ], |
||
150 | // Arrays with stuff that's not even an object |
||
151 | [ [ 'nyan', 42 ] ], |
||
152 | [ [ 'nyan', [] ] ], |
||
153 | // Arrays with Entities that aren't Items |
||
154 | [ [ new PropertyId( 'P2' ), new ItemId( 'Q149' ) ] ], |
||
155 | [ [ new PropertyId( 'P2' ), new PropertyId( 'P3' ) ] ], |
||
156 | ]; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @dataProvider linkProvider |
||
161 | */ |
||
162 | public function testSelfComparisonReturnsTrue( SiteLink $link ) { |
||
163 | $this->assertTrue( $link->equals( $link ) ); |
||
164 | |||
165 | $linkCopy = unserialize( serialize( $link ) ); |
||
166 | $this->assertTrue( $link->equals( $linkCopy ) ); |
||
167 | $this->assertTrue( $linkCopy->equals( $link ) ); |
||
168 | } |
||
169 | |||
170 | public function linkProvider() { |
||
171 | return [ |
||
172 | [ new SiteLink( 'foo', 'Bar' ) ], |
||
173 | [ new SiteLink( 'foo', 'Bar', [ new ItemId( 'Q42' ), new ItemId( 'Q9001' ) ] ) ], |
||
174 | [ new SiteLink( 'foo', 'foo' ) ], |
||
175 | ]; |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * @dataProvider nonEqualityProvider |
||
180 | */ |
||
181 | public function testGivenNonEqualLinks_equalsReturnsFalse( SiteLink $linkOne, SiteLink $linkTwo ) { |
||
182 | $this->assertFalse( $linkOne->equals( $linkTwo ) ); |
||
183 | $this->assertFalse( $linkTwo->equals( $linkOne ) ); |
||
184 | } |
||
185 | |||
186 | public function nonEqualityProvider() { |
||
187 | return [ |
||
188 | [ |
||
189 | new SiteLink( 'foo', 'bar' ), |
||
190 | new SiteLink( 'foo', 'Bar' ), |
||
191 | ], |
||
192 | [ |
||
193 | new SiteLink( 'foo', 'bar' ), |
||
194 | new SiteLink( 'Foo', 'bar' ), |
||
195 | ], |
||
196 | [ |
||
197 | new SiteLink( 'foo', 'bar' ), |
||
198 | new SiteLink( 'foo', 'bar', [ new ItemId( 'Q42' ) ] ), |
||
199 | ], |
||
200 | [ |
||
201 | new SiteLink( 'foo', 'bar', [ new ItemId( 'Q42' ) ] ), |
||
202 | new SiteLink( 'foo', 'bar', [ new ItemId( 'Q42' ), new ItemId( 'Q9001' ) ] ), |
||
203 | ], |
||
204 | ]; |
||
205 | } |
||
206 | |||
207 | public function testCanConstructWithItemIdSet() { |
||
208 | $badgesArray = [ |
||
209 | new ItemId( 'Q36' ), |
||
210 | new ItemId( 'Q149' ), |
||
211 | ]; |
||
212 | $badges = new ItemIdSet( $badgesArray ); |
||
213 | |||
214 | $siteLink = new SiteLink( 'foo', 'bar', $badges ); |
||
215 | |||
216 | $this->assertEquals( $badgesArray, $siteLink->getBadges() ); |
||
217 | } |
||
218 | |||
219 | public function testGivenNonItemIdCollectionForBadges_constructorThrowsException() { |
||
220 | $this->expectException( InvalidArgumentException::class ); |
||
221 | new SiteLink( 'foo', 'bar', 42 ); |
||
0 ignored issues
–
show
|
|||
222 | } |
||
223 | |||
224 | } |
||
225 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: