Completed
Push — 3 ( aac828...50aa1f )
by Damian
19:02 queued 11:34
created

testPasswordEncryptionUpdatedOnChangedPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package framework
4
 * @subpackage tests
5
 */
6
class MemberTest extends FunctionalTest {
7
	protected static $fixture_file = 'MemberTest.yml';
8
9
	protected $orig = array();
10
	protected $local = null;
11
12
	protected $illegalExtensions = array(
13
		'Member' => array(
14
			// TODO Coupling with modules, this should be resolved by automatically
15
			// removing all applied extensions before a unit test
16
			'ForumRole',
17
			'OpenIDAuthenticatedRole'
18
		)
19
	);
20
21
	public function __construct() {
22
		parent::__construct();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class FunctionalTest as the method __construct() does only exist in the following sub-classes of FunctionalTest: MemberTest. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
23
24
		//Setting the locale has to happen in the constructor (using the setUp and tearDown methods doesn't work)
25
		//This is because the test relies on the yaml file being interpreted according to a particular date format
26
		//and this setup occurs before the setUp method is run
27
		$this->local = i18n::default_locale();
0 ignored issues
show
Deprecated Code introduced by
The method i18n::default_locale() has been deprecated with message: since version 4.0; Use the "i18n.default_locale" config setting 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...
28
		i18n::set_default_locale('en_US');
0 ignored issues
show
Deprecated Code introduced by
The method i18n::set_default_locale() has been deprecated with message: since version 4.0; Use the "i18n.default_locale" config setting 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...
29
	}
30
31
	public function __destruct() {
32
		i18n::set_default_locale($this->local);
0 ignored issues
show
Deprecated Code introduced by
The method i18n::set_default_locale() has been deprecated with message: since version 4.0; Use the "i18n.default_locale" config setting 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...
33
	}
34
35
	public function setUp() {
36
		parent::setUp();
37
38
		$this->orig['Member_unique_identifier_field'] = Member::config()->unique_identifier_field;
0 ignored issues
show
Documentation introduced by
The property unique_identifier_field does not exist on object<Config_ForClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
39
		Member::config()->unique_identifier_field = 'Email';
0 ignored issues
show
Documentation introduced by
The property unique_identifier_field does not exist on object<Config_ForClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
40
		Member::set_password_validator(null);
41
	}
42
43
	public function tearDown() {
44
		Member::config()->unique_identifier_field = $this->orig['Member_unique_identifier_field'];
0 ignored issues
show
Documentation introduced by
The property unique_identifier_field does not exist on object<Config_ForClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
45
		parent::tearDown();
46
	}
47
48
	public function testPasswordEncryptionUpdatedOnChangedPassword()
49
	{
50
		Config::inst()->update('Security', 'password_encryption_algorithm', 'none');
51
		$member = Member::create();
52
		$member->SetPassword = 'password';
0 ignored issues
show
Bug introduced by
The property SetPassword does not seem to exist. Did you mean Password?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
53
		$member->write();
54
		$this->assertEquals('password', $member->Password);
55
		$this->assertEquals('none', $member->PasswordEncryption);
56
		Config::inst()->update('Security', 'password_encryption_algorithm', 'blowfish');
57
		$member->SetPassword = 'newpassword';
0 ignored issues
show
Bug introduced by
The property SetPassword does not seem to exist. Did you mean Password?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
58
		$member->write();
59
		$this->assertNotEquals('password', $member->Password);
60
		$this->assertNotEquals('newpassword', $member->Password);
61
		$this->assertEquals('blowfish', $member->PasswordEncryption);
62
	}
63
64
	/**
65
	 * @expectedException ValidationException
66
	 */
67
	public function testWriteDoesntMergeNewRecordWithExistingMember() {
68
		$m1 = new Member();
69
		$m1->Email = '[email protected]';
70
		$m1->write();
71
72
		$m2 = new Member();
73
		$m2->Email = '[email protected]';
74
		$m2->write();
75
	}
76
77
	/**
78
	 * @expectedException ValidationException
79
	 */
80
	public function testWriteDoesntMergeExistingMemberOnIdentifierChange() {
81
		$m1 = new Member();
82
		$m1->Email = '[email protected]';
83
		$m1->write();
84
85
		$m2 = new Member();
86
		$m2->Email = '[email protected]';
87
		$m2->write();
88
89
		$m2->Email = '[email protected]';
90
		$m2->write();
91
	}
92
93
	public function testDefaultPasswordEncryptionOnMember() {
94
		$memberWithPassword = new Member();
95
		$memberWithPassword->Password = 'mypassword';
96
		$memberWithPassword->write();
97
		$this->assertEquals(
98
			$memberWithPassword->PasswordEncryption,
99
			Security::config()->password_encryption_algorithm,
100
			'Password encryption is set for new member records on first write (with setting "Password")'
101
		);
102
103
		$memberNoPassword = new Member();
104
		$memberNoPassword->write();
105
		$this->assertNull(
106
			$memberNoPassword->PasswordEncryption,
107
			'Password encryption is not set for new member records on first write, when not setting a "Password")'
108
		);
109
	}
110
111
	public function testKeepsEncryptionOnEmptyPasswords() {
112
		$member = new Member();
113
		$member->Password = 'mypassword';
114
		$member->PasswordEncryption = 'sha1_v2.4';
115
		$member->write();
116
117
		$member->Password = '';
118
		$member->write();
119
120
		$this->assertEquals(
121
			Security::config()->get('password_encryption_algorithm'),
122
            $member->PasswordEncryption
123
		);
124
		$result = $member->checkPassword('');
125
		$this->assertTrue($result->valid());
126
	}
127
128
	public function testSetPassword() {
129
		$member = $this->objFromFixture('Member', 'test');
130
		$member->Password = "test1";
0 ignored issues
show
Documentation introduced by
The property Password does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
131
		$member->write();
132
		$result = $member->checkPassword('test1');
133
		$this->assertTrue($result->valid());
134
	}
135
136
	/**
137
	 * Test that password changes are logged properly
138
	 */
139
	public function testPasswordChangeLogging() {
140
		$member = $this->objFromFixture('Member', 'test');
141
		$this->assertNotNull($member);
142
		$member->Password = "test1";
0 ignored issues
show
Documentation introduced by
The property Password does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
143
		$member->write();
144
145
		$member->Password = "test2";
0 ignored issues
show
Documentation introduced by
The property Password does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
146
		$member->write();
147
148
		$member->Password = "test3";
0 ignored issues
show
Documentation introduced by
The property Password does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
149
		$member->write();
150
151
		$passwords = DataObject::get("MemberPassword", "\"MemberID\" = $member->ID", "\"Created\" DESC, \"ID\" DESC")
152
			->getIterator();
153
		$this->assertNotNull($passwords);
154
		$passwords->rewind();
155
		$this->assertTrue($passwords->current()->checkPassword('test3'), "Password test3 not found in MemberRecord");
156
157
		$passwords->next();
158
		$this->assertTrue($passwords->current()->checkPassword('test2'), "Password test2 not found in MemberRecord");
159
160
		$passwords->next();
161
		$this->assertTrue($passwords->current()->checkPassword('test1'), "Password test1 not found in MemberRecord");
162
163
		$passwords->next();
164
		$this->assertInstanceOf('DataObject', $passwords->current());
165
		$this->assertTrue($passwords->current()->checkPassword('1nitialPassword'),
166
			"Password 1nitialPassword not found in MemberRecord");
167
168
		//check we don't retain orphaned records when a member is deleted
169
		$member->delete();
170
171
		$passwords = MemberPassword::get()->filter('MemberID', $member->OldID);
172
173
		$this->assertCount(0, $passwords);
174
	}
175
176
	/**
177
	 * Test that changed passwords will send an email
178
	 */
179
	public function testChangedPasswordEmaling() {
180
		Config::inst()->update('Member', 'notify_password_change', true);
181
182
		$this->clearEmails();
183
184
		$member = $this->objFromFixture('Member', 'test');
185
		$this->assertNotNull($member);
186
		$valid = $member->changePassword('32asDF##$$%%');
187
		$this->assertTrue($valid->valid());
188
189
		$this->assertEmailSent('[email protected]', null, 'Your password has been changed',
190
			'/testuser@example\.com/');
191
192
	}
193
194
	/**
195
	 * Test that triggering "forgotPassword" sends an Email with a reset link
196
	 */
197
	public function testForgotPasswordEmaling() {
198
		$this->clearEmails();
199
		$this->autoFollowRedirection = false;
200
201
		$member = $this->objFromFixture('Member', 'test');
202
		$this->assertNotNull($member);
203
204
		// Initiate a password-reset
205
		$response = $this->post('Security/LostPasswordForm', array('Email' => $member->Email));
206
207
		$this->assertEquals($response->getStatusCode(), 302);
208
209
		// We should get redirected to Security/passwordsent
210
		$this->assertContains('Security/passwordsent/[email protected]',
211
			urldecode($response->getHeader('Location')));
212
213
		// Check existance of reset link
214
		$this->assertEmailSent("[email protected]", null, 'Your password reset link',
215
			'/Security\/changepassword\?m='.$member->ID.'&t=[^"]+/');
216
	}
217
218
	/**
219
	 * Test that passwords validate against NZ e-government guidelines
220
	 *  - don't allow the use of the last 6 passwords
221
	 *  - require at least 3 of lowercase, uppercase, digits and punctuation
222
	 *  - at least 7 characters long
223
	 */
224
	public function testValidatePassword() {
225
		$member = $this->objFromFixture('Member', 'test');
226
		$this->assertNotNull($member);
227
228
		Member::set_password_validator(new MemberTest_PasswordValidator());
229
230
		// BAD PASSWORDS
231
232
		$valid = $member->changePassword('shorty');
233
		$this->assertFalse($valid->valid());
234
		$this->assertContains("TOO_SHORT", $valid->codeList());
235
236
		$valid = $member->changePassword('longone');
237
		$this->assertNotContains("TOO_SHORT", $valid->codeList());
238
		$this->assertContains("LOW_CHARACTER_STRENGTH", $valid->codeList());
239
		$this->assertFalse($valid->valid());
240
241
		$valid = $member->changePassword('w1thNumb3rs');
242
		$this->assertNotContains("LOW_CHARACTER_STRENGTH", $valid->codeList());
243
		$this->assertTrue($valid->valid());
244
245
		// Clear out the MemberPassword table to ensure that the system functions properly in that situation
246
		DB::query("DELETE FROM \"MemberPassword\"");
247
248
		// GOOD PASSWORDS
249
250
		$valid = $member->changePassword('withSym###Ls');
251
		$this->assertNotContains("LOW_CHARACTER_STRENGTH", $valid->codeList());
252
		$this->assertTrue($valid->valid());
253
254
		$valid = $member->changePassword('withSym###Ls2');
255
		$this->assertTrue($valid->valid());
256
257
		$valid = $member->changePassword('withSym###Ls3');
258
		$this->assertTrue($valid->valid());
259
260
		$valid = $member->changePassword('withSym###Ls4');
261
		$this->assertTrue($valid->valid());
262
263
		$valid = $member->changePassword('withSym###Ls5');
264
		$this->assertTrue($valid->valid());
265
266
		$valid = $member->changePassword('withSym###Ls6');
267
		$this->assertTrue($valid->valid());
268
269
		$valid = $member->changePassword('withSym###Ls7');
270
		$this->assertTrue($valid->valid());
271
272
		// CAN'T USE PASSWORDS 2-7, but I can use pasword 1
273
274
		$valid = $member->changePassword('withSym###Ls2');
275
		$this->assertFalse($valid->valid());
276
		$this->assertContains("PREVIOUS_PASSWORD", $valid->codeList());
277
278
		$valid = $member->changePassword('withSym###Ls5');
279
		$this->assertFalse($valid->valid());
280
		$this->assertContains("PREVIOUS_PASSWORD", $valid->codeList());
281
282
		$valid = $member->changePassword('withSym###Ls7');
283
		$this->assertFalse($valid->valid());
284
		$this->assertContains("PREVIOUS_PASSWORD", $valid->codeList());
285
286
		$valid = $member->changePassword('withSym###Ls');
287
		$this->assertTrue($valid->valid());
288
289
		// HAVING DONE THAT, PASSWORD 2 is now available from the list
290
291
		$valid = $member->changePassword('withSym###Ls2');
292
		$this->assertTrue($valid->valid());
293
294
		$valid = $member->changePassword('withSym###Ls3');
295
		$this->assertTrue($valid->valid());
296
297
		$valid = $member->changePassword('withSym###Ls4');
298
		$this->assertTrue($valid->valid());
299
300
		Member::set_password_validator(null);
301
	}
302
303
	/**
304
	 * Test that the PasswordExpiry date is set when passwords are changed
305
	 */
306
	public function testPasswordExpirySetting() {
307
		Member::config()->password_expiry_days = 90;
0 ignored issues
show
Documentation introduced by
The property password_expiry_days does not exist on object<Config_ForClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
308
309
		$member = $this->objFromFixture('Member', 'test');
310
		$this->assertNotNull($member);
311
		$valid = $member->changePassword("Xx?1234234");
312
		$this->assertTrue($valid->valid());
313
314
		$expiryDate = date('Y-m-d', time() + 90*86400);
315
		$this->assertEquals($expiryDate, $member->PasswordExpiry);
316
317
		Member::config()->password_expiry_days = null;
0 ignored issues
show
Documentation introduced by
The property password_expiry_days does not exist on object<Config_ForClass>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
318
		$valid = $member->changePassword("Xx?1234235");
319
		$this->assertTrue($valid->valid());
320
321
		$this->assertNull($member->PasswordExpiry);
322
	}
323
324
	public function testIsPasswordExpired() {
325
		$member = $this->objFromFixture('Member', 'test');
326
		$this->assertNotNull($member);
327
		$this->assertFalse($member->isPasswordExpired());
328
329
		$member = $this->objFromFixture('Member', 'noexpiry');
330
		$member->PasswordExpiry = null;
0 ignored issues
show
Documentation introduced by
The property PasswordExpiry does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
331
		$this->assertFalse($member->isPasswordExpired());
332
333
		$member = $this->objFromFixture('Member', 'expiredpassword');
334
		$this->assertTrue($member->isPasswordExpired());
335
336
		// Check the boundary conditions
337
		// If PasswordExpiry == today, then it's expired
338
		$member->PasswordExpiry = date('Y-m-d');
0 ignored issues
show
Documentation introduced by
The property PasswordExpiry does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
339
		$this->assertTrue($member->isPasswordExpired());
340
341
		// If PasswordExpiry == tomorrow, then it's not
342
		$member->PasswordExpiry = date('Y-m-d', time() + 86400);
0 ignored issues
show
Documentation introduced by
The property PasswordExpiry does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
343
		$this->assertFalse($member->isPasswordExpired());
344
345
	}
346
347
	public function testMemberWithNoDateFormatFallsbackToGlobalLocaleDefaultFormat() {
348
		Config::inst()->update('i18n', 'date_format', 'yyyy-MM-dd');
349
		Config::inst()->update('i18n', 'time_format', 'H:mm');
350
		$member = $this->objFromFixture('Member', 'noformatmember');
351
		$this->assertEquals('yyyy-MM-dd', $member->DateFormat);
352
		$this->assertEquals('H:mm', $member->TimeFormat);
353
	}
354
355
	public function testInGroups() {
356
		$staffmember = $this->objFromFixture('Member', 'staffmember');
357
		$managementmember = $this->objFromFixture('Member', 'managementmember');
358
		$accountingmember = $this->objFromFixture('Member', 'accountingmember');
359
		$ceomember = $this->objFromFixture('Member', 'ceomember');
360
361
		$staffgroup = $this->objFromFixture('Group', 'staffgroup');
362
		$managementgroup = $this->objFromFixture('Group', 'managementgroup');
363
		$accountinggroup = $this->objFromFixture('Group', 'accountinggroup');
364
		$ceogroup = $this->objFromFixture('Group', 'ceogroup');
365
366
		$this->assertTrue(
367
			$staffmember->inGroups(array($staffgroup, $managementgroup)),
368
			'inGroups() succeeds if a membership is detected on one of many passed groups'
369
		);
370
		$this->assertFalse(
371
			$staffmember->inGroups(array($ceogroup, $managementgroup)),
372
			'inGroups() fails if a membership is detected on none of the passed groups'
373
		);
374
		$this->assertFalse(
375
			$ceomember->inGroups(array($staffgroup, $managementgroup), true),
376
			'inGroups() fails if no direct membership is detected on any of the passed groups (in strict mode)'
377
		);
378
	}
379
380
	public function testAddToGroupByCode() {
381
		$grouplessMember = $this->objFromFixture('Member', 'grouplessmember');
382
		$memberlessGroup = $this->objFromFixture('Group','memberlessgroup');
383
384
		$this->assertFalse($grouplessMember->Groups()->exists());
385
		$this->assertFalse($memberlessGroup->Members()->exists());
386
387
		$grouplessMember->addToGroupByCode('memberless');
388
389
		$this->assertEquals($memberlessGroup->Members()->Count(), 1);
390
		$this->assertEquals($grouplessMember->Groups()->Count(), 1);
391
392
		$grouplessMember->addToGroupByCode('somegroupthatwouldneverexist', 'New Group');
393
		$this->assertEquals($grouplessMember->Groups()->Count(), 2);
394
395
		$group = DataObject::get_one('Group', array(
396
			'"Group"."Code"' => 'somegroupthatwouldneverexist'
397
		));
398
		$this->assertNotNull($group);
399
		$this->assertEquals($group->Code, 'somegroupthatwouldneverexist');
400
		$this->assertEquals($group->Title, 'New Group');
401
402
	}
403
404
	public function testRemoveFromGroupByCode() {
405
		$grouplessMember = $this->objFromFixture('Member', 'grouplessmember');
406
		$memberlessGroup = $this->objFromFixture('Group','memberlessgroup');
407
408
		$this->assertFalse($grouplessMember->Groups()->exists());
409
		$this->assertFalse($memberlessGroup->Members()->exists());
410
411
		$grouplessMember->addToGroupByCode('memberless');
412
413
		$this->assertEquals($memberlessGroup->Members()->Count(), 1);
414
		$this->assertEquals($grouplessMember->Groups()->Count(), 1);
415
416
		$grouplessMember->addToGroupByCode('somegroupthatwouldneverexist', 'New Group');
417
		$this->assertEquals($grouplessMember->Groups()->Count(), 2);
418
419
		$group = DataObject::get_one('Group', "\"Code\" = 'somegroupthatwouldneverexist'");
420
		$this->assertNotNull($group);
421
		$this->assertEquals($group->Code, 'somegroupthatwouldneverexist');
422
		$this->assertEquals($group->Title, 'New Group');
423
424
		$grouplessMember->removeFromGroupByCode('memberless');
425
		$this->assertEquals($memberlessGroup->Members()->Count(), 0);
426
		$this->assertEquals($grouplessMember->Groups()->Count(), 1);
427
428
		$grouplessMember->removeFromGroupByCode('somegroupthatwouldneverexist');
429
		$this->assertEquals($grouplessMember->Groups()->Count(), 0);
430
	}
431
432
	public function testInGroup() {
433
		$staffmember = $this->objFromFixture('Member', 'staffmember');
434
		$managementmember = $this->objFromFixture('Member', 'managementmember');
435
		$accountingmember = $this->objFromFixture('Member', 'accountingmember');
436
		$ceomember = $this->objFromFixture('Member', 'ceomember');
437
438
		$staffgroup = $this->objFromFixture('Group', 'staffgroup');
439
		$managementgroup = $this->objFromFixture('Group', 'managementgroup');
440
		$accountinggroup = $this->objFromFixture('Group', 'accountinggroup');
441
		$ceogroup = $this->objFromFixture('Group', 'ceogroup');
442
443
		$this->assertTrue(
444
			$staffmember->inGroup($staffgroup),
445
			'Direct group membership is detected'
446
		);
447
		$this->assertTrue(
448
			$managementmember->inGroup($staffgroup),
449
			'Users of child group are members of a direct parent group (if not in strict mode)'
450
		);
451
		$this->assertTrue(
452
			$accountingmember->inGroup($staffgroup),
453
			'Users of child group are members of a direct parent group (if not in strict mode)'
454
		);
455
		$this->assertTrue(
456
			$ceomember->inGroup($staffgroup),
457
			'Users of indirect grandchild group are members of a parent group (if not in strict mode)'
458
		);
459
		$this->assertTrue(
460
			$ceomember->inGroup($ceogroup, true),
461
			'Direct group membership is dected (if in strict mode)'
462
		);
463
		$this->assertFalse(
464
			$ceomember->inGroup($staffgroup, true),
465
			'Users of child group are not members of a direct parent group (if in strict mode)'
466
		);
467
		$this->assertFalse(
468
			$staffmember->inGroup($managementgroup),
469
			'Users of parent group are not members of a direct child group'
470
		);
471
		$this->assertFalse(
472
			$staffmember->inGroup($ceogroup),
473
			'Users of parent group are not members of an indirect grandchild group'
474
		);
475
		$this->assertFalse(
476
			$accountingmember->inGroup($managementgroup),
477
			'Users of group are not members of any siblings'
478
		);
479
		$this->assertFalse(
480
			$staffmember->inGroup('does-not-exist'),
481
			'Non-existant group returns false'
482
		);
483
	}
484
485
	/**
486
	 * Tests that the user is able to view their own record, and in turn, they can
487
	 * edit and delete their own record too.
488
	 */
489
	public function testCanManipulateOwnRecord() {
490
		$extensions = $this->removeExtensions(Object::get_extensions('Member'));
491
		$member = $this->objFromFixture('Member', 'test');
492
		$member2 = $this->objFromFixture('Member', 'staffmember');
493
494
		$this->session()->inst_set('loggedInAs', null);
495
496
		/* Not logged in, you can't view, delete or edit the record */
497
		$this->assertFalse($member->canView());
498
		$this->assertFalse($member->canDelete());
499
		$this->assertFalse($member->canEdit());
500
501
		/* Logged in users can edit their own record */
502
		$this->session()->inst_set('loggedInAs', $member->ID);
503
		$this->assertTrue($member->canView());
504
		$this->assertFalse($member->canDelete());
505
		$this->assertTrue($member->canEdit());
506
507
		/* Other uses cannot view, delete or edit others records */
508
		$this->session()->inst_set('loggedInAs', $member2->ID);
509
		$this->assertFalse($member->canView());
510
		$this->assertFalse($member->canDelete());
511
		$this->assertFalse($member->canEdit());
512
513
		$this->addExtensions($extensions);
514
		$this->session()->inst_set('loggedInAs', null);
515
	}
516
517
	public function testAuthorisedMembersCanManipulateOthersRecords() {
518
		$extensions = $this->removeExtensions(Object::get_extensions('Member'));
519
		$member = $this->objFromFixture('Member', 'test');
520
		$member2 = $this->objFromFixture('Member', 'staffmember');
521
522
		/* Group members with SecurityAdmin permissions can manipulate other records */
523
		$this->session()->inst_set('loggedInAs', $member->ID);
524
		$this->assertTrue($member2->canView());
525
		$this->assertTrue($member2->canDelete());
526
		$this->assertTrue($member2->canEdit());
527
528
		$this->addExtensions($extensions);
529
		$this->session()->inst_set('loggedInAs', null);
530
	}
531
532
	public function testExtendedCan() {
533
		$extensions = $this->removeExtensions(Object::get_extensions('Member'));
534
		$member = $this->objFromFixture('Member', 'test');
535
536
		/* Normal behaviour is that you can't view a member unless canView() on an extension returns true */
537
		$this->assertFalse($member->canView());
538
		$this->assertFalse($member->canDelete());
539
		$this->assertFalse($member->canEdit());
540
541
		/* Apply a extension that allows viewing in any case (most likely the case for member profiles) */
542
		Member::add_extension('MemberTest_ViewingAllowedExtension');
543
		$member2 = $this->objFromFixture('Member', 'staffmember');
544
545
		$this->assertTrue($member2->canView());
546
		$this->assertFalse($member2->canDelete());
547
		$this->assertFalse($member2->canEdit());
548
549
		/* Apply a extension that denies viewing of the Member */
550
		Member::remove_extension('MemberTest_ViewingAllowedExtension');
551
		Member::add_extension('MemberTest_ViewingDeniedExtension');
552
		$member3 = $this->objFromFixture('Member', 'managementmember');
553
554
		$this->assertFalse($member3->canView());
555
		$this->assertFalse($member3->canDelete());
556
		$this->assertFalse($member3->canEdit());
557
558
		/* Apply a extension that allows viewing and editing but denies deletion */
559
		Member::remove_extension('MemberTest_ViewingDeniedExtension');
560
		Member::add_extension('MemberTest_EditingAllowedDeletingDeniedExtension');
561
		$member4 = $this->objFromFixture('Member', 'accountingmember');
562
563
		$this->assertTrue($member4->canView());
564
		$this->assertFalse($member4->canDelete());
565
		$this->assertTrue($member4->canEdit());
566
567
		Member::remove_extension('MemberTest_EditingAllowedDeletingDeniedExtension');
568
		$this->addExtensions($extensions);
569
	}
570
571
	/**
572
	 * Tests for {@link Member::getName()} and {@link Member::setName()}
573
	 */
574
	public function testName() {
575
		$member = $this->objFromFixture('Member', 'test');
576
		$member->setName('Test Some User');
577
		$this->assertEquals('Test Some User', $member->getName());
578
		$member->setName('Test');
579
		$this->assertEquals('Test', $member->getName());
580
		$member->FirstName = 'Test';
0 ignored issues
show
Documentation introduced by
The property FirstName does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
581
		$member->Surname = '';
0 ignored issues
show
Documentation introduced by
The property Surname does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
582
		$this->assertEquals('Test', $member->getName());
583
	}
584
585
	public function testMembersWithSecurityAdminAccessCantEditAdminsUnlessTheyreAdminsThemselves() {
586
		$adminMember = $this->objFromFixture('Member', 'admin');
587
		$otherAdminMember = $this->objFromFixture('Member', 'other-admin');
588
		$securityAdminMember = $this->objFromFixture('Member', 'test');
589
		$ceoMember = $this->objFromFixture('Member', 'ceomember');
590
591
		// Careful: Don't read as english language.
592
		// More precisely this should read canBeEditedBy()
593
594
		$this->assertTrue($adminMember->canEdit($adminMember), 'Admins can edit themselves');
0 ignored issues
show
Bug introduced by
It seems like $adminMember defined by $this->objFromFixture('Member', 'admin') on line 586 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
595
		$this->assertTrue($otherAdminMember->canEdit($adminMember), 'Admins can edit other admins');
0 ignored issues
show
Bug introduced by
It seems like $adminMember defined by $this->objFromFixture('Member', 'admin') on line 586 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
596
		$this->assertTrue($securityAdminMember->canEdit($adminMember), 'Admins can edit other members');
0 ignored issues
show
Bug introduced by
It seems like $adminMember defined by $this->objFromFixture('Member', 'admin') on line 586 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
597
598
		$this->assertTrue($securityAdminMember->canEdit($securityAdminMember), 'Security-Admins can edit themselves');
0 ignored issues
show
Bug introduced by
It seems like $securityAdminMember defined by $this->objFromFixture('Member', 'test') on line 588 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
599
		$this->assertFalse($adminMember->canEdit($securityAdminMember), 'Security-Admins can not edit other admins');
0 ignored issues
show
Bug introduced by
It seems like $securityAdminMember defined by $this->objFromFixture('Member', 'test') on line 588 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
600
		$this->assertTrue($ceoMember->canEdit($securityAdminMember), 'Security-Admins can edit other members');
0 ignored issues
show
Bug introduced by
It seems like $securityAdminMember defined by $this->objFromFixture('Member', 'test') on line 588 can also be of type object<DataObject>; however, DataObject::canEdit() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
601
	}
602
603
	public function testOnChangeGroups() {
604
		$staffGroup = $this->objFromFixture('Group', 'staffgroup');
605
		$staffMember = $this->objFromFixture('Member', 'staffmember');
606
		$adminMember = $this->objFromFixture('Member', 'admin');
607
		$newAdminGroup = new Group(array('Title' => 'newadmin'));
608
		$newAdminGroup->write();
609
		Permission::grant($newAdminGroup->ID, 'ADMIN');
610
		$newOtherGroup = new Group(array('Title' => 'othergroup'));
611
		$newOtherGroup->write();
612
613
		$this->assertTrue(
614
			$staffMember->onChangeGroups(array($staffGroup->ID)),
615
			'Adding existing non-admin group relation is allowed for non-admin members'
616
		);
617
		$this->assertTrue(
618
			$staffMember->onChangeGroups(array($newOtherGroup->ID)),
619
			'Adding new non-admin group relation is allowed for non-admin members'
620
		);
621
		$this->assertFalse(
622
			$staffMember->onChangeGroups(array($newAdminGroup->ID)),
623
			'Adding new admin group relation is not allowed for non-admin members'
624
		);
625
626
		$this->session()->inst_set('loggedInAs', $adminMember->ID);
627
		$this->assertTrue(
628
			$staffMember->onChangeGroups(array($newAdminGroup->ID)),
629
			'Adding new admin group relation is allowed for normal users, when granter is logged in as admin'
630
		);
631
		$this->session()->inst_set('loggedInAs', null);
632
633
		$this->assertTrue(
634
			$adminMember->onChangeGroups(array($newAdminGroup->ID)),
635
			'Adding new admin group relation is allowed for admin members'
636
		);
637
	}
638
639
	/**
640
	 * Test Member_GroupSet::add
641
	 */
642
	public function testOnChangeGroupsByAdd() {
643
		$staffMember = $this->objFromFixture('Member', 'staffmember');
644
		$adminMember = $this->objFromFixture('Member', 'admin');
645
646
		// Setup new admin group
647
		$newAdminGroup = new Group(array('Title' => 'newadmin'));
648
		$newAdminGroup->write();
649
		Permission::grant($newAdminGroup->ID, 'ADMIN');
650
651
		// Setup non-admin group
652
		$newOtherGroup = new Group(array('Title' => 'othergroup'));
653
		$newOtherGroup->write();
654
655
		// Test staff can be added to other group
656
		$this->assertFalse($staffMember->inGroup($newOtherGroup));
657
		$staffMember->Groups()->add($newOtherGroup);
658
		$this->assertTrue(
659
			$staffMember->inGroup($newOtherGroup),
660
			'Adding new non-admin group relation is allowed for non-admin members'
661
		);
662
663
		// Test staff member can't be added to admin groups
664
		$this->assertFalse($staffMember->inGroup($newAdminGroup));
665
		$staffMember->Groups()->add($newAdminGroup);
666
		$this->assertFalse(
667
			$staffMember->inGroup($newAdminGroup),
668
			'Adding new admin group relation is not allowed for non-admin members'
669
		);
670
671
		// Test staff member can be added to admin group by admins
672
		$this->logInAs($adminMember);
673
		$staffMember->Groups()->add($newAdminGroup);
674
		$this->assertTrue(
675
			$staffMember->inGroup($newAdminGroup),
676
			'Adding new admin group relation is allowed for normal users, when granter is logged in as admin'
677
		);
678
679
		// Test staff member can be added if they are already admin
680
		$this->session()->inst_set('loggedInAs', null);
681
		$this->assertFalse($adminMember->inGroup($newAdminGroup));
682
		$adminMember->Groups()->add($newAdminGroup);
683
		$this->assertTrue(
684
			$adminMember->inGroup($newAdminGroup),
685
			'Adding new admin group relation is allowed for admin members'
686
		);
687
	}
688
689
	/**
690
	 * Test Member_GroupSet::add
691
	 */
692
	public function testOnChangeGroupsBySetIDList() {
693
		$staffMember = $this->objFromFixture('Member', 'staffmember');
694
695
		// Setup new admin group
696
		$newAdminGroup = new Group(array('Title' => 'newadmin'));
697
		$newAdminGroup->write();
698
		Permission::grant($newAdminGroup->ID, 'ADMIN');
699
700
		// Test staff member can't be added to admin groups
701
		$this->assertFalse($staffMember->inGroup($newAdminGroup));
702
		$staffMember->Groups()->setByIDList(array($newAdminGroup->ID));
703
		$this->assertFalse(
704
			$staffMember->inGroup($newAdminGroup),
705
			'Adding new admin group relation is not allowed for non-admin members'
706
		);
707
	}
708
709
	/**
710
	 * Test that extensions using updateCMSFields() are applied correctly
711
	 */
712
	public function testUpdateCMSFields() {
713
		Member::add_extension('MemberTest_FieldsExtension');
714
715
		$member = singleton('Member');
716
		$fields = $member->getCMSFields();
717
718
		$this->assertNotNull($fields->dataFieldByName('Email'), 'Scaffolded fields are retained');
719
		$this->assertNull($fields->dataFieldByName('Salt'), 'Field modifications run correctly');
720
		$this->assertNotNull($fields->dataFieldByName('TestMemberField'), 'Extension is applied correctly');
721
722
		Member::remove_extension('MemberTest_FieldsExtension');
723
	}
724
725
	/**
726
	 * Test that all members are returned
727
	 */
728
	public function testMap_in_groupsReturnsAll() {
729
		$members = Member::map_in_groups();
730
		$this->assertEquals(13, count($members), 'There are 12 members in the mock plus a fake admin');
731
	}
732
733
	/**
734
	 * Test that only admin members are returned
735
	 */
736
	public function testMap_in_groupsReturnsAdmins() {
737
		$adminID = $this->objFromFixture('Group', 'admingroup')->ID;
738
		$members = Member::map_in_groups($adminID);
739
740
		$admin = $this->objFromFixture('Member', 'admin');
741
		$otherAdmin = $this->objFromFixture('Member', 'other-admin');
742
743
		$this->assertTrue(in_array($admin->getTitle(), $members),
744
			$admin->getTitle().' should be in the returned list.');
745
		$this->assertTrue(in_array($otherAdmin->getTitle(), $members),
746
			$otherAdmin->getTitle().' should be in the returned list.');
747
		$this->assertEquals(2, count($members), 'There should be 2 members from the admin group');
748
	}
749
750
	/**
751
	 * Add the given array of member extensions as class names.
752
	 * This is useful for re-adding extensions after being removed
753
	 * in a test case to produce an unbiased test.
754
	 *
755
	 * @param array $extensions
756
	 * @return array The added extensions
757
	 */
758
	protected function addExtensions($extensions) {
759
		if($extensions) foreach($extensions as $extension) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $extensions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
760
			Member::add_extension($extension);
761
		}
762
		return $extensions;
763
	}
