Files
DomFramework/Tests/AuthhtpasswdTest.php

73 lines
2.0 KiB
PHP

<?php
/**
* DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD
*/
namespace Domframework\Tests;
use Domframework\Authhtpasswd;
/**
* Test the Authhtpasswd.php file
*/
class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
{
public function testClean()
{
if (file_exists("/tmp/htpasswd.file")) {
unlink("/tmp/htpasswd.file");
}
file_put_contents(
"/tmp/htpasswd.file",
'toto@toto.com:$2y$05$dO7qyX4simzg3pMgWyqHgeAjFauXEyUdPdyrwDMVNj4fTuE24TGuq'
. "\n" .
'titi@titi.com:$2y$05$dO7qyX4simzg3pMgWyqHgeAjFauXEyUdPdyrwDMVNj4fTuE24TGuq'
. "\n"
);
}
public function testConnect()
{
$authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
$res = $authhtpasswd->connect();
$this->assertSame($res, null);
}
public function testAuthentication1()
{
$authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
$res = $authhtpasswd->authentication("toto@toto.com", "toto123");
$this->assertSame($res, true);
}
public function testAuthentication2()
{
$authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
$this->setExpectedException("Exception");
$res = $authhtpasswd->authentication("UNKNOWN@toto.com", "toto123");
}
public function testAuthentication3()
{
$authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
$this->setExpectedException("Exception");
$res = $authhtpasswd->authentication("toto@toto.com", "BAD PASSWD");
}
public function testAuthentication4()
{
$authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
$res = $authhtpasswd->authentication("titi@titi.com", "toto123");
$this->assertSame($res, true);
}
}