Issues (52)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/unit/ByPropertyIdGrouperTest.php (1 issue)

Upgrade to new PHP Analysis Engine

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\Services\Tests;
4
5
use ArrayObject;
6
use InvalidArgumentException;
7
use OutOfBoundsException;
8
use PHPUnit\Framework\TestCase;
9
use Wikibase\DataModel\Entity\PropertyId;
10
use Wikibase\DataModel\PropertyIdProvider;
11
use Wikibase\DataModel\Services\ByPropertyIdGrouper;
12
use Wikibase\DataModel\Snak\Snak;
13
14
/**
15
 * @covers \Wikibase\DataModel\Services\ByPropertyIdGrouper
16
 *
17
 * @license GPL-2.0-or-later
18
 * @author Bene* < [email protected] >
19
 * @author Thiemo Kreuz
20
 */
21
class ByPropertyIdGrouperTest extends TestCase {
22
23
	/**
24
	 * @dataProvider validConstructorArgumentProvider
25
	 */
26
	public function testConstructor( $argument ) {
27
		$instance = new ByPropertyIdGrouper( $argument );
28
		$this->assertCount( count( $argument ), $instance->getPropertyIds() );
29
	}
30
31
	public function validConstructorArgumentProvider() {
32
		return [
33
			[ [] ],
34
			[ [ $this->getPropertyIdProviderMock( 'P1' ) ] ],
35
			[ new ArrayObject() ],
36
			[ new ArrayObject( [ $this->getPropertyIdProviderMock( 'P1' ) ] ) ],
37
		];
38
	}
39
40
	/**
41
	 * @dataProvider invalidConstructorArgumentProvider
42
	 */
43
	public function testConstructorThrowsException( $argument ) {
44
		$this->setExpectedException( InvalidArgumentException::class );
0 ignored issues
show
Deprecated Code introduced by Thiemo Mättig
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
		new ByPropertyIdGrouper( $argument );
46
	}
47
48
	public function invalidConstructorArgumentProvider() {
49
		return [
50
			[ null ],
51
			[ 'notAnObject' ],
52
			[ [ null ] ],
53
			[ [ 'notAnObject' ] ],
54
			[ new ArrayObject( [ null ] ) ],
55
			[ new ArrayObject( [ 'notAnObject' ] ) ],
56
		];
57
	}
58
59
	public function provideGetPropertyIds() {
60
		$cases = [];
61
62
		$cases['empty list'] = [
63
			[],
64
			[]
65
		];
66
67
		$cases['some property ids'] = [
68
			[
69
				$this->getPropertyIdProviderMock( 'P42' ),
70
				$this->getPropertyIdProviderMock( 'P23' )
71
			],
72
			[
73
				new PropertyId( 'P42' ),
74
				new PropertyId( 'P23' )
75
			]
76
		];
77
78
		$cases['duplicate property ids'] = [
79
			$this->getPropertyIdProviders(),
80
			[
81
				new PropertyId( 'P42' ),
82
				new PropertyId( 'P23' ),
83
				new PropertyId( 'P15' ),
84
				new PropertyId( 'P10' )
85
			]
86
		];
87
88
		return $cases;
89
	}
90
91
	/**
92
	 * @dataProvider provideGetPropertyIds
93
	 * @param PropertyIdProvider[] $propertyIdProviders
94
	 * @param PropertyId[] $expectedPropertyIds
95
	 */
96
	public function testGetPropertyIds( array $propertyIdProviders, array $expectedPropertyIds ) {
97
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders );
98
		$propertyIds = $byPropertyIdGrouper->getPropertyIds();
99
		$this->assertEquals( $expectedPropertyIds, $propertyIds );
100
	}
101
102
	public function provideGetByPropertyId() {
103
		$cases = [];
104
105
		$cases[] = [
106
			$this->getPropertyIdProviders(),
107
			'P42',
108
			[ 'abc', 'jkl' ]
109
		];
110
111
		$cases[] = [
112
			$this->getPropertyIdProviders(),
113
			'P23',
114
			[ 'def' ]
115
		];
116
117
		return $cases;
118
	}
119
120
	/**
121
	 * @dataProvider provideGetByPropertyId
122
	 */
123
	public function testGetByPropertyId( array $propertyIdProviders, $propertyId, array $expectedValues ) {
124
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders );
125
		$values = $byPropertyIdGrouper->getByPropertyId( new PropertyId( $propertyId ) );
126
		array_walk( $values, function( Snak &$value ) {
127
			$value = $value->getType();
128
		} );
129
		$this->assertEquals( $expectedValues, $values );
130
	}
131
132
	/**
133
	 * @expectedException OutOfBoundsException
134
	 */
135
	public function testGetByPropertyIdThrowsException() {
136
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $this->getPropertyIdProviders() );
137
		$byPropertyIdGrouper->getByPropertyId( new PropertyId( 'P11' ) );
138
	}
139
140
	public function provideHasPropertyId() {
141
		$cases = [];
142
143
		$cases[] = [ $this->getPropertyIdProviders(), 'P42', true ];
144
		$cases[] = [ $this->getPropertyIdProviders(), 'P23', true ];
145
		$cases[] = [ $this->getPropertyIdProviders(), 'P15', true ];
146
		$cases[] = [ $this->getPropertyIdProviders(), 'P10', true ];
147
		$cases[] = [ $this->getPropertyIdProviders(), 'P11', false ];
148
149
		return $cases;
150
	}
151
152
	/**
153
	 * @dataProvider provideHasPropertyId
154
	 */
155
	public function testHasPropertyId( array $propertyIdProviders, $propertyId, $expectedValue ) {
156
		$byPropertyIdGrouper = new ByPropertyIdGrouper( $propertyIdProviders );
157
		$this->assertEquals( $expectedValue, $byPropertyIdGrouper->hasPropertyId( new PropertyId( $propertyId ) ) );
158
	}
159
160
	/**
161
	 * @return PropertyIdProvider[]
162
	 */
163
	private function getPropertyIdProviders() {
164
		return [
165
			$this->getPropertyIdProviderMock( 'P42', 'abc' ),
166
			$this->getPropertyIdProviderMock( 'P23', 'def' ),
167
			$this->getPropertyIdProviderMock( 'P15', 'ghi' ),
168
			$this->getPropertyIdProviderMock( 'P42', 'jkl' ),
169
			$this->getPropertyIdProviderMock( 'P10', 'mno' )
170
		];
171
	}
172
173
	/**
174
	 * Creates a PropertyIdProvider mock which can return a value.
175
	 *
176
	 * @param string $propertyId
177
	 * @param string|null $type
178
	 *
179
	 * @return PropertyIdProvider
180
	 */
181
	private function getPropertyIdProviderMock( $propertyId, $type = null ) {
182
		$propertyIdProvider = $this->createMock( Snak::class );
183
184
		$propertyIdProvider->expects( $this->once() )
185
			->method( 'getPropertyId' )
186
			->will( $this->returnValue( new PropertyId( $propertyId ) ) );
187
188
		$propertyIdProvider->expects( $this->any() )
189
			->method( 'getType' )
190
			->will( $this->returnValue( $type ) );
191
192
		return $propertyIdProvider;
193
	}
194
195
}
196