764
765
	/**
766
	 * Remove given extensions from Member. This is useful for
767
	 * removing extensions that could produce a biased
768
	 * test result, as some extensions applied by project
769
	 * code or modules can do this.
770
	 *
771
	 * @param array $extensions
772
	 * @return array The removed extensions
773
	 */
774
	protected function removeExtensions($extensions) {
775
		if($extensions) foreach($extensions as $extension) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $extensions of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
776
			Member::remove_extension($extension);
777
		}
778
		return $extensions;
779
	}
780
781
	public function testGenerateAutologinTokenAndStoreHash() {
782
		$enc = new PasswordEncryptor_Blowfish();
783
784
		$m = new Member();
785
		$m->PasswordEncryption = 'blowfish';
786
		$m->Salt = $enc->salt('123');
787
788
		$token = $m->generateAutologinTokenAndStoreHash();
789
790
		$this->assertEquals($m->encryptWithUserSettings($token), $m->AutoLoginHash, 'Stores the token as ahash.');
791
	}
792
793
	public function testValidateAutoLoginToken() {
794
		$enc = new PasswordEncryptor_Blowfish();
795
796
		$m1 = new Member();
797
		$m1->PasswordEncryption = 'blowfish';
798
		$m1->Salt = $enc->salt('123');
799
		$m1Token = $m1->generateAutologinTokenAndStoreHash();
800
801
		$m2 = new Member();
802
		$m2->PasswordEncryption = 'blowfish';
803
		$m2->Salt = $enc->salt('456');
804
		$m2Token = $m2->generateAutologinTokenAndStoreHash();
805
806
		$this->assertTrue($m1->validateAutoLoginToken($m1Token), 'Passes token validity test against matching member.');
807
		$this->assertFalse($m2->validateAutoLoginToken($m1Token), 'Fails token validity test against other member.');
808
	}
