123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <?php
- use Luticate\Auth\Business\LuUsersBusiness;
- use Luticate\Auth\Controller\LuUsersController;
- use Luticate\Auth\Dbo\Users\LuUsersAddDbo;
- use Luticate\Auth\Dbo\Users\LuUsersLoginDbo;
- use Luticate\Utils\Business\LuBusinessException;
- use Luticate\Utils\Controller\LuticateApplication;
- use Luticate\Utils\DataAccess\LuDataAccess;
-
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 9/18/16
- * Time: 1:02 AM
- */
-
- class Db extends LuDataAccess
- {
- protected static $_connection = "luticatedb";
- }
-
- class LuUsersTest extends \PHPUnit_Framework_TestCase
- {
- protected function getCtrl()
- {
- return new LuUsersController();
- }
-
- public static function setUpBeforeClass()
- {
- Db::getPdo()->query("DELETE FROM lu_users WHERE username LIKE '_test_%'");
- }
-
- public static function tearDownAfterClass()
- {
- static::setUpBeforeClass();
- }
-
- public function testUserAdd1()
- {
- $ctrl = static::getCtrl();
-
- $newUser = new LuUsersAddDbo();
- $newUser->setUsername("_test_user1");
- $newUser->setPassword("test42");
- $newUser->setFirstname("Test");
- $newUser->setLastname("user1");
- $newUser->setEmail("test.user1@example.com");
- $newUser->setExternalAuth(null);
- $newUser->setProfileId(null);
-
- $user = $ctrl->add($newUser);
-
- $this->assertNotNull($user);
- $this->assertNotNull($user->getId());
- $this->assertSame("_test_user1", $user->getUsername());
- $this->assertSame("Test", $user->getFirstname());
- $this->assertSame("user1", $user->getLastname());
- $this->assertSame("test.user1@example.com", $user->getEmail());
- $this->assertNull($user->getExternalAuth());
- $this->assertNull($user->getProfileId());
- }
-
- public function testUserAdd2()
- {
- $ctrl = static::getCtrl();
-
- $newUser = new LuUsersAddDbo();
- $newUser->setUsername("_test_user1");
- $newUser->setPassword("test42");
- $newUser->setFirstname("Test");
- $newUser->setLastname("user1");
- $newUser->setEmail("test.user1@example.com");
- $newUser->setExternalAuth(null);
- $newUser->setProfileId(null);
-
- $this->expectException(LuBusinessException::class);
- $ctrl->add($newUser);
- }
-
- public function testUserAdd3()
- {
- $ctrl = static::getCtrl();
-
- $newUser = new LuUsersAddDbo();
- $newUser->setUsername("_test_user2");
- $newUser->setPassword("test42");
- $newUser->setFirstname("Test");
- $newUser->setLastname("user1");
- $newUser->setEmail("test.user1@example.com");
- $newUser->setExternalAuth(null);
- $newUser->setProfileId(null);
-
- $this->expectException(LuBusinessException::class);
- $ctrl->add($newUser);
- }
-
- public function testUserAdd4()
- {
- $ctrl = static::getCtrl();
-
- $newUser = new LuUsersAddDbo();
- $newUser->setUsername("_test_user2");
- $newUser->setPassword("test24");
- $newUser->setFirstname("Test");
- $newUser->setLastname("user2");
- $newUser->setEmail("test.user2@example.com");
- $newUser->setExternalAuth(null);
- $newUser->setProfileId(null);
-
- $user = $ctrl->add($newUser);
-
- $this->assertNotNull($user);
- $this->assertNotNull($user->getId());
- $this->assertSame("_test_user2", $user->getUsername());
- $this->assertSame("Test", $user->getFirstname());
- $this->assertSame("user2", $user->getLastname());
- $this->assertSame("test.user2@example.com", $user->getEmail());
- $this->assertNull($user->getExternalAuth());
- $this->assertNull($user->getProfileId());
- }
-
- public function testUserLogin1()
- {
- $ctrl = static::getCtrl();
-
- $loginDbo = new LuUsersLoginDbo();
- $loginDbo->setUsername("_test_user1");
- $loginDbo->setPassword("test42");
- $loginResult = $ctrl->login($loginDbo);
-
- $this->assertNotNull($loginResult);
- $this->assertSame("test.user1@example.com", $loginResult->getEmail());
-
- $loggedUser = LuUsersBusiness::getUserFromToken($loginResult->getToken());
-
- $this->assertSame("test.user1@example.com", $loggedUser->getEmail());
- }
-
- public function testUserLogin2()
- {
- $ctrl = static::getCtrl();
-
- $loginDbo = new LuUsersLoginDbo();
- $loginDbo->setUsername("_test_user2");
- $loginDbo->setPassword("test24");
- $loginResult = $ctrl->login($loginDbo);
-
- $this->assertNotNull($loginResult);
- $this->assertSame("test.user2@example.com", $loginResult->getEmail());
-
- $loggedUser = LuUsersBusiness::getUserFromToken($loginResult->getToken());
-
- $this->assertSame("test.user2@example.com", $loggedUser->getEmail());
- }
- }
|