ACL\Login phpUnit tets update for ajax page tests
This commit is contained in:
@@ -181,6 +181,50 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'error_string_text' => 'Success: No error',
|
'error_string_text' => 'Success: No error',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'load, no login, ajax flag' => [
|
||||||
|
// error code, only for exceptions
|
||||||
|
[
|
||||||
|
'page_name' => 'edit_users.php',
|
||||||
|
// for ajax
|
||||||
|
'ajax_page' => true,
|
||||||
|
'ajax_test_type' => 'parameter',
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
3000,
|
||||||
|
[
|
||||||
|
'login_error' => 0,
|
||||||
|
'error_string' => 'Success: <b>No error</b>',
|
||||||
|
'error_string_text' => 'Success: No error',
|
||||||
|
// for ajax
|
||||||
|
'action' => 'login',
|
||||||
|
'ajax_get_count' => 0,
|
||||||
|
'ajax_post_count' => 5,
|
||||||
|
'ajax_post_action' => 'login',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'load, no login, ajax globals' => [
|
||||||
|
// error code, only for exceptions
|
||||||
|
[
|
||||||
|
'page_name' => 'edit_users.php',
|
||||||
|
// for ajax
|
||||||
|
'ajax_page' => true,
|
||||||
|
'ajax_test_type' => 'globals',
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
[],
|
||||||
|
3000,
|
||||||
|
[
|
||||||
|
'login_error' => 0,
|
||||||
|
'error_string' => 'Success: <b>No error</b>',
|
||||||
|
'error_string_text' => 'Success: No error',
|
||||||
|
// for ajax
|
||||||
|
'action' => 'login',
|
||||||
|
'ajax_get_count' => 0,
|
||||||
|
'ajax_post_count' => 5,
|
||||||
|
'ajax_post_action' => 'login',
|
||||||
|
],
|
||||||
|
],
|
||||||
'load, session euid set only, php error' => [
|
'load, session euid set only, php error' => [
|
||||||
[
|
[
|
||||||
'page_name' => 'edit_users.php',
|
'page_name' => 'edit_users.php',
|
||||||
@@ -467,7 +511,13 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
int $error,
|
int $error,
|
||||||
array $expected
|
array $expected
|
||||||
): void {
|
): void {
|
||||||
|
// reset session
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
|
// reset post & get
|
||||||
|
$_GET = [];
|
||||||
|
$_POST = [];
|
||||||
|
// reset global ajax page call
|
||||||
|
unset($GLOBALS['AJAX_PAGE']);
|
||||||
// init session (as MOCK)
|
// init session (as MOCK)
|
||||||
/** @var \CoreLibs\Create\Session&MockObject */
|
/** @var \CoreLibs\Create\Session&MockObject */
|
||||||
$session_mock = $this->createPartialMock(
|
$session_mock = $this->createPartialMock(
|
||||||
@@ -588,7 +638,23 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
|
|
||||||
// run test
|
// run test
|
||||||
try {
|
try {
|
||||||
$login_mock->loginMainCall();
|
// if ajax call
|
||||||
|
// check if parameter, or globals (old type)
|
||||||
|
// else normal call
|
||||||
|
if (
|
||||||
|
!empty($mock_settings['ajax_test_type']) &&
|
||||||
|
$mock_settings['ajax_test_type'] == 'parameter'
|
||||||
|
) {
|
||||||
|
$login_mock->loginMainCall($mock_settings['ajax_page']);
|
||||||
|
} elseif (
|
||||||
|
!empty($mock_settings['ajax_test_type']) &&
|
||||||
|
$mock_settings['ajax_test_type'] == 'globals'
|
||||||
|
) {
|
||||||
|
$GLOBALS['AJAX_PAGE'] = $mock_settings['ajax_page'];
|
||||||
|
$login_mock->loginMainCall();
|
||||||
|
} else {
|
||||||
|
$login_mock->loginMainCall();
|
||||||
|
}
|
||||||
// on ok, do post login check based on expected return
|
// on ok, do post login check based on expected return
|
||||||
// - loginGetLastErrorCode
|
// - loginGetLastErrorCode
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@@ -678,8 +744,14 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// print "[E]: " . $e->getCode() . ", ERROR: " . $login_mock->loginGetLastErrorCode() . "/"
|
// print "[E]: " . $e->getCode() . ", ERROR: " . $login_mock->loginGetLastErrorCode() . "/"
|
||||||
// . ($expected['login_error'] ?? 0) . "\n";
|
// . ($expected['login_error'] ?? 0) . "\n";
|
||||||
|
// print "AJAX: " . $login_mock->loginGetAjaxFlag() . "\n";
|
||||||
|
// print "AJAX GLOBAL: " . ($GLOBALS['AJAX_PAGE'] ?? '{f}') . "\n";
|
||||||
|
// print "Login error expext: " . ($expected['login_error'] ?? '{0}') . "\n";
|
||||||
// if this is 3000, then we do further error checks
|
// if this is 3000, then we do further error checks
|
||||||
if ($e->getCode() == 3000) {
|
if (
|
||||||
|
$e->getCode() == 3000 ||
|
||||||
|
!empty($_POST['login_exit']) && $_POST['login_exit'] == 3000
|
||||||
|
) {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected['login_error'],
|
$expected['login_error'],
|
||||||
$login_mock->loginGetLastErrorCode(),
|
$login_mock->loginGetLastErrorCode(),
|
||||||
@@ -716,10 +788,51 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
'Assert login error string does not exit'
|
'Assert login error string does not exit'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// for ajax type, test post return values
|
||||||
|
if ($login_mock->loginGetAjaxFlag()) {
|
||||||
|
$this->assertCount(
|
||||||
|
$expected['ajax_get_count'],
|
||||||
|
$_GET,
|
||||||
|
'Assert ajax error _GET is valid count'
|
||||||
|
);
|
||||||
|
// post has only action, login_exit, login_error,
|
||||||
|
// login_error_text and login_html
|
||||||
|
// 5 entries
|
||||||
|
$this->assertCount(
|
||||||
|
$expected['ajax_post_count'],
|
||||||
|
$_POST,
|
||||||
|
'Assert ajax error _POST is valid count'
|
||||||
|
);
|
||||||
|
// test post entries
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected['ajax_post_action'],
|
||||||
|
$_POST['action'],
|
||||||
|
'Assert ajax _POST action'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$login_mock->loginGetLastErrorCode(),
|
||||||
|
$_POST['login_error'],
|
||||||
|
'Assert ajax _POST error'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$login_mock->loginGetErrorMsg($login_mock->loginGetLastErrorCode(), true),
|
||||||
|
$_POST['login_error_text'],
|
||||||
|
'Assert ajax _POST error text'
|
||||||
|
);
|
||||||
|
// html login basic check only, content is the same as when
|
||||||
|
// read from loginGetLoginHTML()
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
'<html>',
|
||||||
|
$_POST['login_html'],
|
||||||
|
'Assert ajax _POST html string exits'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// print "EXCEPTION: " . print_r($e, true) . "\n";
|
// print "EXCEPTION: " . print_r($e, true) . "\n";
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$e->getCode(),
|
!$login_mock->loginGetAjaxFlag() ?
|
||||||
|
$e->getCode() :
|
||||||
|
$_POST['login_exit'] ?? 0,
|
||||||
$error,
|
$error,
|
||||||
'Expected error code: ' . $e->getCode()
|
'Expected error code: ' . $e->getCode()
|
||||||
. ', ' . $e->getMessage()
|
. ', ' . $e->getMessage()
|
||||||
|
|||||||
@@ -3683,7 +3683,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function returingProvider(): array
|
public function returningPrvoider(): array
|
||||||
{
|
{
|
||||||
// NOTE that query can have multiple inserts
|
// NOTE that query can have multiple inserts
|
||||||
// NOTE if there are different INSERTS before the primary keys
|
// NOTE if there are different INSERTS before the primary keys
|
||||||
@@ -3801,7 +3801,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
*
|
*
|
||||||
* @covers ::dbGetReturningExt
|
* @covers ::dbGetReturningExt
|
||||||
* @covers ::dbGetReturningArray
|
* @covers ::dbGetReturningArray
|
||||||
* @dataProvider returingProvider
|
* @dataProvider returningPrvoider
|
||||||
* @testdox Check returning cursor using $pk_name with $key and $pos [$_dataName]
|
* @testdox Check returning cursor using $pk_name with $key and $pos [$_dataName]
|
||||||
*
|
*
|
||||||
* @param string $query
|
* @param string $query
|
||||||
|
|||||||
Reference in New Issue
Block a user