809
810
	public function testCanDelete() {
811
		$admin1 = $this->objFromFixture('Member', 'admin');
812
		$admin2 = $this->objFromFixture('Member', 'other-admin');
813
		$member1 = $this->objFromFixture('Member', 'grouplessmember');
814
		$member2 = $this->objFromFixture('Member', 'noformatmember');
815
816
		$this->assertTrue(
817
			$admin1->canDelete($admin2),
0 ignored issues
show
Bug introduced by
It seems like $admin2 defined by $this->objFromFixture('Member', 'other-admin') on line 812 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
818
			'Admins can delete other admins'
819
		);
820
		$this->assertTrue(
821
			$member1->canDelete($admin2),
0 ignored issues
show
Bug introduced by
It seems like $admin2 defined by $this->objFromFixture('Member', 'other-admin') on line 812 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
822
			'Admins can delete non-admins'
823
		);
824
		$this->assertFalse(
825
			$admin1->canDelete($admin1),
0 ignored issues
show
Bug introduced by
It seems like $admin1 defined by $this->objFromFixture('Member', 'admin') on line 811 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
826
			'Admins can not delete themselves'
827
		);
828
		$this->assertFalse(
829
			$member1->canDelete($member2),
0 ignored issues
show
Bug introduced by
It seems like $member2 defined by $this->objFromFixture('Member', 'noformatmember') on line 814 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
830
			'Non-admins can not delete other non-admins'
831
		);
832
		$this->assertFalse(
833
			$member1->canDelete($member1),
0 ignored issues
show
Bug introduced by
It seems like $member1 defined by $this->objFromFixture('M...er', 'grouplessmember') on line 813 can also be of type object<DataObject>; however, DataObject::canDelete() does only seem to accept object<Member>|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
834
			'Non-admins can not delete themselves'
835
		);
836
	}
