Beispiel #1
0
 public function testIt()
 {
     $PROCEDURE_NAME = 'User/Authenticate';
     // Initialize the database.
     CliWriter::echoInfo("Loading " . __FILE__);
     // Get the procedure.
     $dataInterface = DatabaseInterface::getInstance();
     /** @var \dbeurive\BackendTest\EntryPoints\Brands\MySql\Procedures\User\Authenticate $procedure */
     $procedure = $dataInterface->getProcedure($PROCEDURE_NAME);
     /** @var ProcedureResult $result */
     // -----------------------------------------------------------------------------------------------------------------
     // Test: Login exists, and password is valid.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT login as 'user.login', password as 'user.password' FROM user LIMIT 1", []);
     $result = $procedure->execute(['user.login' => $user[0]['user.login'], 'user.password' => $user[0]['user.password']]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsNotEmpty($result);
     $this->assertResultValueSetIsNotEmpty($result);
     $this->assertResultValuesCount(1, $result);
     $this->assertTrue($result->isSuccess());
     $this->assertResultDataSetCount(1, $result);
     // -----------------------------------------------------------------------------------------------------------------
     // Test: Login exists, and password is not valid.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT login as 'user.login', password as 'user.password' FROM user LIMIT 1", []);
     $result = $procedure->execute(['user.login' => $user[0]['user.login'], 'user.password' => $user[0]['user.password'] . '__']);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertFalse($result->isError());
     $this->assertResultDataSetCount(0, $result);
 }
Beispiel #2
0
 public function testIt()
 {
     $PROCEDURE_NAME = 'User/Delete';
     // Initialize the database.
     CliWriter::echoInfo("Loading " . __FILE__);
     /* var \dbeurive\BackendTest\EntryPoints\Brands\MySql\Procedures\User\Delete $procedure */
     $dataInterface = DatabaseInterface::getInstance();
     $procedure = $dataInterface->getProcedure($PROCEDURE_NAME);
     /** @var ProcedureResult $result */
     // -----------------------------------------------------------------------------------------------------------------
     // Test: user does not exist.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $user[0]['max'] + 1;
     $result = $procedure->execute(['user.id' => $id]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertResultValueSetIsEmpty($result);
     $this->assertResultValuesCount(0, $result);
     $this->assertResultDataSetCount(0, $result);
     $this->assertNull($result->getErrorMessage());
     // -----------------------------------------------------------------------------------------------------------------
     // Test: user exists _AND_ has no profile !!!!!!!!
     // Remember that the last user has no profile !!!!!!!
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $user[0]['max'];
     $result = $procedure->execute(['user.id' => $id]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertResultValueSetIsEmpty($result);
     $this->assertResultValuesCount(0, $result);
     $this->assertResultDataSetCount(0, $result);
     $this->assertNull($result->getErrorMessage());
 }
Beispiel #3
0
 public function testIt()
 {
     $REQ_NAME = 'User/Authenticate';
     CliWriter::echoInfo("Loading " . __FILE__);
     // Get the SQL request.
     $dataInterface = DatabaseInterface::getInstance();
     $request = $dataInterface->getSql($REQ_NAME);
     /** @var SqlResult $result */
     // -----------------------------------------------------------------------------------------------------------------
     // Test: Login does not exist.
     // -----------------------------------------------------------------------------------------------------------------
     $result = $request->execute(['user.login' => 'toto', 'user.password' => 'titi']);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     // -----------------------------------------------------------------------------------------------------------------
     // Test: Login exists, but password is not valid.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT login as 'user.login', password as 'user.password' FROM user LIMIT 1", []);
     $result = $request->execute(['user.login' => $user[0]['user.login'], 'user.password' => "{$user[0]['user.password']}___"]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     // -----------------------------------------------------------------------------------------------------------------
     // Test: Login exists, and password is valid.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT login as 'user.login', password as 'user.password' FROM user LIMIT 1", []);
     $result = $request->execute(['user.login' => $user[0]['user.login'], 'user.password' => $user[0]['user.password']]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsNotEmpty($result);
     $this->assertResultDataSetCount(1, $result);
     $this->assertNull($result->getErrorMessage());
 }
Beispiel #4
0
 public function testIt()
 {
     $REQ_NAME = 'Profile/Get';
     CliWriter::echoInfo("Loading " . __FILE__);
     // Initialize the database.
     CliWriter::echoInfo("Loaded");
     // Get the SQL request.
     $dataInterface = DatabaseInterface::getInstance();
     $request = $dataInterface->getSql($REQ_NAME);
     /** @var SqlResult $result */
     // -----------------------------------------------------------------------------------------------------------------
     // Test: profile does not exist (no user associated).
     // -----------------------------------------------------------------------------------------------------------------
     $res = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $res[0]['max'] + 1;
     $result = $request->execute(['profile.fk_user_id' => $id]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     // -----------------------------------------------------------------------------------------------------------------
     // Test: profile exists.
     // -----------------------------------------------------------------------------------------------------------------
     $res = TestTools::select("SELECT max(profile.fk_user_id) as 'max' FROM profile", []);
     $id = $res[0]['max'];
     $result = $request->execute(['profile.fk_user_id' => $id]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsNotEmpty($result);
     $this->assertNull($result->getErrorMessage());
     $this->assertResultDataSetCount(1, $result);
 }
Beispiel #5
0
 public function testMysqlConnect()
 {
     $connector = new \dbeurive\Backend\Cli\Adapter\Database\Connector\MySqlPdo($this->__mySqlConnectorConfiguration);
     $connector->connect();
     /** @var \PDO $pdo */
     $pdo = $connector->getDatabaseHandler();
     // The connexion is not established.
     Utils\Pdo::setPdo($pdo);
     $result = Utils\Pdo::select("SELECT COUNT(id) FROM user;");
     $this->assertCount(1, $result);
 }
Beispiel #6
0
 public function testIt()
 {
     $REQ_NAME = 'User/Delete';
     // Get the SQL request.
     $dataInterface = DatabaseInterface::getInstance();
     $request = $dataInterface->getSql($REQ_NAME);
     /** @var SqlResult $result */
     // -------------------------------------------------------------------------------------------------------------
     // Test: user's ID does not exists
     // -------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $user[0]['max'] + 1;
     $result = $request->execute(['user.id' => $id]);
     print_r($result->getErrorMessage());
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     // -------------------------------------------------------------------------------------------------------------
     // Test: delete a user that does note have any profile. It works.
     // -------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $user[0]['max'];
     $result = $request->execute(['user.id' => $id]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     // -------------------------------------------------------------------------------------------------------------
     // Test: initial validation fails (the mandatory configuration is not defined).
     // -------------------------------------------------------------------------------------------------------------
     error_reporting(E_ERROR | E_PARSE);
     $result = $request->execute([]);
     error_reporting(E_WARNING | E_ERROR | E_PARSE);
     $this->assertFalse($result->isSuccess());
     // -------------------------------------------------------------------------------------------------------------
     // Test: delete a user that has a profile. It does NOT works.
     // -------------------------------------------------------------------------------------------------------------
     $this->expectException(\PDOException::class);
     $user = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $user[0]['max'];
     // error_reporting(E_ERROR | E_PARSE);
     $request->execute(['user.id' => $id]);
     // error_reporting(E_WARNING | E_ERROR | E_PARSE);
 }
Beispiel #7
0
 public function testIt()
 {
     $REQ_NAME = 'User/Update';
     CliWriter::echoInfo("Loading " . __FILE__);
     // Get the SQL request.
     $dataInterface = DatabaseInterface::getInstance();
     $request = $dataInterface->getSql($REQ_NAME);
     /** @var SqlResult $result */
     // -----------------------------------------------------------------------------------------------------------------
     // Update a password.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT max(user.id) as 'max' FROM user", []);
     $id = $user[0]['max'];
     $result = $request->execute(['user.id' => $id, 'user.password' => "New Password!"]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     $res = TestTools::select("SELECT user.password as 'user.password' FROM user WHERE id={$id}", []);
     $password = $res[0]['user.password'];
     $this->assertEquals('New Password!', $password);
 }
Beispiel #8
0
 public function testIt()
 {
     $REQ_NAME = 'User/Upsert';
     CliWriter::echoInfo("Loading " . __FILE__);
     // Get the SQL request.
     $dataInterface = DatabaseInterface::getInstance();
     $request = $dataInterface->getSql($REQ_NAME);
     /** @var SqlResult $result */
     // -----------------------------------------------------------------------------------------------------------------
     // Update a password.
     // -----------------------------------------------------------------------------------------------------------------
     $user = TestTools::select("SELECT * FROM user ORDER BY id LIMIT 1", []);
     $id = $user[0]['id'];
     $login = $user[0]['login'];
     $password = $user[0]['password'];
     $description = $user[0]['description'];
     $result = $request->execute(['user.login' => $login, 'user.password' => "New {$password}!", 'user.description' => $description]);
     $this->assertStatusIsOk($result);
     $this->assertResultDataSetIsEmpty($result);
     $this->assertNull($result->getErrorMessage());
     $res = TestTools::select("SELECT user.password as 'user.password' FROM user WHERE id={$id}", []);
     $newPassword = $res[0]['user.password'];
     $this->assertEquals("New {$password}!", $newPassword);
 }
Beispiel #9
0
    // -----------------------------------------------------------------------------------------------------------------
    // Clean the database.
    // ----------------------------------------------------------------------------------------------------------------
    \dbeurive\BackendTest\Utils\Pdo::delete("DELETE FROM profile");
    \dbeurive\BackendTest\Utils\Pdo::delete("DELETE FROM user");
    // -----------------------------------------------------------------------------------------------------------------
    // Creating users.
    // Please note that we create a special user with no profile.
    // This special user is the one the the last ID (the greatest ID's value).
    // -----------------------------------------------------------------------------------------------------------------
    for ($i = 1; $i <= $USER_COUNT + 1; $i++) {
        $v = array('login' => "login{$i}", 'password' => "password{$i}", 'description' => "description{$i}");
        $sql = "INSERT INTO user (login, password, description) " . "VALUES " . "(:login, :password, :description)";
        \dbeurive\BackendTest\Utils\Pdo::insert($sql, $v);
    }
    $ids['users'] = array_map(function ($v) {
        return $v[0];
    }, \dbeurive\BackendTest\Utils\Pdo::select("SELECT id FROM user ORDER BY id", array(), \PDO::FETCH_NUM));
    // -----------------------------------------------------------------------------------------------------------------
    // Creating users' profiles.
    // -----------------------------------------------------------------------------------------------------------------
    for ($i = 0; $i < $USER_COUNT; $i++) {
        $v = array('first_name' => "firstName{$i}", 'last_name' => "name{$i}", 'fk_user_id' => $ids['users'][$i]);
        $sql = "INSERT INTO profile (first_name, last_name, fk_user_id) " . "VALUES " . "(:first_name, :last_name, :fk_user_id)";
        \dbeurive\BackendTest\Utils\Pdo::insert($sql, $v);
    }
    $ids['profiles'] = array_map(function ($v) {
        return $v[0];
    }, \dbeurive\BackendTest\Utils\Pdo::select("SELECT id FROM profile", array(), \PDO::FETCH_NUM));
    return true;
}, $pdo);