Update Tests to supports namespaces
This commit is contained in:
93
Tests/CsrfTest.php
Normal file
93
Tests/CsrfTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
/** Test the csrf.php file */
|
||||
class csrfTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_csrf1 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$res = $csrf->createToken ();
|
||||
$GLOBALS["CSRFTEST-Token"] = $res;
|
||||
$this->assertSame (30, strlen ($res));
|
||||
}
|
||||
|
||||
public function test_csrf2 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$res = $csrf->createToken ();
|
||||
$this->assertSame (
|
||||
strspn ($res,
|
||||
"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ") , strlen ($res));
|
||||
}
|
||||
|
||||
public function test_csrf3 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$this->setExpectedException ("Exception");
|
||||
$res = $csrf->checkToken ("NOT VALID TOKEN");
|
||||
}
|
||||
|
||||
public function test_csrf4 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$token = $csrf->createToken ();
|
||||
$res = $csrf->checkToken ($token);
|
||||
$this->assertSame (true, $res);
|
||||
}
|
||||
|
||||
public function test_csrf5 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$token = $csrf->createToken ();
|
||||
$res = $csrf->extendToken ($token);
|
||||
$this->assertSame (true, $res);
|
||||
}
|
||||
|
||||
public function test_csrf6 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$token = $csrf->createToken ();
|
||||
$res = $csrf->getToken ();
|
||||
$this->assertSame ($token, $res);
|
||||
}
|
||||
|
||||
public function test_csrf7 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$res = $csrf->getToken ();
|
||||
$this->assertSame (30, strlen ($res));
|
||||
}
|
||||
|
||||
public function test_csrf_multiple_1 ()
|
||||
{
|
||||
$csrf1 = new csrf ();
|
||||
$token1 = $csrf1->createToken ();
|
||||
$csrf2 = new csrf ();
|
||||
$token2 = $csrf2->createToken ();
|
||||
$this->assertSame (true,
|
||||
$csrf2->checkToken ($token1) && $csrf2->checkToken ($token2));
|
||||
}
|
||||
|
||||
public function test_csrf_multiple_extend_2 ()
|
||||
{
|
||||
$csrf = new csrf ();
|
||||
$res = $csrf->extendToken ($GLOBALS["CSRFTEST-Token"]);
|
||||
$this->assertSame (true, $res);
|
||||
}
|
||||
|
||||
public function test_csrf_multiple_get ()
|
||||
{
|
||||
$csrf1 = new csrf ();
|
||||
$token1 = $csrf1->createToken ();
|
||||
$csrf2 = new csrf ();
|
||||
$token2 = $csrf2->getToken ();
|
||||
$this->assertSame ($token1, $token2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user