837
838
	public function testFailedLoginCount() {
839
		$maxFailedLoginsAllowed = 3;
840
		//set up the config variables to enable login lockouts
841
		Config::inst()->update('Member', 'lock_out_after_incorrect_logins', $maxFailedLoginsAllowed);
842
843
		$member = $this->objFromFixture('Member', 'test');
844
		$failedLoginCount = $member->FailedLoginCount;
0 ignored issues
show
Documentation introduced by
The property FailedLoginCount does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
845
846
		for ($i = 1; $i < $maxFailedLoginsAllowed; ++$i) {
847
			$member->registerFailedLogin();
848
849
			$this->assertEquals(
850
				++$failedLoginCount,
851
				$member->FailedLoginCount,
852
				'Failed to increment $member->FailedLoginCount'
853
			);
854
855
			$this->assertFalse(
856
				$member->isLockedOut(),
857
				"Member has been locked out too early"
858
			);
859
		}
860
	}
861
862
	public function testMemberValidator()
863
	{
864
		// clear custom requirements for this test
865
		Config::inst()->update('Member_Validator', 'customRequired', null);
866
		$memberA = $this->objFromFixture('Member', 'admin');
867
		$memberB = $this->objFromFixture('Member', 'test');
868
869
		// create a blank form
870
		$form = new MemberTest_ValidatorForm();
871
872
		$validator = new Member_Validator();
873
		$validator->setForm($form);
874
875
		// Simulate creation of a new member via form, but use an existing member identifier
876
		$fail = $validator->php(array(
877
			'FirstName' => 'Test',
878
			'Email' => $memberA->Email
879
		));
880
881
		$this->assertFalse(
882
			$fail,
883
			'Member_Validator must fail when trying to create new Member with existing Email.'
884
		);
885
886
		// populate the form with values from another member
887
		$form->loadDataFrom($memberB);
0 ignored issues
show
Bug introduced by
It seems like $memberB defined by $this->objFromFixture('Member', 'test') on line 867 can be null; however, Form::loadDataFrom() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
888
889
		// Assign the validator to an existing member
890
		// (this is basically the same as passing the member ID with the form data)
891
		$validator->setForMember($memberB);
892
893
		// Simulate update of a member via form and use an existing member Email
894
		$fail = $validator->php(array(
895
			'FirstName' => 'Test',
896
			'Email' => $memberA->Email
897
		));
898
899
		// Simulate update to a new Email address
900
		$pass1 = $validator->php(array(
901
			'FirstName' => 'Test',
902
			'Email' => '[email protected]'
903
		));
904
905
		// Pass in the same Email address that the member already has. Ensure that case is valid
906
		$pass2 = $validator->php(array(
907
			'FirstName' => 'Test',
908
			'Surname' => 'User',
909
			'Email' => $memberB->Email
910
		));
911
912
		$this->assertFalse(
913
			$fail,
914
			'Member_Validator must fail when trying to update existing member with existing Email.'
915
		);
916
917
		$this->assertTrue(
918
			$pass1,
919
			'Member_Validator must pass when Email is updated to a value that\'s not in use.'
920
		);
921
922
		$this->assertTrue(
923
			$pass2,
924
			'Member_Validator must pass when Member updates his own Email to the already existing value.'
925
		);
926
	}
