135 lines
4.0 KiB
PHP
135 lines
4.0 KiB
PHP
<?php
|
|
|
|
/** DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Userssql;
|
|
|
|
/** Test the Userssql.php file */
|
|
class UserssqlTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function test_clean()
|
|
{
|
|
@unlink("/tmp/database.db");
|
|
}
|
|
|
|
public function test_initStorage()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->initStorage();
|
|
$this->assertSame($res, 0);
|
|
}
|
|
|
|
public function test_listusers1()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->listusers();
|
|
$this->assertSame($res, array ());
|
|
}
|
|
|
|
public function test_adduser1()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->adduser("toto@toto.com", "Toto", "Toto2");
|
|
$this->assertSame($res, "toto@toto.com");
|
|
}
|
|
|
|
public function test_listusers2()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->listusers();
|
|
$this->assertSame($res, array (array ("email" => "toto@toto.com",
|
|
"firstname" => "Toto",
|
|
"lastname" => "Toto2")));
|
|
}
|
|
|
|
public function test_overwritepassword1()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->overwritepassword("toto@toto.com", "PassW0rd");
|
|
$this->assertSame($res, 1);
|
|
}
|
|
|
|
public function test_checkValidPassword1()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd");
|
|
$this->assertSame($res, true);
|
|
}
|
|
|
|
public function test_checkValidPassword2()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->checkValidPassword("toto@toto.com", "BAD PASSWD");
|
|
$this->assertSame($res, false);
|
|
}
|
|
|
|
public function test_changepassword1()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->changepassword("toto@toto.com", "PassW0rd", "NEW PASS!");
|
|
$this->assertSame($res, 1);
|
|
}
|
|
|
|
public function test_checkValidPassword3()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd");
|
|
$this->assertSame($res, false);
|
|
}
|
|
|
|
public function test_checkValidPassword4()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->checkValidPassword("toto@toto.com", "NEW PASS!");
|
|
$this->assertSame($res, true);
|
|
}
|
|
|
|
public function test_updateuser()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->updateuser(
|
|
"toto@toto.com",
|
|
"titi@titi.com",
|
|
"titi",
|
|
"titi2"
|
|
);
|
|
$this->assertSame($res, 1);
|
|
}
|
|
|
|
public function test_listusers3()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->listusers();
|
|
$this->assertSame($res, array (array ("email" => "titi@titi.com",
|
|
"firstname" => "titi",
|
|
"lastname" => "titi2")));
|
|
}
|
|
|
|
public function test_checkValidPassword5()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->checkValidPassword("titi@titi.com", "NEW PASS!");
|
|
$this->assertSame($res, true);
|
|
}
|
|
|
|
public function test_deluser()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->deluser("titi@titi.com");
|
|
$this->assertSame($res, 1);
|
|
}
|
|
|
|
public function test_listusers4()
|
|
{
|
|
$userssql = new Userssql("sqlite:///tmp/database.db");
|
|
$res = $userssql->listusers();
|
|
$this->assertSame($res, array ());
|
|
}
|
|
}
|