2012-09-07 01:17:39 +02:00
|
|
|
<?php
|
2013-10-16 00:29:43 +02:00
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
use SilverStripe\ORM\DataExtension;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Dev\FunctionalTest;
|
|
|
|
use SilverStripe\Security\Member;
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
|
2013-10-16 00:29:43 +02:00
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2012-09-07 01:17:39 +02:00
|
|
|
class CMSProfileControllerTest extends FunctionalTest {
|
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
protected static $fixture_file = 'CMSProfileControllerTest.yml';
|
2012-09-07 01:17:39 +02:00
|
|
|
|
|
|
|
public $autoFollowRedirection = false;
|
|
|
|
|
|
|
|
public function testMemberCantEditAnother() {
|
2016-06-23 01:37:22 +02:00
|
|
|
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user1');
|
|
|
|
$anotherMember = $this->objFromFixture('SilverStripe\\Security\\Member', 'user2');
|
2012-09-07 01:17:39 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $member->ID);
|
|
|
|
|
2012-10-30 17:28:27 +01:00
|
|
|
$response = $this->post('admin/myprofile/EditForm', array(
|
|
|
|
'action_save' => 1,
|
2012-09-07 01:17:39 +02:00
|
|
|
'ID' => $anotherMember->ID,
|
|
|
|
'FirstName' => 'JoeEdited',
|
|
|
|
'Surname' => 'BloggsEdited',
|
|
|
|
'Email' => $member->Email,
|
|
|
|
'Locale' => $member->Locale,
|
|
|
|
'Password[_Password]' => 'password',
|
|
|
|
'Password[_ConfirmPassword]' => 'password',
|
|
|
|
));
|
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
$anotherMember = $this->objFromFixture('SilverStripe\\Security\\Member', 'user2');
|
2012-09-07 01:17:39 +02:00
|
|
|
|
|
|
|
$this->assertNotEquals($anotherMember->FirstName, 'JoeEdited', 'FirstName field stays the same');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMemberEditsOwnProfile() {
|
2016-06-23 01:37:22 +02:00
|
|
|
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user3');
|
2012-09-07 01:17:39 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $member->ID);
|
|
|
|
|
2012-10-30 17:28:27 +01:00
|
|
|
$response = $this->post('admin/myprofile/EditForm', array(
|
|
|
|
'action_save' => 1,
|
2012-09-07 01:17:39 +02:00
|
|
|
'ID' => $member->ID,
|
|
|
|
'FirstName' => 'JoeEdited',
|
|
|
|
'Surname' => 'BloggsEdited',
|
|
|
|
'Email' => $member->Email,
|
|
|
|
'Locale' => $member->Locale,
|
|
|
|
'Password[_Password]' => 'password',
|
|
|
|
'Password[_ConfirmPassword]' => 'password',
|
|
|
|
));
|
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user3');
|
2012-09-07 01:17:39 +02:00
|
|
|
|
2015-08-26 16:46:52 +02:00
|
|
|
$this->assertEquals('JoeEdited', $member->FirstName, 'FirstName field was changed');
|
2012-09-07 01:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testExtendedPermissionsStopEditingOwnProfile() {
|
2016-08-19 00:51:35 +02:00
|
|
|
$existingExtensions = Member::config()->get('extensions');
|
|
|
|
Member::config()->update('extensions', array('CMSProfileControllerTestExtension'));
|
2012-09-07 01:17:39 +02:00
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user1');
|
2012-09-07 01:17:39 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', $member->ID);
|
|
|
|
|
2012-10-30 17:28:27 +01:00
|
|
|
$response = $this->post('admin/myprofile/EditForm', array(
|
|
|
|
'action_save' => 1,
|
2012-09-07 01:17:39 +02:00
|
|
|
'ID' => $member->ID,
|
|
|
|
'FirstName' => 'JoeEdited',
|
|
|
|
'Surname' => 'BloggsEdited',
|
|
|
|
'Email' => $member->Email,
|
|
|
|
'Locale' => $member->Locale,
|
|
|
|
'Password[_Password]' => 'password',
|
|
|
|
'Password[_ConfirmPassword]' => 'password',
|
|
|
|
));
|
|
|
|
|
2016-06-23 01:37:22 +02:00
|
|
|
$member = $this->objFromFixture('SilverStripe\\Security\\Member', 'user1');
|
2012-09-07 01:17:39 +02:00
|
|
|
|
2012-10-28 22:22:53 +01:00
|
|
|
$this->assertNotEquals($member->FirstName, 'JoeEdited',
|
|
|
|
'FirstName field was NOT changed because we modified canEdit');
|
2012-09-10 04:09:40 +02:00
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
Member::config()
|
|
|
|
->remove('extensions')
|
|
|
|
->update('extensions', $existingExtensions);
|
2012-09-07 01:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-10-16 00:29:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package framework
|
|
|
|
* @subpackage tests
|
|
|
|
*/
|
2012-09-07 01:17:39 +02:00
|
|
|
class CMSProfileControllerTestExtension extends DataExtension {
|
|
|
|
|
|
|
|
public function canEdit($member = null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|