927
928
	public function testMemberValidatorWithExtensions()
929
	{
930
		// clear custom requirements for this test
931
		Config::inst()->update('Member_Validator', 'customRequired', null);
932
933
		// create a blank form
934
		$form = new MemberTest_ValidatorForm();
935
936
		// Test extensions
937
		Member_Validator::add_extension('MemberTest_MemberValidator_SurnameMustMatchFirstNameExtension');
938
		$validator = new Member_Validator();
939
		$validator->setForm($form);
940
941
		// This test should fail, since the extension enforces FirstName == Surname
942
		$fail = $validator->php(array(
943
			'FirstName' => 'Test',
944
			'Surname' => 'User',
945
			'Email' => '[email protected]'
946
		));
947
948
		$pass = $validator->php(array(
949
			'FirstName' => 'Test',
950
			'Surname' => 'Test',
951
			'Email' => '[email protected]'
952
		));
953
954
		$this->assertFalse(
955
			$fail,
956
			'Member_Validator must fail because of added extension.'
957
		);
958
959
		$this->assertTrue(
960
			$pass,
961
			'Member_Validator must succeed, since it meets all requirements.'
962
		);
963
964
		// Add another extension that always fails. This ensures that all extensions are considered in the validation
965
		Member_Validator::add_extension('MemberTest_MemberValidator_AlwaysFailsExtension');
966
		$validator = new Member_Validator();
967
		$validator->setForm($form);
968
969
		// Even though the data is valid, This test should still fail, since one extension always returns false
970
		$fail = $validator->php(array(
971
			'FirstName' => 'Test',
972
			'Surname' => 'Test',
973
			'Email' => '[email protected]'
974
		));
975
976
		$this->assertFalse(
977
			$fail,
978
			'Member_Validator must fail because of added extensions.'
979
		);
980
981
		// Remove added extensions
982
		Member_Validator::remove_extension('MemberTest_MemberValidator_AlwaysFailsExtension');
983
		Member_Validator::remove_extension('MemberTest_MemberValidator_SurnameMustMatchFirstNameExtension');
984
	}
