diff --git a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php index 8cfe1ee02..5c310d7cb 100644 --- a/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php +++ b/core/lib/Thelia/Core/Event/Administrator/AdministratorUpdatePasswordEvent.php @@ -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; } /** diff --git a/core/lib/Thelia/Tests/Action/AdministratorTest.php b/core/lib/Thelia/Tests/Action/AdministratorTest.php index 99160c073..bfaee0d6b 100644 --- a/core/lib/Thelia/Tests/Action/AdministratorTest.php +++ b/core/lib/Thelia/Tests/Action/AdministratorTest.php @@ -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())); + } + } \ No newline at end of file