Esempio n. 1
0
 public function testPassword()
 {
     $hash = new BasicHashService();
     $password = '******';
     $doc = new PasswordTraitDoc();
     $doc->setPassword($password);
     $this->documentManager->persist($doc);
     $this->documentManager->flush();
     $this->assertNotEquals($password, $doc->getPassword());
     $this->assertEquals($doc->getPassword(), $hash->hashValue($password, $doc->getSalt()));
     $this->assertNotEquals($doc->getPassword(), $hash->hashValue('not password', $doc->getSalt()));
     $newPassword = '******';
     $doc->setPassword($newPassword);
     $this->documentManager->flush();
     $this->assertNotEquals($newPassword, $doc->getPassword());
     $this->assertEquals($doc->getPassword(), $hash->hashValue($newPassword, $doc->getSalt()));
     $this->assertNotEquals($doc->getPassword(), $hash->hashValue($password, $doc->getSalt()));
 }
 public function testPasswordUpdateAllow()
 {
     $this->calls = array();
     $documentManager = $this->documentManager;
     $eventManager = $documentManager->getEventManager();
     $eventManager->addEventListener(Events::UPDATE_DENIED, $this);
     $testDoc = new PasswordTraitDoc();
     $testDoc->setPassword('password1');
     $documentManager->persist($testDoc);
     $documentManager->flush();
     $id = $testDoc->getId();
     $documentManager->clear();
     $repository = $documentManager->getRepository(get_class($testDoc));
     $testDoc = $repository->find($id);
     $testDoc->setPassword('password2');
     $documentManager->flush();
     $this->assertFalse(isset($this->calls[Events::UPDATE_DENIED]));
 }