985
986
	public function testCustomMemberValidator()
987
	{
988
		// clear custom requirements for this test
989
		Config::inst()->update('Member_Validator', 'customRequired', null);
990
991
		$member = $this->objFromFixture('Member', 'admin');
992
993
		$form = new MemberTest_ValidatorForm();
994
		$form->loadDataFrom($member);
0 ignored issues
show
Bug introduced by
It seems like $member defined by $this->objFromFixture('Member', 'admin') on line 991 can be null; however, Form::loadDataFrom() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
995
996
		$validator = new Member_Validator();
997
		$validator->setForm($form);
998
999
		$pass = $validator->php(array(
1000
			'FirstName' => 'Borris',
1001
			'Email' => '[email protected]'
1002
		));
1003
1004
		$fail = $validator->php(array(
1005
			'Email' => '[email protected]',
1006
			'Surname' => ''
1007
		));
1008
1009
		$this->assertTrue($pass, 'Validator requires a FirstName and Email');
1010
		$this->assertFalse($fail, 'Missing FirstName');
1011
1012
		$ext = new MemberTest_ValidatorExtension();
1013
		$ext->updateValidator($validator);
1014
1015
		$pass = $validator->php(array(
1016
			'FirstName' => 'Borris',
1017
			'Email' => '[email protected]'
1018
		));
1019
1020
		$fail = $validator->php(array(
1021
			'Email' => '[email protected]'
1022
		));
1023
1024
		$this->assertFalse($pass, 'Missing surname');
1025
		$this->assertFalse($fail, 'Missing surname value');
1026
1027
		$fail = $validator->php(array(
1028
			'Email' => '[email protected]',
1029
			'Surname' => 'Silverman'
1030
		));
1031
1032
		$this->assertTrue($fail, 'Passes with email and surname now (no firstname)');
1033
	}
