Skip to content

Commit

Permalink
Force the account ID value during update so it can't be changed
Browse files Browse the repository at this point in the history
(and so it's also available in the field validators)
Fixes #15
  • Loading branch information
adamlundrigan committed Aug 13, 2014
1 parent f234fff commit 98c2c13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/LdcUserProfile/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function indexAction()

$fm = $this->flashMessenger()->setNamespace('ldc-user-profile');

// Ensure that the user can't change the account ID during update
$prg['zfcuser']['id'] = $this->zfcUserAuthentication()->getIdentity()->getId();

$form->setData($prg);
if ( ! $form->isValid() ) {
$fm->addErrorMessage('One or more of the values you provided is invalid.');
Expand Down
10 changes: 7 additions & 3 deletions tests/LdcUserProfileTest/Controller/ProfileControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ProfileControllerTest extends \PHPUnit_Framework_TestCase
public function setUp()
{
$this->mockUserEntity = new \ZfcUser\Entity\User();
$this->mockUserEntity->setId(42);

$this->mockUserService = \Mockery::mock('ZfcUser\Service\User');

Expand Down Expand Up @@ -105,7 +106,8 @@ public function testControllerDispatchedWithValidFormDataWillCompleteAndRedirect

$req = $this->controller->getRequest();
$req->setMethod(Request::METHOD_POST);
$req->getPost()->set('foo', 'bar');
$req->getPost()->set('foo', ['bar' => 'baz']);
$req->getPost()->set('zfcuser', ['id' => 42]);

$postData = $req->getPost()->toArray();
$mockResult = new \stdClass();
Expand Down Expand Up @@ -133,7 +135,8 @@ public function testControllerDispatchedWithInvalidFormDataWillRenderForm()

$req = $this->controller->getRequest();
$req->setMethod(Request::METHOD_POST);
$req->getPost()->set('foo', 'bar');
$req->getPost()->set('foo', ['bar' => 'baz']);
$req->getPost()->set('zfcuser', ['id' => 42]);

$postData = $req->getPost()->toArray();
$mockResult = new \stdClass();
Expand All @@ -159,7 +162,8 @@ public function testControllerWillRenderFormWhenSaveCallFails()

$req = $this->controller->getRequest();
$req->setMethod(Request::METHOD_POST);
$req->getPost()->set('foo', 'bar');
$req->getPost()->set('foo', ['bar' => 'baz']);
$req->getPost()->set('zfcuser', ['id' => 42]);

$postData = $req->getPost()->toArray();
$mockResult = new \stdClass();
Expand Down

0 comments on commit 98c2c13

Please sign in to comment.