create test for updatePassword event

This commit is contained in:
Manuel Raynaud
2014-01-31 12:51:15 +01:00
parent b3cc5e3f80
commit 64f89d07a9
2 changed files with 43 additions and 0 deletions

View File

@@ -54,6 +54,8 @@ class AdministratorUpdatePasswordEvent extends ActionEvent
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
@@ -70,6 +72,8 @@ class AdministratorUpdatePasswordEvent extends ActionEvent
public function setAdmin(Admin $admin)
{
$this->admin = $admin;
return $this;
}
/**

View File

@@ -25,6 +25,7 @@ namespace Thelia\Tests\Action;
use Thelia\Action\Administrator;
use Thelia\Core\Event\Administrator\AdministratorEvent;
use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent;
use Thelia\Model\AdminQuery;
use Thelia\Model\LangQuery;
@@ -100,5 +101,43 @@ class AdministratorTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
}
public function testDelete()
{
$admin = AdminQuery::create()->findOne();
$adminEvent = new AdministratorEvent();
$adminEvent
->setId($admin->getId())
->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"))
;
$actionAdmin = new Administrator();
$actionAdmin->delete($adminEvent);
$deletedAdmin = $adminEvent->getAdministrator();
$this->assertInstanceOf("Thelia\Model\Admin", $deletedAdmin);
$this->assertTrue($deletedAdmin->isDeleted());
}
public function testUpdatePassword()
{
$admin = AdminQuery::create()->findOne();
$adminEvent = new AdministratorUpdatePasswordEvent($admin);
$adminEvent
->setPassword('toto')
->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$actionAdmin = new Administrator();
$actionAdmin->updatePassword($adminEvent);
$updatedAdmin = $adminEvent->getAdmin();
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
$this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
}
}