1034
1035
	public function testCurrentUser() {
1036
		$this->assertNull(Member::currentUser());
1037
1038
		$adminMember = $this->objFromFixture('Member', 'admin');
1039
		$this->logInAs($adminMember);
1040
1041
		$userFromSession = Member::currentUser();
1042
		$this->assertEquals($adminMember->ID, $userFromSession->ID);
1043
	}
1044
1045
}
1046
1047
/**
1048
 * @package framework
1049
 * @subpackage tests
1050
 */
1051
class MemberTest_ValidatorForm extends Form implements TestOnly {
1052
1053
	public function __construct() {
1054
		parent::__construct(Controller::curr(), __CLASS__, new FieldList(
1055
			new TextField('Email'),
1056
			new TextField('Surname'),
1057
			new TextField('ID'),
1058
			new TextField('FirstName')
1059
		), new FieldList(
1060
			new FormAction('someAction')
1061
		));
1062
	}
1063
}
1064
1065
/**
1066
 * @package framework
1067
 * @subpackage tests
1068
 */
1069
class MemberTest_ValidatorExtension extends DataExtension implements TestOnly {
1070
1071
	public function updateValidator(&$validator) {
1072
		$validator->addRequiredField('Surname');
1073
		$validator->removeRequiredField('FirstName');
1074
	}
1075
}
1076
1077
/**
1078
 * Extension that adds additional validation criteria
1079
 * @package framework
1080
 * @subpackage tests
1081
 */
