mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
79 lines
2.4 KiB
PHP
79 lines
2.4 KiB
PHP
|
<?php
|
||
|
class CMSProfileControllerTest extends FunctionalTest {
|
||
|
|
||
|
public static $fixture_file = 'CMSProfileControllerTest.yml';
|
||
|
|
||
|
public $autoFollowRedirection = false;
|
||
|
|
||
|
public function testMemberCantEditAnother() {
|
||
|
$member = $this->objFromFixture('Member', 'user1');
|
||
|
$anotherMember = $this->objFromFixture('Member', 'user2');
|
||
|
$this->session()->inst_set('loggedInAs', $member->ID);
|
||
|
|
||
|
$response = $this->post('admin/myprofile/Member_ProfileForm', array(
|
||
|
'action_dosave' => 1,
|
||
|
'ID' => $anotherMember->ID,
|
||
|
'FirstName' => 'JoeEdited',
|
||
|
'Surname' => 'BloggsEdited',
|
||
|
'Email' => $member->Email,
|
||
|
'Locale' => $member->Locale,
|
||
|
'Password[_Password]' => 'password',
|
||
|
'Password[_ConfirmPassword]' => 'password',
|
||
|
));
|
||
|
|
||
|
$anotherMember = $this->objFromFixture('Member', 'user2');
|
||
|
|
||
|
$this->assertNotEquals($anotherMember->FirstName, 'JoeEdited', 'FirstName field stays the same');
|
||
|
}
|
||
|
|
||
|
public function testMemberEditsOwnProfile() {
|
||
|
$member = $this->objFromFixture('Member', 'user1');
|
||
|
$this->session()->inst_set('loggedInAs', $member->ID);
|
||
|
|
||
|
$response = $this->post('admin/myprofile/Member_ProfileForm', array(
|
||
|
'action_dosave' => 1,
|
||
|
'ID' => $member->ID,
|
||
|
'FirstName' => 'JoeEdited',
|
||
|
'Surname' => 'BloggsEdited',
|
||
|
'Email' => $member->Email,
|
||
|
'Locale' => $member->Locale,
|
||
|
'Password[_Password]' => 'password',
|
||
|
'Password[_ConfirmPassword]' => 'password',
|
||
|
));
|
||
|
|
||
|
$member = $this->objFromFixture('Member', 'user1');
|
||
|
|
||
|
$this->assertEquals($member->FirstName, 'JoeEdited', 'FirstName field was changed');
|
||
|
}
|
||
|
|
||
|
public function testExtendedPermissionsStopEditingOwnProfile() {
|
||
|
Config::inst()->update('Member', 'extensions', array('CMSProfileControllerTestExtension'));
|
||
|
|
||
|
$member = $this->objFromFixture('Member', 'user1');
|
||
|
$this->session()->inst_set('loggedInAs', $member->ID);
|
||
|
|
||
|
$response = $this->post('admin/myprofile/Member_ProfileForm', array(
|
||
|
'action_dosave' => 1,
|
||
|
'ID' => $member->ID,
|
||
|
'FirstName' => 'JoeEdited',
|
||
|
'Surname' => 'BloggsEdited',
|
||
|
'Email' => $member->Email,
|
||
|
'Locale' => $member->Locale,
|
||
|
'Password[_Password]' => 'password',
|
||
|
'Password[_ConfirmPassword]' => 'password',
|
||
|
));
|
||
|
|
||
|
$member = $this->objFromFixture('Member', 'user1');
|
||
|
|
||
|
$this->assertNotEquals($member->FirstName, 'JoeEdited', 'FirstName field was NOT changed because we modified canEdit');
|
||
|
}
|
||
|
|
||
|
}
|
||
|
class CMSProfileControllerTestExtension extends DataExtension {
|
||
|
|
||
|
public function canEdit($member = null) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
}
|