ApiTest::testRedirectPage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Elgg\Roles;
4
5
use ElggUser;
6
use PHPUnit_Framework_TestCase;
7
8
class ApiTest extends PHPUnit_Framework_TestCase {
9
10
	/**
11
	 * @var Api
12
	 */
13
	protected $api;
14
15
	public function setUp() {
16
		$this->api = new Api(new DbMock());
17
	}
18
19
	public function testGetReservedRoleName() {
20
		$expected = array(Api::DEFAULT_ROLE, Api::ADMIN_ROLE, Api::VISITOR_ROLE);
21
		$this->assertEquals($expected, $this->api->getReservedRoleNames());
22
	}
23
24
	public function testIsReservedName() {
25
		$this->assertTrue($this->api->isReservedRoleName(Api::DEFAULT_ROLE));
26
		$this->assertFalse($this->api->isReservedRoleName('foobar'));
27
	}
28
29
	public function testGetPermissions() {
30
		$expected = [
31
			'bar/foo' => ['rule' => 'allow'],
32
			'baz' => array('rule' => 'deny', 'redirect' => 'bar/foo'),
33
		];
34
		$this->assertEquals($expected, $this->api->getPermissions($this->api->getRoleByName('default'), 'actions'));
0 ignored issues
show
Security Bug introduced by
It seems like $this->api->getRoleByName('default') targeting Elgg\Roles\Api::getRoleByName() can also be of type false; however, Elgg\Roles\Api::getPermissions() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?
Loading history...
35
	}
36
37
	public function testGetPermissionsWithExtensions() {
38
		$expected = [
39
			'baz' => array('rule' => 'deny', 'redirect' => 'bar/foo'),
40
			'foo/bar' => ['rule' => 'allow'],
41
			'foo/bar/baz' => ['rule' => 'deny'],
42
			'bar/foo' => ['rule' => 'deny']
43
		];
44
		$this->assertEquals($expected, $this->api->getPermissions($this->api->getRoleByName('tester1'), 'actions'));
0 ignored issues
show
Security Bug introduced by
It seems like $this->api->getRoleByName('tester1') targeting Elgg\Roles\Api::getRoleByName() can also be of type false; however, Elgg\Roles\Api::getPermissions() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?
Loading history...
45
	}
46
47
	public function testGetRoleByName() {
48
49
		$role = $this->api->getRoleByName('default');
50
		$this->assertInstanceOf('\ElggRole', $role);
51
		$this->assertEquals('default', $role->name);
52
53
		$this->assertFalse($this->api->getRoleByName('foo'));
54
	}
55
56
	public function testGetSelectable() {
57
58
		$selectable = $this->api->getSelectable();
59
		$this->assertContains($this->api->getRoleByName('tester1'), $selectable);
60
		$this->assertContains($this->api->getRoleByName('tester2'), $selectable);
61
		$this->assertNotContains($this->api->getRoleByName('default'), $selectable);
62
	}
63
64
	public function testFilterName() {
65
66
		$this->assertEquals(Api::VISITOR_ROLE, $this->api->filterName(Api::NO_ROLE));
67
		$this->assertEquals(Api::DEFAULT_ROLE, $this->api->filterName(Api::DEFAULT_ROLE));
68
		$this->assertEquals('tester1', $this->api->filterName('tester1'));
69
70
		$user = new ElggUser();
71
		$this->assertEquals(Api::DEFAULT_ROLE, $this->api->filterName(Api::NO_ROLE, $user));
72
73
		$admin = new ElggUser();
74
		$admin->admin = true;
75
		$this->assertEquals(Api::ADMIN_ROLE, $this->api->filterName(Api::NO_ROLE, $admin));
76
	}
77
78
	public function testSetGetRole() {
79
80
		$user = new ElggUser();
81
82
		$role = $this->api->getRoleByName('tester1');
83
		$this->api->setRole($user, $role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('tester1') on line 82 can also be of type false; however, Elgg\Roles\Api::setRole() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
84
		$this->assertEquals($role, $this->api->getRole($user));
85
86
		$role = $this->api->getRoleByName(Api::DEFAULT_ROLE);
87
		$this->api->setRole($user, $role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByNam...oles\Api::DEFAULT_ROLE) on line 86 can also be of type false; however, Elgg\Roles\Api::setRole() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
88
		$this->assertEquals($role, $this->api->getRole($user));
89
	}
90
91
	public function testContext() {
92
93
		elgg_push_context('foo');
94
		elgg_push_context('bar');
95
96
		$this->assertFalse($this->api->checkContext(['context' => 'baz']));
0 ignored issues
show
Documentation introduced by
array('context' => 'baz') is of type array<string,string,{"context":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
		$this->assertTrue($this->api->checkContext(['context' => 'foo']));
0 ignored issues
show
Documentation introduced by
array('context' => 'foo') is of type array<string,string,{"context":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
98
		$this->assertTrue($this->api->checkContext(['context' => 'bar']));
0 ignored issues
show
Documentation introduced by
array('context' => 'bar') is of type array<string,string,{"context":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
99
		$this->assertTrue($this->api->checkContext(['context' => ['foo', 'bar']]));
0 ignored issues
show
Documentation introduced by
array('context' => array('foo', 'bar')) is of type array<string,array<integ...",\"1\":\"string\"}>"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
		$this->assertTrue($this->api->checkContext(['context' => ['bar']]));
0 ignored issues
show
Documentation introduced by
array('context' => array('bar')) is of type array<string,array<integ...,{\"0\":\"string\"}>"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
101
102
		elgg_pop_context();
103
		elgg_pop_context();
104
	}
105
106
	public function testContextStrict() {
107
108
		elgg_push_context('foo');
109
		elgg_push_context('bar');
110
111
		$this->assertTrue($this->api->checkContext(['context' => 'bar'], true));
0 ignored issues
show
Documentation introduced by
array('context' => 'bar') is of type array<string,string,{"context":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
112
		$this->assertFalse($this->api->checkContext(['context' => 'baz'], true));
0 ignored issues
show
Documentation introduced by
array('context' => 'baz') is of type array<string,string,{"context":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
113
		$this->assertFalse($this->api->checkContext(['context' => 'foo'], true));
0 ignored issues
show
Documentation introduced by
array('context' => 'foo') is of type array<string,string,{"context":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
		$this->assertTrue($this->api->checkContext(['context' => ['foo', 'bar']], true));
0 ignored issues
show
Documentation introduced by
array('context' => array('foo', 'bar')) is of type array<string,array<integ...",\"1\":\"string\"}>"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
115
		$this->assertTrue($this->api->checkContext(['context' => ['bar']], true));
0 ignored issues
show
Documentation introduced by
array('context' => array('bar')) is of type array<string,array<integ...,{\"0\":\"string\"}>"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
116
117
		elgg_pop_context();
118
		elgg_pop_context();
119
	}
120
121
	public function testDenyView() {
122
		$role = $this->api->getRoleByName('deny');
123
		$this->api->setupViews($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 122 can also be of type false; however, Elgg\Roles\Api::setupViews() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
124
		$this->assertEquals('', elgg_view('foo/bar'));
125
	}
126
127
	public function testAllowView() {
128
		$role = $this->api->getRoleByName('allow');
129
		$this->api->setupViews($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 128 can also be of type false; however, Elgg\Roles\Api::setupViews() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
130
		$this->assertEquals('bar', elgg_view('foo/bar'));
131
	}
132
133
	public function testExtendView() {
134
		$role = $this->api->getRoleByName('extend');
135
		$this->api->setupViews($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('extend') on line 134 can also be of type false; however, Elgg\Roles\Api::setupViews() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
136
		$this->assertEquals('bazbar', elgg_view('foo/bar'));
137
	}
138
139
	public function testReplaceView() {
140
		$role = $this->api->getRoleByName('replace');
141
		$this->api->setupViews($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('replace') on line 140 can also be of type false; however, Elgg\Roles\Api::setupViews() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
142
		$this->assertEquals('baz2', elgg_view('foo/baz'));
143
	}
144
145
	public function testDenyAction() {
146
		$role = $this->api->getRoleByName('deny');
147
		$this->assertFalse($this->api->actionGatekeeper($role, 'foo/bar'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 146 can also be of type false; however, Elgg\Roles\Api::actionGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
148
		$this->assertNull($this->api->actionGatekeeper($role, 'foo/baz'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 146 can also be of type false; however, Elgg\Roles\Api::actionGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
149
	}
150
151
	public function testAllowAction() {
152
		$role = $this->api->getRoleByName('allow');
153
		$this->assertNull($this->api->actionGatekeeper($role, 'foo/bar'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 152 can also be of type false; however, Elgg\Roles\Api::actionGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
154
		$this->assertNull($this->api->actionGatekeeper($role, 'foo/baz'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 152 can also be of type false; however, Elgg\Roles\Api::actionGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
155
	}
156
157
	public function testDenyPage() {
158
		$role = $this->api->getRoleByName('deny');
159
		$this->assertEquals(['forward' => REFERRER, 'error' => true], $this->api->pageGatekeeper($role, 'foo/bar'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 158 can also be of type false; however, Elgg\Roles\Api::pageGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
160
		$this->assertEquals(['forward' => false, 'error' => false], $this->api->pageGatekeeper($role, 'foo/baz'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 158 can also be of type false; however, Elgg\Roles\Api::pageGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
161
	}
162
163
	public function testAllowPage() {
164
		$role = $this->api->getRoleByName('allow');
165
		$this->assertEquals(['forward' => false, 'error' => false], $this->api->pageGatekeeper($role, 'foo/bar'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 164 can also be of type false; however, Elgg\Roles\Api::pageGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
166
		$this->assertEquals(['forward' => false, 'error' => false], $this->api->pageGatekeeper($role, 'foo/baz'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 164 can also be of type false; however, Elgg\Roles\Api::pageGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
167
	}
168
169
	public function testRedirectPage() {
170
		$role = $this->api->getRoleByName('replace');
171
		$this->assertEquals(['forward' => 'foo/baz', 'error' => false], $this->api->pageGatekeeper($role, 'foo/bar'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('replace') on line 170 can also be of type false; however, Elgg\Roles\Api::pageGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
172
		$this->assertEquals(['forward' => false, 'error' => false], $this->api->pageGatekeeper($role, 'foo/baz'));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('replace') on line 170 can also be of type false; however, Elgg\Roles\Api::pageGatekeeper() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
173
	}
174
175 View Code Duplication
	public function testDenyHook() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
176
177
		elgg_register_plugin_hook_handler('foo', 'bar', '\Elgg\Values::getTrue');
178
		$role = $this->api->getRoleByName('deny');
179
		$this->api->setupHooks($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 178 can also be of type false; however, Elgg\Roles\Api::setupHooks() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
180
181
		$expected = false;
182
		$actual = elgg_trigger_plugin_hook('foo', 'bar', null, $expected);
183
		$this->assertEquals($expected, $actual);
184
	}
185
186 View Code Duplication
	public function testAllowHook() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
188
		elgg_register_plugin_hook_handler('foo', 'bar', '\Elgg\Values::getTrue');
189
		$role = $this->api->getRoleByName('allow');
190
		$this->api->setupHooks($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 189 can also be of type false; however, Elgg\Roles\Api::setupHooks() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
191
192
		$expected = true;
193
		$actual = elgg_trigger_plugin_hook('foo', 'bar', null, null);
194
		$this->assertEquals($expected, $actual);
195
	}
196
197 View Code Duplication
	public function testExtendHook() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
198
199
		elgg_register_plugin_hook_handler('foo', 'bar', '\Elgg\Values::getTrue');
200
		$role = $this->api->getRoleByName('extend');
201
		$this->api->setupHooks($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('extend') on line 200 can also be of type false; however, Elgg\Roles\Api::setupHooks() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
202
203
		$expected = false;
204
		$actual = elgg_trigger_plugin_hook('foo', 'bar', null, null);
205
		$this->assertEquals($expected, $actual);
206
	}
207
208 View Code Duplication
	public function testReplaceHook() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
210
		elgg_register_plugin_hook_handler('foo', 'bar', '\Elgg\Values::getTrue');
211
		$role = $this->api->getRoleByName('replace');
212
		$this->api->setupHooks($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('replace') on line 211 can also be of type false; however, Elgg\Roles\Api::setupHooks() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
213
214
		$expected = false;
215
		$actual = elgg_trigger_plugin_hook('foo', 'bar', null, null);
216
		$this->assertEquals($expected, $actual);
217
	}
218
219 View Code Duplication
	public function testDenyEvent() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
220
221
		elgg_register_event_handler('foo', 'bar', '\Elgg\Values::getFalse');
222
		$role = $this->api->getRoleByName('deny');
223
		$this->api->setupEvents($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 222 can also be of type false; however, Elgg\Roles\Api::setupEvents() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
224
225
		$expected = true;
226
		$actual = elgg_trigger_event('foo', 'bar');
227
		$this->assertEquals($expected, $actual);
228
	}
229
230 View Code Duplication
	public function testAllowEvent() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
231
232
		elgg_register_event_handler('foo', 'bar', '\Elgg\Values::getFalse');
233
		$role = $this->api->getRoleByName('allow');
234
		$this->api->setupEvents($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 233 can also be of type false; however, Elgg\Roles\Api::setupEvents() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
235
236
		$expected = false;
237
		$actual = elgg_trigger_event('foo', 'bar');
238
		$this->assertEquals($expected, $actual);
239
	}
240
241 View Code Duplication
	public function testExtendEvent() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
242
243
		elgg_register_event_handler('foo', 'bar', '\Elgg\Values::getTrue');
244
		$role = $this->api->getRoleByName('extend');
245
		$this->api->setupEvents($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('extend') on line 244 can also be of type false; however, Elgg\Roles\Api::setupEvents() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
246
247
		$expected = false;
248
		$actual = elgg_trigger_event('foo', 'bar');
249
		$this->assertEquals($expected, $actual);
250
	}
251
252 View Code Duplication
	public function testReplaceEvent() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
253
254
		elgg_register_event_handler('foo', 'bar', '\Elgg\Values::getTrue');
255
		$role = $this->api->getRoleByName('replace');
256
		$this->api->setupEvents($role);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('replace') on line 255 can also be of type false; however, Elgg\Roles\Api::setupEvents() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
257
258
		$expected = false;
259
		$actual = elgg_trigger_event('foo', 'bar');
260
		$this->assertEquals($expected, $actual);
261
	}
262
263
	public function testDenyMenu() {
264
		$role = $this->api->getRoleByName('deny');
265
266
		$menu = $this->getMenu();
267
		$this->assertEmpty($this->api->setupMenu($role, 'foo', $menu));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 264 can also be of type false; however, Elgg\Roles\Api::setupMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
268
269
		$filtered_menu = $this->api->setupMenu($role, 'bar', $menu);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('deny') on line 264 can also be of type false; however, Elgg\Roles\Api::setupMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
270
		$this->assertNotContains($menu['parent'], $filtered_menu);
271
		$this->assertNotContains($menu['child'], $filtered_menu);
272
	}
273
274
	public function testAllowMenu() {
275
		$role = $this->api->getRoleByName('allow');
276
		$menu = $this->getMenu();
277
		$this->assertEquals($menu, $this->api->setupMenu($role, 'foo', $menu));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 275 can also be of type false; however, Elgg\Roles\Api::setupMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
278
		$this->assertEquals($menu, $this->api->setupMenu($role, 'bar', $menu));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('allow') on line 275 can also be of type false; however, Elgg\Roles\Api::setupMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
279
	}
280
281
	public function testExtendMenu() {
282
		$role = $this->api->getRoleByName('extend');
283
		$menu = $this->getMenu();
284
		$this->assertEquals(count($menu) + 1, count($this->api->setupMenu($role, 'foo', $menu)));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('extend') on line 282 can also be of type false; however, Elgg\Roles\Api::setupMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
285
	}
286
287
	public function testReplaceMenu() {
288
		$role = $this->api->getRoleByName('replace');
289
290
		$menu = $this->getMenu();
291
292
		$filtered_menu = $this->api->setupMenu($role, 'bar', $menu);
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('replace') on line 288 can also be of type false; however, Elgg\Roles\Api::setupMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
293
		$this->assertEquals('baz2', $filtered_menu['parent']->getName());
294
		$this->assertEquals('baz2', $filtered_menu['child']->getParentName());
295
	}
296
297
	public function getMenu() {
298
299
		$menu = array();
300
		$menu['parent'] = \ElggMenuItem::factory(array(
301
					'name' => 'baz',
302
					'href' => 'baz',
303
					'text' => 'baz',
304
		));
305
		$menu['bad'] = 'bad';
306
		$menu['child'] = \ElggMenuItem::factory(array(
307
					'name' => 'baz:child',
308
					'parent_name' => 'baz',
309
					'href' => 'baz/child',
310
					'text' => 'baz:child'
311
		));
312
		return $menu;
313
	}
314
315
	public function testCleanMenu() {
316
317
		$role = $this->api->getRoleByName('tester1');
318
		$item = \ElggMenuItem::factory(array(
319
			'name' => 'foo',
320
			'href' => 'action/bar/foo',
321
			'text' => 'foo',
322
		));
323
324
		$this->assertNotContains($item, $this->api->cleanMenu($role, [$item]));
0 ignored issues
show
Security Bug introduced by
It seems like $role defined by $this->api->getRoleByName('tester1') on line 317 can also be of type false; however, Elgg\Roles\Api::cleanMenu() does only seem to accept object<ElggRole>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
325
	}
326
327
	/**
328
	 * @dataProvider providerMatchPath
329
	 */
330
	public function testMatchPath($expectation, $a, $b) {
331
		if ($expectation === true) {
332
			$this->assertTrue($this->api->matchPath($a, $b));
333
		} else if ($expectation === false) {
334
			$this->assertFalse($this->api->matchPath($a, $b));
335
		}
336
	}
337
338
	public function providerMatchPath() {
339
340
		return array(
341
			array(
342
				true,
343
				'blog/edit',
344
				'/blog/edit',
345
			),
346
			array(
347
				true,
348
				'blog/save',
349
				elgg_normalize_url('blog/save'),
350
			),
351
			array(
352
				false,
353
				'blog/view/123',
354
				'/groups/blog/view/123',
355
			),
356
			array(
357
				true,
358
				'/blog/add/234',
359
				'blog/add/234',
360
			),
361
			array(
362
				false,
363
				'/blog/new/345',
364
				'/blog/new/',
365
			),
366
			array(
367
				true,
368
				'regexp(/^admin\/((?!administer_utilities\/reportedcontent).)*$/)',
369
				'admin/plugins',
370
			),
371
			array(
372
				false,
373
				'regexp(/^admin\/((?!administer_utilities\/reportedcontent).)*$/)',
374
				'/admin/reportedcontent/123',
375
			),
376
			array(
377
				true,
378
				'/blog/owner/\d+/.*',
379
				'/blog/owner/25/some-title',
380
			),
381
			array(
382
				true,
383
				'/blog/(view|edit)/\d+/.*',
384
				'blog/edit/15/some-title',
385
			),
386
		);
387
	}
388
}
389