1082
class MemberTest_MemberValidator_SurnameMustMatchFirstNameExtension extends DataExtension implements TestOnly
1083
{
1084
	public function updatePHP($data, $form) {
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1085
		return $data['FirstName'] == $data['Surname'];
1086
	}
1087
}
1088
1089
/**
1090
 * Extension that adds additional validation criteria
1091
 * @package framework
1092
 * @subpackage tests
1093
 */
1094
class MemberTest_MemberValidator_AlwaysFailsExtension extends DataExtension implements TestOnly
1095
{
1096
	public function updatePHP($data, $form) {
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1097
		return false;
1098
	}
1099
}
1100
1101
/**
1102
 * @package framework
1103
 * @subpackage tests
1104
 */
1105
class MemberTest_ViewingAllowedExtension extends DataExtension implements TestOnly {
1106
1107
	public function canView($member = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1108
		return true;
1109
	}
1110
}
1111
1112
/**
1113
 * @package framework
1114
 * @subpackage tests
1115
 */
1116
class MemberTest_ViewingDeniedExtension extends DataExtension implements TestOnly {
1117
1118
	public function canView($member = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1119
		return false;
1120
	}
1121
}
1122
1123
/**
1124
 * @package framework
1125
 * @subpackage tests
1126
 */
1127
class MemberTest_FieldsExtension extends DataExtension implements TestOnly {
1128
1129
	public function updateCMSFields(FieldList $fields) {
1130
		$fields->addFieldToTab('Root.Main', new TextField('TestMemberField', 'Test'));
1131
	}
1132
1133
}
1134
1135
/**
1136
 * @package framework
1137
 * @subpackage tests
1138
 */
1139
class MemberTest_EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly {
1140
1141
	public function canView($member = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $member is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1142
		return true;
1143
	}
1144
1145
	public function canEdit($member = null) {
1146
		return true;
1147
	}
1148
1149
	public function canDelete($member = null) {
1150
		return false;
1151
	}
1152
1153
}
1154
1155
/**
1156
 * @package framework
1157
 * @subpackage tests
1158
 */
1159
class MemberTest_PasswordValidator extends PasswordValidator {
1160
	public function __construct() {
1161
		parent::__construct();
1162
		$this->minLength(7);
1163
		$this->checkHistoricalPasswords(6);
1164
		$this->characterStrength(3, array('lowercase','uppercase','digits','punctuation'));
1165
	}
1166
1167
}
1168