diff --git a/src/PServerCMS/Service/Donate.php b/src/PServerCMS/Service/Donate.php index 773d5c0..78457f9 100644 --- a/src/PServerCMS/Service/Donate.php +++ b/src/PServerCMS/Service/Donate.php @@ -25,7 +25,10 @@ public function getStatisticData( $lastDays = 10 ) $range = DateTimer::getDateRange4Period($dateTime, new \DateTime()); foreach($range as $date){ foreach($typList as $type){ - $result[$date->format('Y-m-d')][$type] = ['amount' => 0, 'coins' => 0]; + $result[$date->format('Y-m-d')][$type] = [ + 'amount' => 0, + 'coins' => 0 + ]; } } diff --git a/src/PServerCMS/Service/User.php b/src/PServerCMS/Service/User.php index 5da646f..002bf50 100644 --- a/src/PServerCMS/Service/User.php +++ b/src/PServerCMS/Service/User.php @@ -5,6 +5,7 @@ use PServerCMS\Entity\UserCodes; use PServerCMS\Entity\UserInterface; +use SmallUser\Entity\UserInterface as SmallUserInterface; use PServerCMS\Entity\User as Entity; use PServerCMS\Entity\Repository\AvailableCountries as RepositoryAvailableCountries; use PServerCMS\Entity\Repository\CountryList; @@ -324,10 +325,10 @@ protected function setAvailableCountries4User( UserInterface $user, $ip) } /** - * @param UserInterface $user + * @param SmallUserInterface $user * @return bool */ - protected function isValidLogin( UserInterface $user ) + protected function isValidLogin( SmallUserInterface $user ) { $result = true; if (!$this->isCountryAllowed( $user )) { @@ -400,9 +401,9 @@ protected function getUser4Id( $userId ) } /** - * @param UserInterface $user + * @param SmallUserInterface $user */ - protected function doLogin( UserInterface $user ) + protected function doLogin( SmallUserInterface $user ) { parent::doLogin( $user ); $entityManager = $this->getEntityManager(); @@ -419,10 +420,10 @@ protected function doLogin( UserInterface $user ) } /** - * @param UserInterface $user + * @param SmallUserInterface $user * @return bool */ - protected function handleInvalidLogin( UserInterface $user ) + protected function handleInvalidLogin( SmallUserInterface $user ) { $maxTries = $this->getConfigService()->get( 'pserver.login.exploit.try' ); diff --git a/tests/PServerCMSTest/Entity/UserTest.php b/tests/PServerCMSTest/Entity/UserTest.php index b71c45d..e8c8dd2 100644 --- a/tests/PServerCMSTest/Entity/UserTest.php +++ b/tests/PServerCMSTest/Entity/UserTest.php @@ -4,10 +4,12 @@ namespace PServerCMSTest\Entity; use PServerCMS\Entity\User; +use PServerCMS\Entity\UserExtension; use PServerCMS\Entity\UserRole; +use PServerCMSTest\Util\TestBase; use Zend\Crypt\Password\Bcrypt; -class UserTest extends \PHPUnit_Framework_TestCase +class UserTest extends TestBase { public function testConstruct() { @@ -127,9 +129,32 @@ public function testGetRoles() $this->assertInstanceOf('Zend\Permissions\Acl\Role\RoleInterface', $result[0]); } - public function testHashPassword() + public function testUserExtension() { - $this->markTestIncomplete('missing mock servicemanager'); + $entity = new User(); + $entityExtension = new UserExtension(); + + $entity->addUserExtension($entityExtension); + $entity->addUserExtension($entityExtension); + + $this->assertEquals(2, count($entity->getUserExtension())); + + $entity->removeUserExtension($entityExtension); + + $this->assertEquals(1, count($entity->getUserExtension())); + } + + public function testHashPasswordTrue() + { + $userService = $this->getMockBuilder('PServerCMS\Service\User') + ->disableOriginalConstructor() + ->getMock(); + + $userService->expects($this->any()) + ->method('isSamePasswordOption') + ->will($this->returnValue(true)); + + $this->serviceManager->setService('small_user_service', $userService); $entity = new User(); $password = 'foobar'; @@ -141,5 +166,42 @@ public function testHashPassword() $this->assertTrue($result); } + public function testHashPasswordFalse() + { + // We need a mocking of GameBackend =) + $gameService = $this->getMockBuilder('GameBackend\DataService\DataServiceInterface') + ->disableOriginalConstructor() + ->getMock(); + + $gameService->expects($this->any()) + ->method('isPasswordSame') + ->will($this->returnValue(false)); + + // Mock UserService + $userService = $this->getMockBuilder('PServerCMS\Service\User') + ->disableOriginalConstructor() + ->getMock(); + + $userService->expects($this->any()) + ->method('isSamePasswordOption') + ->will($this->returnValue(false)); + + $userService->expects($this->any()) + ->method('getGameBackendService') + ->will($this->returnValue($gameService)); + + + $this->serviceManager->setService('small_user_service', $userService); + + $entity = new User(); + $password = 'foobar'; + $bCrypt = new Bcrypt(); + + $entity->setPassword($bCrypt->create( $password )); + $result = User::hashPassword($entity, $password); + + $this->assertFalse($result); + } + } diff --git a/tests/PServerCMSTest/Util/TestBase.php b/tests/PServerCMSTest/Util/TestBase.php index 36a99cf..f0de9fb 100644 --- a/tests/PServerCMSTest/Util/TestBase.php +++ b/tests/PServerCMSTest/Util/TestBase.php @@ -4,6 +4,7 @@ namespace PServerCMSTest\Util; use PHPUnit_Framework_TestCase as TestCase; +use PServerCMS\Service\ServiceManager; class TestBase extends TestCase { @@ -16,6 +17,7 @@ public function setUp() { parent::setUp(); $this->serviceManager = ServiceManagerFactory::getServiceManager(); + ServiceManager::setInstance($this->serviceManager); } /**