Skip to content

Commit

Permalink
Merge pull request #536 from adamlundrigan/hotfix/523
Browse files Browse the repository at this point in the history
Remove default user state value check during registration process
  • Loading branch information
Danielss89 committed Oct 29, 2014
2 parents 18a0476 + f57949e commit 1827610
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/ZfcUser/Service/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ public function register(array $data)

// If user state is enabled, set the default state value
if ($this->getOptions()->getEnableUserState()) {
if ($this->getOptions()->getDefaultUserState()) {
$user->setState($this->getOptions()->getDefaultUserState());
}
$user->setState($this->getOptions()->getDefaultUserState());
}
$this->getEventManager()->trigger(__FUNCTION__, $this, array('user' => $user, 'form' => $form));
$this->getUserMapper()->insert($user);
Expand Down
144 changes: 143 additions & 1 deletion tests/ZfcUserTest/Service/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled()
$this->options->expects($this->once())
->method('getEnableUserState')
->will($this->returnValue(true));
$this->options->expects($this->exactly(2))
$this->options->expects($this->once())
->method('getDefaultUserState')
->will($this->returnValue(1));

Expand Down Expand Up @@ -153,6 +153,148 @@ public function testRegisterWithUsernameAndDisplayNameUserStateDisabled()
$this->assertSame($user, $result);
}

/**
* @covers ZfcUser\Service\User::register
*/
public function testRegisterWithDefaultUserStateOfZero()
{
$expectArray = array('username' => 'ZfcUser', 'display_name' => 'Zfc User');

$user = $this->getMock('ZfcUser\Entity\User');
$user->expects($this->once())
->method('setPassword');
$user->expects($this->once())
->method('getPassword');
$user->expects($this->once())
->method('setUsername')
->with('ZfcUser');
$user->expects($this->once())
->method('setDisplayName')
->with('Zfc User');
$user->expects($this->once())
->method('setState')
->with(0);

$this->options->expects($this->once())
->method('getUserEntityClass')
->will($this->returnValue('ZfcUser\Entity\User'));
$this->options->expects($this->once())
->method('getPasswordCost')
->will($this->returnValue(4));
$this->options->expects($this->once())
->method('getEnableUsername')
->will($this->returnValue(true));
$this->options->expects($this->once())
->method('getEnableDisplayName')
->will($this->returnValue(true));
$this->options->expects($this->once())
->method('getEnableUserState')
->will($this->returnValue(true));
$this->options->expects($this->once())
->method('getDefaultUserState')
->will($this->returnValue(0));

$registerForm = $this->getMockBuilder('ZfcUser\Form\Register')->disableOriginalConstructor()->getMock();
$registerForm->expects($this->once())
->method('setHydrator');
$registerForm->expects($this->once())
->method('bind');
$registerForm->expects($this->once())
->method('setData')
->with($expectArray);
$registerForm->expects($this->once())
->method('getData')
->will($this->returnValue($user));
$registerForm->expects($this->once())
->method('isValid')
->will($this->returnValue(true));

$this->eventManager->expects($this->exactly(2))
->method('trigger');

$this->mapper->expects($this->once())
->method('insert')
->with($user)
->will($this->returnValue($user));

$this->service->setRegisterForm($registerForm);

$result = $this->service->register($expectArray);

$this->assertSame($user, $result);
$this->assertEquals(0, $user->getState());
}

/**
* @covers ZfcUser\Service\User::register
*/
public function testRegisterWithUserStateDisabled()
{
$expectArray = array('username' => 'ZfcUser', 'display_name' => 'Zfc User');

$user = $this->getMock('ZfcUser\Entity\User');
$user->expects($this->once())
->method('setPassword');
$user->expects($this->once())
->method('getPassword');
$user->expects($this->once())
->method('setUsername')
->with('ZfcUser');
$user->expects($this->once())
->method('setDisplayName')
->with('Zfc User');
$user->expects($this->never())
->method('setState');

$this->options->expects($this->once())
->method('getUserEntityClass')
->will($this->returnValue('ZfcUser\Entity\User'));
$this->options->expects($this->once())
->method('getPasswordCost')
->will($this->returnValue(4));
$this->options->expects($this->once())
->method('getEnableUsername')
->will($this->returnValue(true));
$this->options->expects($this->once())
->method('getEnableDisplayName')
->will($this->returnValue(true));
$this->options->expects($this->once())
->method('getEnableUserState')
->will($this->returnValue(false));
$this->options->expects($this->never())
->method('getDefaultUserState');

$registerForm = $this->getMockBuilder('ZfcUser\Form\Register')->disableOriginalConstructor()->getMock();
$registerForm->expects($this->once())
->method('setHydrator');
$registerForm->expects($this->once())
->method('bind');
$registerForm->expects($this->once())
->method('setData')
->with($expectArray);
$registerForm->expects($this->once())
->method('getData')
->will($this->returnValue($user));
$registerForm->expects($this->once())
->method('isValid')
->will($this->returnValue(true));

$this->eventManager->expects($this->exactly(2))
->method('trigger');

$this->mapper->expects($this->once())
->method('insert')
->with($user)
->will($this->returnValue($user));

$this->service->setRegisterForm($registerForm);

$result = $this->service->register($expectArray);

$this->assertSame($user, $result);
$this->assertEquals(0, $user->getState());
}

/**
* @covers ZfcUser\Service\User::changePassword
*/
Expand Down

0 comments on commit 1827610

Please sign in to comment.