refactoring

This commit is contained in:
Roland Gruber 2023-10-31 17:36:39 +01:00
parent d611abedb4
commit 0afff2089e
24 changed files with 604 additions and 594 deletions

View file

@ -51,17 +51,17 @@ $row->addField(new htmlButton('name1', 'Click me'));
$row->addLabel(new htmlOutputText('Primary')); $row->addLabel(new htmlOutputText('Primary'));
$primaryButton = new htmlButton('name2', 'Click me'); $primaryButton = new htmlButton('name2', 'Click me');
$primaryButton->setCSSClasses(array('lam-primary')); $primaryButton->setCSSClasses(['lam-primary']);
$row->addField($primaryButton); $row->addField($primaryButton);
$row->addLabel(new htmlOutputText('Secondary')); $row->addLabel(new htmlOutputText('Secondary'));
$primaryButton = new htmlButton('name2a', 'Click me'); $primaryButton = new htmlButton('name2a', 'Click me');
$primaryButton->setCSSClasses(array('lam-secondary')); $primaryButton->setCSSClasses(['lam-secondary']);
$row->addField($primaryButton); $row->addField($primaryButton);
$row->addLabel(new htmlOutputText('Danger')); $row->addLabel(new htmlOutputText('Danger'));
$primaryButton = new htmlButton('name3', 'Click me'); $primaryButton = new htmlButton('name3', 'Click me');
$primaryButton->setCSSClasses(array('lam-danger')); $primaryButton->setCSSClasses(['lam-danger']);
$row->addField($primaryButton); $row->addField($primaryButton);
$row->addLabel(new htmlOutputText('Disabled')); $row->addLabel(new htmlOutputText('Disabled'));
@ -70,10 +70,10 @@ $buttonDisabled->setIsEnabled(false);
$row->addField($buttonDisabled); $row->addField($buttonDisabled);
$row->add(new htmlSubTitle('Tables')); $row->add(new htmlSubTitle('Tables'));
$tableTitles = array('text 1', 'text 2', 'text 3', 'text 4', 'text 5'); $tableTitles = ['text 1', 'text 2', 'text 3', 'text 4', 'text 5'];
$tableData = array(); $tableData = [];
for ($rowNumber = 0; $rowNumber < 10; $rowNumber++) { for ($rowNumber = 0; $rowNumber < 10; $rowNumber++) {
$tableRow = array(); $tableRow = [];
for ($column = 0; $column < 5; $column++) { for ($column = 0; $column < 5; $column++) {
$tableRow[] = new htmlOutputText('value' . $column); $tableRow[] = new htmlOutputText('value' . $column);
} }
@ -85,7 +85,7 @@ $row->add($table);
$row->addVerticalSpacer('2rem'); $row->addVerticalSpacer('2rem');
$row->add(new htmlOutputText('Account list')); $row->add(new htmlOutputText('Account list'));
$table = new htmlResponsiveTable($tableTitles, $tableData); $table = new htmlResponsiveTable($tableTitles, $tableData);
$table->setCSSClasses(array('accountlist')); $table->setCSSClasses(['accountlist']);
$row->add($table); $row->add($table);
$row->add(new htmlSubTitle('Input fields')); $row->add(new htmlSubTitle('Input fields'));
@ -95,7 +95,7 @@ $row->addField(new htmlInputField('text1', 'Some text'));
$row->addLabel(new htmlOutputText('Autocomplete')); $row->addLabel(new htmlOutputText('Autocomplete'));
$autocompleteInput = new htmlInputField('text1a', 'Some text'); $autocompleteInput = new htmlInputField('text1a', 'Some text');
$autocompleteInput->enableAutocompletion(array('Some text', 'Some text2', 'Some text3', 'Some text4')); $autocompleteInput->enableAutocompletion(['Some text', 'Some text2', 'Some text3', 'Some text4']);
$row->addField($autocompleteInput); $row->addField($autocompleteInput);
$row->addLabel(new htmlOutputText('Disabled')); $row->addLabel(new htmlOutputText('Disabled'));
@ -132,10 +132,10 @@ $checkRow2->add($checkboxDisabled);
$row->add($checkRow2); $row->add($checkRow2);
$row->addLabel(new htmlOutputText('Default')); $row->addLabel(new htmlOutputText('Default'));
$row->addField(new htmlRadio('radio1', array('label1' => 'value', 'label2' => 'value2'), 'value')); $row->addField(new htmlRadio('radio1', ['label1' => 'value', 'label2' => 'value2'], 'value'));
$row->addLabel(new htmlOutputText('Disabled')); $row->addLabel(new htmlOutputText('Disabled'));
$radioDisabled = new htmlRadio('radio2', array('label1' => 'value', 'label2' => 'value2'), 'value'); $radioDisabled = new htmlRadio('radio2', ['label1' => 'value', 'label2' => 'value2'], 'value');
$radioDisabled->setIsEnabled(false); $radioDisabled->setIsEnabled(false);
$row->addField($radioDisabled); $row->addField($radioDisabled);
@ -156,20 +156,20 @@ $colorDisabled->setIsEnabled(false);
$row->addField($colorDisabled); $row->addField($colorDisabled);
$row->addLabel(new htmlOutputText('Default select')); $row->addLabel(new htmlOutputText('Default select'));
$row->addField(new htmlSelect('select1', array(1, 2, 3), array(2))); $row->addField(new htmlSelect('select1', [1, 2, 3], [2]));
$row->addLabel(new htmlOutputText('Disabled select')); $row->addLabel(new htmlOutputText('Disabled select'));
$selectDisabled = new htmlSelect('select2', array(1, 2, 3), array(2)); $selectDisabled = new htmlSelect('select2', [1, 2, 3], [2]);
$selectDisabled->setIsEnabled(false); $selectDisabled->setIsEnabled(false);
$row->addField($selectDisabled); $row->addField($selectDisabled);
$row->addLabel(new htmlOutputText('Default multiselect')); $row->addLabel(new htmlOutputText('Default multiselect'));
$multiSelect1 = new htmlSelect('select1', array("1", "2", "3"), array("1", "3"), 5); $multiSelect1 = new htmlSelect('select1', ["1", "2", "3"], ["1", "3"], 5);
$multiSelect1->setMultiSelect(true); $multiSelect1->setMultiSelect(true);
$row->addField($multiSelect1); $row->addField($multiSelect1);
$row->addLabel(new htmlOutputText('Disabled multiselect')); $row->addLabel(new htmlOutputText('Disabled multiselect'));
$multiSelect2 = new htmlSelect('select2', array("1", "2", "3"), array("1", "3"), 5); $multiSelect2 = new htmlSelect('select2', ["1", "2", "3"], ["1", "3"], 5);
$multiSelect2->setIsEnabled(false); $multiSelect2->setIsEnabled(false);
$multiSelect2->setMultiSelect(true); $multiSelect2->setMultiSelect(true);
$row->addField($multiSelect2); $row->addField($multiSelect2);
@ -177,12 +177,12 @@ $row->addField($multiSelect2);
$row->add(new htmlSpacer(null, '5rem')); $row->add(new htmlSpacer(null, '5rem'));
$row->addLabel(new htmlOutputText('Default select filter')); $row->addLabel(new htmlOutputText('Default select filter'));
$defaultSelectElements = array(); $defaultSelectElements = [];
for ($i = 0; $i < 1000; $i++) { for ($i = 0; $i < 1000; $i++) {
$text = str_pad($i, 4, '0', STR_PAD_LEFT); $text = str_pad($i, 4, '0', STR_PAD_LEFT);
$defaultSelectElements['Text ' . $text] = $text; $defaultSelectElements['Text ' . $text] = $text;
} }
$row->addField(new htmlSelect('selectWithFilter', $defaultSelectElements, array('0002'))); $row->addField(new htmlSelect('selectWithFilter', $defaultSelectElements, ['0002']));
$row->addLabel(new htmlOutputText('Filter')); $row->addLabel(new htmlOutputText('Filter'));
$selectFilter = new htmlInputField('selectFilter'); $selectFilter = new htmlInputField('selectFilter');
$selectFilter->filterSelectBox('selectWithFilter'); $selectFilter->filterSelectBox('selectWithFilter');
@ -191,12 +191,12 @@ $row->addField($selectFilter);
$row->add(new htmlSpacer(null, '5rem')); $row->add(new htmlSpacer(null, '5rem'));
$row->addLabel(new htmlOutputText('Default multiselect filter')); $row->addLabel(new htmlOutputText('Default multiselect filter'));
$defaultScrollElements = array(); $defaultScrollElements = [];
for ($i = 0; $i < 1000; $i++) { for ($i = 0; $i < 1000; $i++) {
$text = str_pad($i, 4, '0', STR_PAD_LEFT); $text = str_pad($i, 4, '0', STR_PAD_LEFT);
$defaultScrollElements['Text ' . $text] = $text; $defaultScrollElements['Text ' . $text] = $text;
} }
$scrollSelect = new htmlSelect('scrollSelect', $defaultScrollElements, array("0001", "0003", "0999"), 10); $scrollSelect = new htmlSelect('scrollSelect', $defaultScrollElements, ["0001", "0003", "0999"], 10);
$scrollSelect->setHasDescriptiveElements(true); $scrollSelect->setHasDescriptiveElements(true);
$scrollSelect->setMultiSelect(true); $scrollSelect->setMultiSelect(true);
$row->addField($scrollSelect); $row->addField($scrollSelect);
@ -208,12 +208,12 @@ $row->addField($scrollFilter);
$row->add(new htmlSpacer(null, '5rem')); $row->add(new htmlSpacer(null, '5rem'));
$row->addLabel(new htmlOutputText('Dynamic multiselect filter')); $row->addLabel(new htmlOutputText('Dynamic multiselect filter'));
$dynamicScrollElements = array(); $dynamicScrollElements = [];
for ($i = 0; $i < 100000; $i++) { for ($i = 0; $i < 100000; $i++) {
$text = str_pad($i, 6, '0', STR_PAD_LEFT); $text = str_pad($i, 6, '0', STR_PAD_LEFT);
$dynamicScrollElements['Text ' . $text] = $text; $dynamicScrollElements['Text ' . $text] = $text;
} }
$multiSelect3 = new htmlSelect('dynamicSelect', $dynamicScrollElements, array("000001", "000003", "099999"), 10); $multiSelect3 = new htmlSelect('dynamicSelect', $dynamicScrollElements, ["000001", "000003", "099999"], 10);
$multiSelect3->setHasDescriptiveElements(true); $multiSelect3->setHasDescriptiveElements(true);
$multiSelect3->setMultiSelect(true); $multiSelect3->setMultiSelect(true);
$multiSelect3->enableDynamicScrolling(); $multiSelect3->enableDynamicScrolling();
@ -257,7 +257,7 @@ $row->add(new htmlSpacer(null, '5rem'));
$row->add(new htmlSubTitle('Accordion')); $row->add(new htmlSubTitle('Accordion'));
$accordionElementsSingle = array(); $accordionElementsSingle = [];
$accordionElementsSingleContent1 = new htmlResponsiveRow(); $accordionElementsSingleContent1 = new htmlResponsiveRow();
$accordionElementsSingleContent1->add(new htmlResponsiveInputField('Input 1', 'acc1i1')); $accordionElementsSingleContent1->add(new htmlResponsiveInputField('Input 1', 'acc1i1'));
$accordionElementsSingleContent1->add(new htmlResponsiveInputField('Input 2', 'acc1i2')); $accordionElementsSingleContent1->add(new htmlResponsiveInputField('Input 2', 'acc1i2'));
@ -267,7 +267,7 @@ $row->add(new htmlAccordion('acc_single', $accordionElementsSingle));
$row->add(new htmlSpacer(null, '5rem')); $row->add(new htmlSpacer(null, '5rem'));
$accordionElementsSingleClosed = array(); $accordionElementsSingleClosed = [];
$accordionElementsSingleContentClosed = new htmlResponsiveRow(); $accordionElementsSingleContentClosed = new htmlResponsiveRow();
$accordionElementsSingleContentClosed->add(new htmlResponsiveInputField('Input 1', 'acc1ai1')); $accordionElementsSingleContentClosed->add(new htmlResponsiveInputField('Input 1', 'acc1ai1'));
$accordionElementsSingleContentClosed->add(new htmlResponsiveInputField('Input 2', 'acc1ai2')); $accordionElementsSingleContentClosed->add(new htmlResponsiveInputField('Input 2', 'acc1ai2'));
@ -277,7 +277,7 @@ $row->add(new htmlAccordion('acc_singleClosed', $accordionElementsSingleClosed,
$row->add(new htmlSpacer(null, '5rem')); $row->add(new htmlSpacer(null, '5rem'));
$accordionElementsMulti = array(); $accordionElementsMulti = [];
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$accordionElementsContent = new htmlResponsiveRow(); $accordionElementsContent = new htmlResponsiveRow();
$accordionElementsContent->add(new htmlResponsiveInputField('Input 1', 'acc1i1' . $i)); $accordionElementsContent->add(new htmlResponsiveInputField('Input 1', 'acc1i1' . $i));
@ -291,33 +291,33 @@ $row->add(new htmlSpacer(null, '5rem'));
$row->add(new htmlSubTitle('Sortable list')); $row->add(new htmlSubTitle('Sortable list'));
$sortableList1 = new htmlSortableList(array( $sortableList1 = new htmlSortableList([
'text 1', 'text 1',
'text 2', 'text 2',
'text 3', 'text 3',
'text 4', 'text 4',
'text 5', 'text 5',
), 'sortableList1'); ], 'sortableList1');
$sortableList1->setCSSClasses(array('module-list')); $sortableList1->setCSSClasses(array('module-list'));
$row->add($sortableList1); $row->add($sortableList1);
$row->add(new htmlSpacer(null, '2rem')); $row->add(new htmlSpacer(null, '2rem'));
$listElements = array(); $listElements = [];
for ($i = 0; $i < 8; $i++) { for ($i = 0; $i < 8; $i++) {
$el = new htmlTable('100%'); $el = new htmlTable('100%');
$image = new htmlImage('../../graphics/tux.svg'); $image = new htmlImage('../../graphics/tux.svg');
$image->setCSSClasses(array('size16', 'margin-right5-mobile-only')); $image->setCSSClasses(['size16', 'margin-right5-mobile-only']);
$el->addElement($image); $el->addElement($image);
$el->addElement(new htmlOutputText("Text " . $i)); $el->addElement(new htmlOutputText("Text " . $i));
$image2 = new htmlImage('../../graphics/del.svg'); $image2 = new htmlImage('../../graphics/del.svg');
$image2->setCSSClasses(array('size16', 'margin-right5-mobile-only')); $image2->setCSSClasses(['size16', 'margin-right5-mobile-only']);
$image2->alignment = htmlElement::ALIGN_RIGHT; $image2->alignment = htmlElement::ALIGN_RIGHT;
$el->addElement($image2); $el->addElement($image2);
$listElements[] = $el; $listElements[] = $el;
} }
$sortableList2 = new htmlSortableList($listElements, 'sortableList2'); $sortableList2 = new htmlSortableList($listElements, 'sortableList2');
$sortableList2->setCSSClasses(array('module-list')); $sortableList2->setCSSClasses(['module-list']);
$row->add($sortableList2); $row->add($sortableList2);
$row->add(new htmlSubTitle('Alert')); $row->add(new htmlSubTitle('Alert'));
@ -344,7 +344,7 @@ $row->add(new htmlSpacer(null, '20rem'));
$form = new htmlForm('formname', 'designExamples.php', $row); $form = new htmlForm('formname', 'designExamples.php', $row);
parseHtml(null, $form, array(), false, 'user'); parseHtml(null, $form, [], false, 'user');
?> ?>
<script type="text/javascript" src="../../templates/lib/extra/ckeditor/ckeditor.js"></script> <script type="text/javascript" src="../../templates/lib/extra/ckeditor/ckeditor.js"></script>

View file

@ -36,7 +36,7 @@ require_once 'lam/lib/2factor.inc';
*/ */
class TwoFactorTest extends TestCase { class TwoFactorTest extends TestCase {
const USER_NAME = 'uid=test,dc=example,dc=com'; public const USER_NAME = 'uid=test,dc=example,dc=com';
private ?LAMConfig $serverProfile = null; private ?LAMConfig $serverProfile = null;

View file

@ -2,7 +2,7 @@
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2018 - 2021 Roland Gruber Copyright (C) 2018 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -51,8 +51,8 @@ class AccountTest extends TestCase {
$this->assertEquals(7215, unformatShortFormatToSeconds('2h15s')); $this->assertEquals(7215, unformatShortFormatToSeconds('2h15s'));
$this->assertEquals(172815, unformatShortFormatToSeconds('2d15s')); $this->assertEquals(172815, unformatShortFormatToSeconds('2d15s'));
$this->assertEquals(173700, unformatShortFormatToSeconds('2d15m')); $this->assertEquals(173700, unformatShortFormatToSeconds('2d15m'));
$this->assertEquals(1209615, unformatShortFormatToSeconds('2w15s')); $this->assertEquals(1_209_615, unformatShortFormatToSeconds('2w15s'));
$this->assertEquals(95817615, unformatShortFormatToSeconds('3y2w15s')); $this->assertEquals(95_817_615, unformatShortFormatToSeconds('3y2w15s'));
} }
/** /**
@ -83,8 +83,8 @@ class AccountTest extends TestCase {
$this->assertEquals('2h15s', formatSecondsToShortFormat(7215)); $this->assertEquals('2h15s', formatSecondsToShortFormat(7215));
$this->assertEquals('2d15s', formatSecondsToShortFormat(172815)); $this->assertEquals('2d15s', formatSecondsToShortFormat(172815));
$this->assertEquals('2d15m', formatSecondsToShortFormat(173700)); $this->assertEquals('2d15m', formatSecondsToShortFormat(173700));
$this->assertEquals('2w15s', formatSecondsToShortFormat(1209615)); $this->assertEquals('2w15s', formatSecondsToShortFormat(1_209_615));
$this->assertEquals('3y2w15s', formatSecondsToShortFormat(95817615)); $this->assertEquals('3y2w15s', formatSecondsToShortFormat(95_817_615));
} }
/** /**
@ -199,7 +199,7 @@ class AccountTest extends TestCase {
*/ */
function testPwdHash() { function testPwdHash() {
$testPassword = '1234556'; $testPassword = '1234556';
$types = array('ARGON2ID', 'SSHA', 'SHA', 'SMD5', 'MD5', 'CRYPT', 'CRYPT-SHA512'); $types = ['ARGON2ID', 'SSHA', 'SHA', 'SMD5', 'MD5', 'CRYPT', 'CRYPT-SHA512'];
foreach ($types as $type) { foreach ($types as $type) {
$hash = pwd_hash($testPassword, true, $type); $hash = pwd_hash($testPassword, true, $type);
$type = getHashType($hash); $type = getHashType($hash);
@ -244,7 +244,7 @@ class AccountTest extends TestCase {
function testGenerateRandomPassword() { function testGenerateRandomPassword() {
global $_SESSION; global $_SESSION;
$_SESSION = array('cfgMain' => new LAMCfgMain()); $_SESSION = ['cfgMain' => new LAMCfgMain()];
$this->assertEquals(20, strlen(generateRandomPassword(20))); $this->assertEquals(20, strlen(generateRandomPassword(20)));
} }

View file

@ -2,7 +2,7 @@
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2019 Roland Gruber Copyright (C) 2019 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -34,233 +34,243 @@ class BaseModuleTest extends TestCase {
} }
function test_check_profileOptions_ext_preg() { function test_check_profileOptions_ext_preg() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('10'), 'test_val1' => ['10'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEmpty($errors, print_r($errors, true)); $this->assertEmpty($errors, print_r($errors, true));
} }
function test_check_profileOptions_ext_preg_fail() { function test_check_profileOptions_ext_preg_fail() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('a'), 'test_val1' => ['a'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEquals(array(array('ERROR', 'error1')), $errors); $this->assertEquals([['ERROR', 'error1']], $errors);
} }
function test_check_profileOptions_regex() { function test_check_profileOptions_regex() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_reg1'] = array( $meta['profile_checks']['test_reg1'] = [
'type' => 'regex', 'type' => 'regex',
'regex' => 'ab+a', 'regex' => 'ab+a',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_reg1' => array('abbba'), 'test_reg1' => ['abbba'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEmpty($errors, print_r($errors, true)); $this->assertEmpty($errors, print_r($errors, true));
} }
function test_check_profileOptions_regex_fail() { function test_check_profileOptions_regex_fail() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_reg1'] = array( $meta['profile_checks']['test_reg1'] = [
'type' => 'regex', 'type' => 'regex',
'regex' => 'ab+a', 'regex' => 'ab+a',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_reg1' => array('aCa'), 'test_reg1' => ['aCa'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEquals(array(array('ERROR', 'error1')), $errors); $this->assertEquals([['ERROR', 'error1']], $errors);
} }
function test_check_profileOptions_cmp() { function test_check_profileOptions_cmp() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$meta['profile_checks']['test_val2'] = array( $meta['profile_checks']['test_val2'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error2')); 'error_message' => ['ERROR', 'error2']];
$meta['profile_checks']['test_cmp'] = array( $meta['profile_checks']['test_cmp'] = [
'type' => 'int_greater', 'type' => 'int_greater',
'cmp_name1' => 'test_val2', 'cmp_name1' => 'test_val2',
'cmp_name2' => 'test_val1', 'cmp_name2' => 'test_val1',
'error_message' => array('ERROR', 'errorCMP')); 'error_message' => ['ERROR', 'errorCMP']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('10'), 'test_val1' => ['10'],
'test_val2' => array('20'), 'test_val2' => ['20'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEmpty($errors, print_r($errors, true)); $this->assertEmpty($errors, print_r($errors, true));
} }
function test_check_profileOptions_cmp_fail_equal() { function test_check_profileOptions_cmp_fail_equal() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$meta['profile_checks']['test_val2'] = array( $meta['profile_checks']['test_val2'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error2')); 'error_message' => ['ERROR', 'error2']];
$meta['profile_checks']['test_cmp'] = array( $meta['profile_checks']['test_cmp'] = [
'type' => 'int_greater', 'type' => 'int_greater',
'cmp_name1' => 'test_val2', 'cmp_name1' => 'test_val2',
'cmp_name2' => 'test_val1', 'cmp_name2' => 'test_val1',
'error_message' => array('ERROR', 'errorCMP')); 'error_message' => ['ERROR', 'errorCMP']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('10'), 'test_val1' => ['10'],
'test_val2' => array('10'), 'test_val2' => ['10'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEquals(array(array('ERROR', 'errorCMP')), $errors); $this->assertEquals([['ERROR', 'errorCMP']], $errors);
} }
function test_check_profileOptions_cmp_fail_smaller() { function test_check_profileOptions_cmp_fail_smaller() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$meta['profile_checks']['test_val2'] = array( $meta['profile_checks']['test_val2'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error2')); 'error_message' => ['ERROR', 'error2']];
$meta['profile_checks']['test_cmp'] = array( $meta['profile_checks']['test_cmp'] = [
'type' => 'int_greater', 'type' => 'int_greater',
'cmp_name1' => 'test_val2', 'cmp_name1' => 'test_val2',
'cmp_name2' => 'test_val1', 'cmp_name2' => 'test_val1',
'error_message' => array('ERROR', 'errorCMP')); 'error_message' => ['ERROR', 'errorCMP']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('20'), 'test_val1' => ['20'],
'test_val2' => array('10'), 'test_val2' => ['10'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEquals(array(array('ERROR', 'errorCMP')), $errors); $this->assertEquals([['ERROR', 'errorCMP']], $errors);
} }
function test_check_profileOptions_cmpEqual_greater() { function test_check_profileOptions_cmpEqual_greater() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$meta['profile_checks']['test_val2'] = array( $meta['profile_checks']['test_val2'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error2')); 'error_message' => ['ERROR', 'error2']];
$meta['profile_checks']['test_cmp'] = array( $meta['profile_checks']['test_cmp'] = [
'type' => 'int_greaterOrEqual', 'type' => 'int_greaterOrEqual',
'cmp_name1' => 'test_val2', 'cmp_name1' => 'test_val2',
'cmp_name2' => 'test_val1', 'cmp_name2' => 'test_val1',
'error_message' => array('ERROR', 'errorCMP')); 'error_message' => ['ERROR', 'errorCMP']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('10'), 'test_val1' => ['10'],
'test_val2' => array('20'), 'test_val2' => ['20'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEmpty($errors, print_r($errors, true)); $this->assertEmpty($errors, print_r($errors, true));
} }
function test_check_profileOptions_cmpEqual_equal() { function test_check_profileOptions_cmpEqual_equal() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$meta['profile_checks']['test_val2'] = array( $meta['profile_checks']['test_val2'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error2')); 'error_message' => ['ERROR', 'error2']];
$meta['profile_checks']['test_cmp'] = array( $meta['profile_checks']['test_cmp'] = [
'type' => 'int_greaterOrEqual', 'type' => 'int_greaterOrEqual',
'cmp_name1' => 'test_val2', 'cmp_name1' => 'test_val2',
'cmp_name2' => 'test_val1', 'cmp_name2' => 'test_val1',
'error_message' => array('ERROR', 'errorCMP')); 'error_message' => ['ERROR', 'errorCMP']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('10'), 'test_val1' => ['10'],
'test_val2' => array('10'), 'test_val2' => ['10'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEmpty($errors, print_r($errors, true)); $this->assertEmpty($errors, print_r($errors, true));
} }
function test_check_profileOptions_cmpEqual_fail() { function test_check_profileOptions_cmpEqual_fail() {
$meta = [];
$module = new baseModuleDummy('user'); $module = new baseModuleDummy('user');
$meta['profile_checks']['test_val1'] = array( $meta['profile_checks']['test_val1'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error1')); 'error_message' => ['ERROR', 'error1']];
$meta['profile_checks']['test_val2'] = array( $meta['profile_checks']['test_val2'] = [
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'digit', 'regex' => 'digit',
'error_message' => array('ERROR', 'error2')); 'error_message' => ['ERROR', 'error2']];
$meta['profile_checks']['test_cmp'] = array( $meta['profile_checks']['test_cmp'] = [
'type' => 'int_greaterOrEqual', 'type' => 'int_greaterOrEqual',
'cmp_name1' => 'test_val2', 'cmp_name1' => 'test_val2',
'cmp_name2' => 'test_val1', 'cmp_name2' => 'test_val1',
'error_message' => array('ERROR', 'errorCMP')); 'error_message' => ['ERROR', 'errorCMP']];
$module->setMeta($meta); $module->setMeta($meta);
$options = array( $options = [
'test_val1' => array('20'), 'test_val1' => ['20'],
'test_val2' => array('10'), 'test_val2' => ['10'],
); ];
$errors = $module->check_profileOptions($options, 'user1'); $errors = $module->check_profileOptions($options, 'user1');
$this->assertEquals(array(array('ERROR', 'errorCMP')), $errors); $this->assertEquals([['ERROR', 'errorCMP']], $errors);
} }
} }

View file

@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 - 2021 Roland Gruber Copyright (C) 2020 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -32,46 +32,48 @@ include_once __DIR__ . '/../../lib/persistence.inc';
class ConfigDataExporterTest extends TestCase { class ConfigDataExporterTest extends TestCase {
public function testExportAsJson() { public function testExportAsJson() {
$mainData = array( $mainData = [
'confMainKey1' => 'val', 'confMainKey1' => 'val',
'confMainKey2' => 4, 'confMainKey2' => 4,
'confMainKey3' => '', 'confMainKey3' => '',
); ];
$profileData = array( $profileData = [
'profile1' => array('ServerURL' => 'myserver'), 'profile1' => ['ServerURL' => 'myserver'],
'profile2' => array('ServerURL' => 'myserver2'), 'profile2' => ['ServerURL' => 'myserver2'],
); ];
$accountProfileData = array( $accountProfileData = [
'profile1' => array('user' => array('default' => array('key' => 'value'))), 'profile1' => ['user' => ['default' => ['key' => 'value']]],
'profile2' => array( 'profile2' => ['user' => ['default' => ['key' => 'value']], 'group' => ['default' => ['key' => 'value']]],
'user' => array('default' => array('key' => 'value')), ];
'group' => array('default' => array('key' => 'value')), $accountProfileTemplateData = [
), 'user' => ['default' => ['key' => 'value']],
); 'group' => ['default' => ['key' => 'value']],
$accountProfileTemplateData = array( ];
'user' => array('default' => array('key' => 'value')), $pdfData = [
'group' => array('default' => array('key' => 'value')), 'profile1' => [
); 'structures' => [
$pdfData = array( 'user' => [
'profile1' => array('structures' => array( 'default' => ['key' => 'value']
'user' => array( ]
'default' => array('key' => 'value')) ]
)), ],
'profile2' => array('structures' => array( 'profile2' => [
'user' => array('default' => array('key' => 'value')), 'structures' => [
'group' => array('default' => array('key' => 'value')), 'user' => ['default' => ['key' => 'value']],
)), 'group' => ['default' => ['key' => 'value']],
); ]
$pdfTemplateData = array( ],
'user' => array('default' => array('key' => 'value')), ];
'group' => array('default' => array('key' => 'value')), $pdfTemplateData = [
); 'user' => ['default' => ['key' => 'value']],
$selfServiceData = array( 'group' => ['default' => ['key' => 'value']],
'profile1' => array('key' => 'value'), ];
'profile2' => array('key' => 'value'), $selfServiceData = [
); 'profile1' => ['key' => 'value'],
$webauthn = array(); 'profile2' => ['key' => 'value'],
$expectedJson = json_encode(array( ];
$webauthn = [];
$expectedJson = json_encode([
'mainConfig' => $mainData, 'mainConfig' => $mainData,
'certificates' => 'certs', 'certificates' => 'certs',
'serverProfiles' => $profileData, 'serverProfiles' => $profileData,
@ -81,14 +83,14 @@ class ConfigDataExporterTest extends TestCase {
'pdfProfileTemplates' => $pdfTemplateData, 'pdfProfileTemplates' => $pdfTemplateData,
'selfServiceProfiles' => $selfServiceData, 'selfServiceProfiles' => $selfServiceData,
'webauthn' => $webauthn, 'webauthn' => $webauthn,
'cronJobs' => array() 'cronJobs' => []
)); ]);
$exporter = $this->getMockBuilder('\LAM\PERSISTENCE\ConfigDataExporter') $exporter = $this->getMockBuilder('\LAM\PERSISTENCE\ConfigDataExporter')
->setMethods(array('_getMainConfigData', '_getCertificates', '_getServerProfiles', ->setMethods(['_getMainConfigData', '_getCertificates', '_getServerProfiles',
'_getAccountProfiles', '_getAccountProfileTemplates', '_getPdfProfiles', '_getAccountProfiles', '_getAccountProfileTemplates', '_getPdfProfiles',
'_getPdfProfileTemplates', '_getSelfServiceProfiles', '_getWebauthn', '_getPdfProfileTemplates', '_getSelfServiceProfiles', '_getWebauthn',
'_getCronJobData')) '_getCronJobData'])
->getMock(); ->getMock();
$exporter->method('_getMainConfigData')->willReturn($mainData); $exporter->method('_getMainConfigData')->willReturn($mainData);
$exporter->method('_getCertificates')->willReturn('certs'); $exporter->method('_getCertificates')->willReturn('certs');
@ -99,7 +101,7 @@ class ConfigDataExporterTest extends TestCase {
$exporter->method('_getPdfProfileTemplates')->willReturn($pdfTemplateData); $exporter->method('_getPdfProfileTemplates')->willReturn($pdfTemplateData);
$exporter->method('_getSelfServiceProfiles')->willReturn($selfServiceData); $exporter->method('_getSelfServiceProfiles')->willReturn($selfServiceData);
$exporter->method('_getWebauthn')->willReturn($webauthn); $exporter->method('_getWebauthn')->willReturn($webauthn);
$exporter->method('_getCronJobData')->willReturn(array()); $exporter->method('_getCronJobData')->willReturn([]);
$json = $exporter->exportAsJson(); $json = $exporter->exportAsJson();

View file

@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2018 - 2021 Roland Gruber Copyright (C) 2018 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -42,11 +42,11 @@ class ImporterTest extends TestCase {
* No LDIF at all. * No LDIF at all.
*/ */
public function testCompletelyInvalid() { public function testCompletelyInvalid() {
$lines = array( $lines = [
"this is no LDIF" "this is no LDIF"
); ];
$this->expectException(LAMException::class, 'this is no LDIF'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -56,11 +56,11 @@ class ImporterTest extends TestCase {
* Wrong format version. * Wrong format version.
*/ */
public function testWrongVersion() { public function testWrongVersion() {
$lines = array( $lines = [
"version: 3" "version: 3"
); ];
$this->expectException(LAMException::class, 'version: 3'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -70,11 +70,11 @@ class ImporterTest extends TestCase {
* Multiple versions. * Multiple versions.
*/ */
public function testMultipleVersions() { public function testMultipleVersions() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"version: 1" "version: 1"
); ];
$this->expectException(LAMException::class); $this->expectException(LAMException::class);
@ -86,10 +86,10 @@ class ImporterTest extends TestCase {
* Data after version. * Data after version.
*/ */
public function testDataAfterVersion() { public function testDataAfterVersion() {
$lines = array( $lines = [
"version: 1", "version: 1",
"some: data" "some: data"
); ];
$this->expectException(LAMException::class); $this->expectException(LAMException::class);
@ -101,13 +101,13 @@ class ImporterTest extends TestCase {
* DN line without any data. * DN line without any data.
*/ */
public function testDnNoData() { public function testDnNoData() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com" "dn: uid=test,dc=example,dc=com"
); ];
$this->expectException(LAMException::class, 'dn: uid=test,dc=example,dc=com'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -117,13 +117,13 @@ class ImporterTest extends TestCase {
* One complete entry. * One complete entry.
*/ */
public function testSingleFullEntry() { public function testSingleFullEntry() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"objectClass: inetOrgPerson", "objectClass: inetOrgPerson",
"uid: test", "uid: test",
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
@ -134,15 +134,15 @@ class ImporterTest extends TestCase {
* Change entry with invalid changetype. * Change entry with invalid changetype.
*/ */
public function testChangeInvalidType() { public function testChangeInvalidType() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: invalid", "changetype: invalid",
"uid: test", "uid: test",
); ];
$this->expectException(LAMException::class, 'uid=test,dc=example,dc=com - changetype: invalid'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -152,34 +152,34 @@ class ImporterTest extends TestCase {
* Change entry with add changetype. * Change entry with add changetype.
*/ */
public function testChangeAdd() { public function testChangeAdd() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: add", "changetype: add",
"uid: test", "uid: test",
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(AddEntryTask::class, get_class($task)); $this->assertEquals(AddEntryTask::class, $task::class);
} }
/** /**
* Change entry with modrdn changetype and invalid options. * Change entry with modrdn changetype and invalid options.
*/ */
public function testChangeModRdnInvalidData() { public function testChangeModRdnInvalidData() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: modrdn", "changetype: modrdn",
"uid: test", "uid: test",
); ];
$this->expectException(LAMException::class, 'uid=test,dc=example,dc=com'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -189,16 +189,16 @@ class ImporterTest extends TestCase {
* Change entry with modrdn changetype and invalid deleteoldrdn. * Change entry with modrdn changetype and invalid deleteoldrdn.
*/ */
public function testChangeModRdnInvalidDeleteoldrdn() { public function testChangeModRdnInvalidDeleteoldrdn() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: modrdn", "changetype: modrdn",
"newrdn: uid1=test", "newrdn: uid1=test",
"deleteoldrdn: x", "deleteoldrdn: x",
); ];
$this->expectException(LAMException::class, 'uid=test,dc=example,dc=com'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -208,35 +208,35 @@ class ImporterTest extends TestCase {
* Change entry with modrdn changetype. * Change entry with modrdn changetype.
*/ */
public function testChangeModRdn() { public function testChangeModRdn() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: modrdn", "changetype: modrdn",
"newrdn: uid1=test", "newrdn: uid1=test",
"deleteoldrdn: 0", "deleteoldrdn: 0",
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(RenameEntryTask::class, get_class($task)); $this->assertEquals(RenameEntryTask::class, $task::class);
} }
/** /**
* Change entry with delete changetype with extra line. * Change entry with delete changetype with extra line.
*/ */
public function testChangeDeleteInvalid() { public function testChangeDeleteInvalid() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: delete", "changetype: delete",
"uid: test", "uid: test",
); ];
$this->expectException(LAMException::class, 'uid=test,dc=example,dc=com'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -246,33 +246,33 @@ class ImporterTest extends TestCase {
* Change entry with delete changetype. * Change entry with delete changetype.
*/ */
public function testChangeDelete() { public function testChangeDelete() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: delete", "changetype: delete",
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(DeleteEntryTask::class, get_class($task)); $this->assertEquals(DeleteEntryTask::class, $task::class);
} }
/** /**
* Change entry with modify changetype with invalid operation. * Change entry with modify changetype with invalid operation.
*/ */
public function testChangeModifyInvalid() { public function testChangeModifyInvalid() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: modify", "changetype: modify",
"invalid: test", "invalid: test",
); ];
$this->expectException(LAMException::class, 'uid=test,dc=example,dc=com'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -282,7 +282,7 @@ class ImporterTest extends TestCase {
* Change entry with modify changetype and add operation. * Change entry with modify changetype and add operation.
*/ */
public function testChangeModifyAddInvalid() { public function testChangeModifyAddInvalid() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
@ -290,9 +290,9 @@ class ImporterTest extends TestCase {
"add: uid", "add: uid",
"uid: uid1", "uid: uid1",
"invalid: uid2" "invalid: uid2"
); ];
$this->expectException(LAMException::class, 'uid=test,dc=example,dc=com'); $this->expectException(LAMException::class);
$importer = new Importer(); $importer = new Importer();
$importer->getTasks($lines); $importer->getTasks($lines);
@ -302,7 +302,7 @@ class ImporterTest extends TestCase {
* Change entry with modify changetype and add operation. * Change entry with modify changetype and add operation.
*/ */
public function testChangeModifyAdd() { public function testChangeModifyAdd() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
@ -310,17 +310,17 @@ class ImporterTest extends TestCase {
"add: uid", "add: uid",
"uid: uid1", "uid: uid1",
"uid: uid2" "uid: uid2"
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(MultiTask::class, get_class($task)); $this->assertEquals(MultiTask::class, $task::class);
$subtasks = $task->getTasks(); $subtasks = $task->getTasks();
$this->assertEquals(1, sizeof($subtasks)); $this->assertEquals(1, sizeof($subtasks));
$subTask = $subtasks[0]; $subTask = $subtasks[0];
$this->assertEquals(AddAttributesTask::class, get_class($subTask)); $this->assertEquals(AddAttributesTask::class, $subTask::class);
$this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com'); $this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com');
$attributes = $subTask->getAttributes(); $attributes = $subTask->getAttributes();
$this->assertEquals(1, sizeof($attributes)); $this->assertEquals(1, sizeof($attributes));
@ -333,7 +333,7 @@ class ImporterTest extends TestCase {
* Change entry with modify changetype and two add operations. * Change entry with modify changetype and two add operations.
*/ */
public function testChangeModifyAddTwice() { public function testChangeModifyAddTwice() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
@ -345,17 +345,17 @@ class ImporterTest extends TestCase {
"add: gn", "add: gn",
"gn: name1", "gn: name1",
"gn: name2" "gn: name2"
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(MultiTask::class, get_class($task)); $this->assertEquals(MultiTask::class, $task::class);
$subtasks = $task->getTasks(); $subtasks = $task->getTasks();
$this->assertEquals(2, sizeof($subtasks)); $this->assertEquals(2, sizeof($subtasks));
$subTask = $subtasks[0]; $subTask = $subtasks[0];
$this->assertEquals(AddAttributesTask::class, get_class($subTask)); $this->assertEquals(AddAttributesTask::class, $subTask::class);
$this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com'); $this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com');
$attributes = $subTask->getAttributes(); $attributes = $subTask->getAttributes();
$this->assertEquals(1, sizeof($attributes)); $this->assertEquals(1, sizeof($attributes));
@ -363,7 +363,7 @@ class ImporterTest extends TestCase {
$this->assertTrue(in_array('uid1', $attributes['uid'])); $this->assertTrue(in_array('uid1', $attributes['uid']));
$this->assertTrue(in_array('uid2', $attributes['uid'])); $this->assertTrue(in_array('uid2', $attributes['uid']));
$subTask = $subtasks[1]; $subTask = $subtasks[1];
$this->assertEquals(AddAttributesTask::class, get_class($subTask)); $this->assertEquals(AddAttributesTask::class, $subTask::class);
$this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com'); $this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com');
$attributes = $subTask->getAttributes(); $attributes = $subTask->getAttributes();
$this->assertEquals(1, sizeof($attributes)); $this->assertEquals(1, sizeof($attributes));
@ -376,7 +376,7 @@ class ImporterTest extends TestCase {
* Change entry with modify changetype and delete operation. * Change entry with modify changetype and delete operation.
*/ */
public function testChangeModifyDelete() { public function testChangeModifyDelete() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
@ -384,17 +384,17 @@ class ImporterTest extends TestCase {
"delete: uid", "delete: uid",
"uid: uid1", "uid: uid1",
"uid: uid2" "uid: uid2"
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(MultiTask::class, get_class($task)); $this->assertEquals(MultiTask::class, $task::class);
$subtasks = $task->getTasks(); $subtasks = $task->getTasks();
$this->assertEquals(1, sizeof($subtasks)); $this->assertEquals(1, sizeof($subtasks));
$subTask = $subtasks[0]; $subTask = $subtasks[0];
$this->assertEquals(DeleteAttributesTask::class, get_class($subTask)); $this->assertEquals(DeleteAttributesTask::class, $subTask::class);
$this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com'); $this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com');
$attributes = $subTask->getAttributes(); $attributes = $subTask->getAttributes();
$this->assertEquals(1, sizeof($attributes)); $this->assertEquals(1, sizeof($attributes));
@ -407,23 +407,23 @@ class ImporterTest extends TestCase {
* Change entry with modify changetype and delete operation. * Change entry with modify changetype and delete operation.
*/ */
public function testChangeModifyDeleteAll() { public function testChangeModifyDeleteAll() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
"changetype: modify", "changetype: modify",
"delete: uid", "delete: uid",
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(MultiTask::class, get_class($task)); $this->assertEquals(MultiTask::class, $task::class);
$subtasks = $task->getTasks(); $subtasks = $task->getTasks();
$this->assertEquals(1, sizeof($subtasks)); $this->assertEquals(1, sizeof($subtasks));
$subTask = $subtasks[0]; $subTask = $subtasks[0];
$this->assertEquals(DeleteAttributesTask::class, get_class($subTask)); $this->assertEquals(DeleteAttributesTask::class, $subTask::class);
$this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com'); $this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com');
$attributes = $subTask->getAttributes(); $attributes = $subTask->getAttributes();
$this->assertTrue(empty($attributes)); $this->assertTrue(empty($attributes));
@ -433,7 +433,7 @@ class ImporterTest extends TestCase {
* Change entry with modify changetype and replace operation. * Change entry with modify changetype and replace operation.
*/ */
public function testChangeModifyReplace() { public function testChangeModifyReplace() {
$lines = array( $lines = [
"version: 1", "version: 1",
"", "",
"dn: uid=test,dc=example,dc=com", "dn: uid=test,dc=example,dc=com",
@ -441,17 +441,17 @@ class ImporterTest extends TestCase {
"replace: uid", "replace: uid",
"uid: uid1", "uid: uid1",
"uid: uid2", "uid: uid2",
); ];
$importer = new Importer(); $importer = new Importer();
$tasks = $importer->getTasks($lines); $tasks = $importer->getTasks($lines);
$this->assertEquals(1, sizeof($tasks)); $this->assertEquals(1, sizeof($tasks));
$task = $tasks[0]; $task = $tasks[0];
$this->assertEquals(MultiTask::class, get_class($task)); $this->assertEquals(MultiTask::class, $task::class);
$subtasks = $task->getTasks(); $subtasks = $task->getTasks();
$this->assertEquals(1, sizeof($subtasks)); $this->assertEquals(1, sizeof($subtasks));
$subTask = $subtasks[0]; $subTask = $subtasks[0];
$this->assertEquals(ReplaceAttributesTask::class, get_class($subTask)); $this->assertEquals(ReplaceAttributesTask::class, $subTask::class);
$this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com'); $this->assertEquals($subTask->getDn(), 'uid=test,dc=example,dc=com');
$attributes = $subTask->getAttributes(); $attributes = $subTask->getAttributes();
$this->assertEquals(1, sizeof($attributes)); $this->assertEquals(1, sizeof($attributes));

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 - 2021 Roland Gruber Copyright (C) 2020 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -31,7 +31,7 @@ include_once __DIR__ . '/../../lib/config.inc';
class LAMCfgMainTest extends TestCase { class LAMCfgMainTest extends TestCase {
private $conf; private $conf;
private $file; private string $file;
/** /**
* Prepares the environment before running a test. * Prepares the environment before running a test.
@ -82,7 +82,7 @@ class LAMCfgMainTest extends TestCase {
$this->conf->licenseEmailTo = 'TO'; $this->conf->licenseEmailTo = 'TO';
$this->conf->licenseEmailFrom = 'FROM'; $this->conf->licenseEmailFrom = 'FROM';
$this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL; $this->conf->licenseWarningType = LAMCfgMain::LICENSE_WARNING_ALL;
$this->conf->setLicenseLines(array('123', '456')); $this->conf->setLicenseLines(['123', '456']);
$this->conf->licenseEmailDateSent = $timestamp; $this->conf->licenseEmailDateSent = $timestamp;
$this->conf->save(); $this->conf->save();
@ -93,7 +93,7 @@ class LAMCfgMainTest extends TestCase {
$this->assertEquals($timestamp, $this->conf->licenseEmailDateSent); $this->assertEquals($timestamp, $this->conf->licenseEmailDateSent);
$this->assertTrue($this->conf->wasLicenseWarningSent($timestamp)); $this->assertTrue($this->conf->wasLicenseWarningSent($timestamp));
$this->assertEquals(LAMCfgMain::LICENSE_WARNING_ALL, $this->conf->licenseWarningType); $this->assertEquals(LAMCfgMain::LICENSE_WARNING_ALL, $this->conf->licenseWarningType);
$this->assertEquals(array('123', '456'), $this->conf->getLicenseLines()); $this->assertEquals(['123', '456'], $this->conf->getLicenseLines());
} }
/** /**
@ -142,7 +142,7 @@ class LAMCfgMainTest extends TestCase {
* Tests the import. * Tests the import.
*/ */
public function testImportData() { public function testImportData() {
$importData = array(); $importData = [];
$importData['passwordMinLower'] = 3; $importData['passwordMinLower'] = 3;
$importData['sessionTimeout'] = 240; $importData['sessionTimeout'] = 240;
$importData['logLevel'] = LOG_ERR; $importData['logLevel'] = LOG_ERR;
@ -163,7 +163,7 @@ class LAMCfgMainTest extends TestCase {
* Tests the import with invalid data. * Tests the import with invalid data.
*/ */
public function testImportData_invalid() { public function testImportData_invalid() {
$importData = array(); $importData = [];
$importData['passwordMinLower'] = 3; $importData['passwordMinLower'] = 3;
$importData['sessionTimeout'] = 240; $importData['sessionTimeout'] = 240;
$importData['logLevel'] = LOG_ERR; $importData['logLevel'] = LOG_ERR;

View file

@ -30,7 +30,7 @@ include_once __DIR__ . '/../utils/configuration.inc';
*/ */
class LAMConfigTest extends TestCase { class LAMConfigTest extends TestCase {
const FILE_NAME = 'd_lam_config_test'; public const FILE_NAME = 'd_lam_config_test';
/** /**
* *
@ -195,9 +195,9 @@ class LAMConfigTest extends TestCase {
$valInvalid = 'admin;'; $valInvalid = 'admin;';
$this->assertFalse($this->lAMConfig->set_Adminstring($valInvalid)); $this->assertFalse($this->lAMConfig->set_Adminstring($valInvalid));
$this->lAMConfig->set_Adminstring($val); $this->lAMConfig->set_Adminstring($val);
$this->assertEquals(array('cn=admin,dc=test', 'cn=admin2,dc=test'), $this->lAMConfig->get_Admins()); $this->assertEquals(['cn=admin,dc=test', 'cn=admin2,dc=test'], $this->lAMConfig->get_Admins());
$this->doSave(); $this->doSave();
$this->assertEquals(array('cn=admin,dc=test', 'cn=admin2,dc=test'), $this->lAMConfig->get_Admins()); $this->assertEquals(['cn=admin,dc=test', 'cn=admin2,dc=test'], $this->lAMConfig->get_Admins());
} }
/** /**
@ -384,7 +384,7 @@ class LAMConfigTest extends TestCase {
public function testAccountModules() { public function testAccountModules() {
$scope = 'user'; $scope = 'user';
$this->assertFalse($this->lAMConfig->set_AccountModules('abc', $scope)); $this->assertFalse($this->lAMConfig->set_AccountModules('abc', $scope));
$val = array('posixAccount', 'shadowAccount'); $val = ['posixAccount', 'shadowAccount'];
$this->lAMConfig->set_AccountModules($val, $scope); $this->lAMConfig->set_AccountModules($val, $scope);
$this->assertEquals($val, $this->lAMConfig->get_AccountModules($scope)); $this->assertEquals($val, $this->lAMConfig->get_AccountModules($scope));
$this->doSave(); $this->doSave();
@ -396,7 +396,7 @@ class LAMConfigTest extends TestCase {
*/ */
public function testmoduleSettings() { public function testmoduleSettings() {
$this->assertFalse($this->lAMConfig->set_moduleSettings('abc')); $this->assertFalse($this->lAMConfig->set_moduleSettings('abc'));
$val = array('posixAccount_123' => array('123'), 'shadowAccount_123' => array('123')); $val = ['posixAccount_123' => ['123'], 'shadowAccount_123' => ['123']];
$this->lAMConfig->set_moduleSettings($val); $this->lAMConfig->set_moduleSettings($val);
$this->assertTrue(array_key_exists('posixAccount_123', $this->lAMConfig->get_moduleSettings())); $this->assertTrue(array_key_exists('posixAccount_123', $this->lAMConfig->get_moduleSettings()));
$this->assertTrue(array_key_exists('shadowAccount_123', $this->lAMConfig->get_moduleSettings())); $this->assertTrue(array_key_exists('shadowAccount_123', $this->lAMConfig->get_moduleSettings()));
@ -409,7 +409,7 @@ class LAMConfigTest extends TestCase {
* Tests LAMConfig->get_ActiveTypes() and LAMConfig->set_ActiveTypes() * Tests LAMConfig->get_ActiveTypes() and LAMConfig->set_ActiveTypes()
*/ */
public function testActiveTypes() { public function testActiveTypes() {
$val = array('user', 'group'); $val = ['user', 'group'];
$this->lAMConfig->set_ActiveTypes($val); $this->lAMConfig->set_ActiveTypes($val);
$this->assertEquals($val, $this->lAMConfig->get_ActiveTypes()); $this->assertEquals($val, $this->lAMConfig->get_ActiveTypes());
$this->doSave(); $this->doSave();
@ -421,7 +421,7 @@ class LAMConfigTest extends TestCase {
*/ */
public function testtypeSettings() { public function testtypeSettings() {
$this->assertFalse($this->lAMConfig->set_typeSettings('abc')); $this->assertFalse($this->lAMConfig->set_typeSettings('abc'));
$val = array('posixAccount_123' => '123', 'shadowAccount_123' => '123'); $val = ['posixAccount_123' => '123', 'shadowAccount_123' => '123'];
$this->lAMConfig->set_typeSettings($val); $this->lAMConfig->set_typeSettings($val);
$this->assertTrue(array_key_exists('posixAccount_123', $this->lAMConfig->get_typeSettings())); $this->assertTrue(array_key_exists('posixAccount_123', $this->lAMConfig->get_typeSettings()));
$this->assertTrue(array_key_exists('shadowAccount_123', $this->lAMConfig->get_typeSettings())); $this->assertTrue(array_key_exists('shadowAccount_123', $this->lAMConfig->get_typeSettings()));
@ -435,7 +435,7 @@ class LAMConfigTest extends TestCase {
*/ */
public function testGetToolSettings() { public function testGetToolSettings() {
$this->assertFalse($this->lAMConfig->setToolSettings('abc')); $this->assertFalse($this->lAMConfig->setToolSettings('abc'));
$val = array('user_123' => '123', 'group_123' => '123'); $val = ['user_123' => '123', 'group_123' => '123'];
$this->lAMConfig->setToolSettings($val); $this->lAMConfig->setToolSettings($val);
$this->assertTrue(array_key_exists('user_123', $this->lAMConfig->getToolSettings())); $this->assertTrue(array_key_exists('user_123', $this->lAMConfig->getToolSettings()));
$this->assertTrue(array_key_exists('group_123', $this->lAMConfig->getToolSettings())); $this->assertTrue(array_key_exists('group_123', $this->lAMConfig->getToolSettings()));
@ -448,10 +448,10 @@ class LAMConfigTest extends TestCase {
* Checks isToolActive(). * Checks isToolActive().
*/ */
public function testIsToolActive() { public function testIsToolActive() {
$this->lAMConfig->setToolSettings(array( $this->lAMConfig->setToolSettings([
'tool_hide_tool1' => 'true', 'tool_hide_tool1' => 'true',
'tool_hide_tool2' => 'false', 'tool_hide_tool2' => 'false',
)); ]);
$this->assertFalse($this->lAMConfig->isToolActive('tool1')); $this->assertFalse($this->lAMConfig->isToolActive('tool1'));
$this->assertTrue($this->lAMConfig->isToolActive('tool2')); $this->assertTrue($this->lAMConfig->isToolActive('tool2'));
$this->assertTrue($this->lAMConfig->isToolActive('tool3')); $this->assertTrue($this->lAMConfig->isToolActive('tool3'));
@ -857,7 +857,7 @@ class LAMConfigTest extends TestCase {
* Tests LAMConfig->setJobSettings() and LAMConfig->getJobSettings() * Tests LAMConfig->setJobSettings() and LAMConfig->getJobSettings()
*/ */
public function testJobSettings() { public function testJobSettings() {
$val = array('setting' => array('123')); $val = ['setting' => ['123']];
$this->lAMConfig->setJobSettings($val); $this->lAMConfig->setJobSettings($val);
$this->assertEquals($val, $this->lAMConfig->getJobSettings()); $this->assertEquals($val, $this->lAMConfig->getJobSettings());
$this->doSave(); $this->doSave();
@ -948,51 +948,51 @@ class LAMConfigTest extends TestCase {
public function testExportData() { public function testExportData() {
$this->lAMConfig->set_defaultLanguage('lang'); $this->lAMConfig->set_defaultLanguage('lang');
$this->lAMConfig->set_ServerURL('myserver'); $this->lAMConfig->set_ServerURL('myserver');
$this->lAMConfig->set_typeSettings(array('typetest' => '1')); $this->lAMConfig->set_typeSettings(['typetest' => '1']);
$this->lAMConfig->set_moduleSettings(array('modtest' => '1')); $this->lAMConfig->set_moduleSettings(['modtest' => '1']);
$this->lAMConfig->setToolSettings(array('tooltest' => '1')); $this->lAMConfig->setToolSettings(['tooltest' => '1']);
$this->lAMConfig->setJobSettings(array('jobtest' => '1')); $this->lAMConfig->setJobSettings(['jobtest' => '1']);
$data = $this->lAMConfig->exportData(); $data = $this->lAMConfig->exportData();
$this->assertEquals('lang', $data['defaultLanguage']); $this->assertEquals('lang', $data['defaultLanguage']);
$this->assertEquals('myserver', $data['ServerURL']); $this->assertEquals('myserver', $data['ServerURL']);
$this->assertEquals(array('typetest' => '1'), $data['typeSettings']); $this->assertEquals(['typetest' => '1'], $data['typeSettings']);
$this->assertEquals(array('modtest' => '1'), $data['moduleSettings']); $this->assertEquals(['modtest' => '1'], $data['moduleSettings']);
$this->assertEquals(array('tooltest' => '1'), $data['toolSettings']); $this->assertEquals(['tooltest' => '1'], $data['toolSettings']);
$this->assertEquals(array('jobtest' => '1'), $data['jobSettings']); $this->assertEquals(['jobtest' => '1'], $data['jobSettings']);
} }
/** /**
* Tests the import. * Tests the import.
*/ */
public function testImportData() { public function testImportData() {
$importData = array(); $importData = [];
$importData['ServerURL'] = 'testserver'; $importData['ServerURL'] = 'testserver';
$importData['defaultLanguage'] = 'de_DE.utf8'; $importData['defaultLanguage'] = 'de_DE.utf8';
$importData['typeSettings'] = array('typetest' => 'value'); $importData['typeSettings'] = ['typetest' => 'value'];
$importData['toolSettings'] = array('tooltest' => 'value'); $importData['toolSettings'] = ['tooltest' => 'value'];
$importData['moduleSettings'] = array('modtest' => 'value'); $importData['moduleSettings'] = ['modtest' => 'value'];
$importData['jobSettings'] = array('jobtest' => 'value'); $importData['jobSettings'] = ['jobtest' => 'value'];
$importData['IGNORE_ME'] = 'ignore'; $importData['IGNORE_ME'] = 'ignore';
$this->lAMConfig->importData($importData); $this->lAMConfig->importData($importData);
$this->assertEquals('testserver', $this->lAMConfig->get_ServerURL()); $this->assertEquals('testserver', $this->lAMConfig->get_ServerURL());
$this->assertEquals('de_DE.utf8', $this->lAMConfig->get_defaultLanguage()); $this->assertEquals('de_DE.utf8', $this->lAMConfig->get_defaultLanguage());
$this->assertEquals(array('typetest' => 'value'), $this->lAMConfig->get_typeSettings()); $this->assertEquals(['typetest' => 'value'], $this->lAMConfig->get_typeSettings());
$this->assertEquals(array('tooltest' => 'value'), $this->lAMConfig->getToolSettings()); $this->assertEquals(['tooltest' => 'value'], $this->lAMConfig->getToolSettings());
$this->assertEquals(array('modtest' => 'value'), $this->lAMConfig->get_moduleSettings()); $this->assertEquals(['modtest' => 'value'], $this->lAMConfig->get_moduleSettings());
$this->assertEquals(array('jobtest' => 'value'), $this->lAMConfig->getJobSettings()); $this->assertEquals(['jobtest' => 'value'], $this->lAMConfig->getJobSettings());
} }
/** /**
* Tests the import with invalid data. * Tests the import with invalid data.
*/ */
public function testImportData_invalid() { public function testImportData_invalid() {
$importData = array(); $importData = [];
$importData['ServerURL'] = 'testserver'; $importData['ServerURL'] = 'testserver';
$importData['typeSettings'] = array('typetest' => 'value'); $importData['typeSettings'] = ['typetest' => 'value'];
$importData['defaultLanguage'] = new LAMLanguage('de_de', 'UTF-8', 'DE'); $importData['defaultLanguage'] = new LAMLanguage('de_de', 'UTF-8', 'DE');
$this->expectException(LAMException::class); $this->expectException(LAMException::class);

View file

@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2017 - 2021 Roland Gruber Copyright (C) 2017 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -41,7 +41,7 @@ class PdfStructTest extends TestCase {
public function testRead() { public function testRead() {
$file = $this->getTestFileName('test.xml'); $file = $this->getTestFileName('test.xml');
$fileHandle = fopen($file, "r"); $fileHandle = fopen($file, "r");
$originalXML = fread($fileHandle, 1000000); $originalXML = fread($fileHandle, 1_000_000);
fclose($fileHandle); fclose($fileHandle);
$reader = new PDFStructureReader(); $reader = new PDFStructureReader();
$structure = $reader->read($originalXML); $structure = $reader->read($originalXML);
@ -86,7 +86,7 @@ class PdfStructTest extends TestCase {
* @return string file name * @return string file name
*/ */
private function getTestFileName($file): string { private function getTestFileName($file): string {
return dirname(dirname(__FILE__)) . '/resources/pdf/' . $file; return dirname(__DIR__) . '/resources/pdf/' . $file;
} }
/** /**
@ -97,7 +97,7 @@ class PdfStructTest extends TestCase {
$file = $this->getTestFileName('writer.xml'); $file = $this->getTestFileName('writer.xml');
// read input XML // read input XML
$fileHandle = fopen($file, "r"); $fileHandle = fopen($file, "r");
$originalXML = fread($fileHandle, 1000000); $originalXML = fread($fileHandle, 1_000_000);
fclose($fileHandle); fclose($fileHandle);
// read structure // read structure
$reader = new PDFStructureReader(); $reader = new PDFStructureReader();
@ -125,14 +125,14 @@ class PdfStructTest extends TestCase {
*/ */
public function testExportPDFEntrySection() { public function testExportPDFEntrySection() {
$section = new PDFEntrySection('mytitle'); $section = new PDFEntrySection('mytitle');
$section->setEntries(array(new PDFSectionEntry('key1'), new PDFSectionEntry('key2'))); $section->setEntries([new PDFSectionEntry('key1'), new PDFSectionEntry('key2')]);
$data = $section->export(); $data = $section->export();
$expected = array( $expected = [
'title' => 'mytitle', 'title' => 'mytitle',
'entries' => array('key1', 'key2') 'entries' => ['key1', 'key2']
); ];
$this->assertEquals($expected, $data); $this->assertEquals($expected, $data);
} }
@ -146,32 +146,32 @@ class PdfStructTest extends TestCase {
$structure->setLogo('somelogo'); $structure->setLogo('somelogo');
$structure->setTitle('mytitle'); $structure->setTitle('mytitle');
$entrySection = new PDFEntrySection('sometitle'); $entrySection = new PDFEntrySection('sometitle');
$entrySection->setEntries(array(new PDFSectionEntry('key1'))); $entrySection->setEntries([new PDFSectionEntry('key1')]);
$structure->setSections(array( $structure->setSections([
new PDFTextSection('sometext'), new PDFTextSection('sometext'),
$entrySection $entrySection
)); ]);
$data = $structure->export(); $data = $structure->export();
$expected = array( $expected = [
'title' => 'mytitle', 'title' => 'mytitle',
'foldingMarks' => PDFStructure::FOLDING_STANDARD, 'foldingMarks' => PDFStructure::FOLDING_STANDARD,
'logo' => 'somelogo', 'logo' => 'somelogo',
'sections' => array( 'sections' => [
array( [
'type' => 'text', 'type' => 'text',
'data' => 'sometext' 'data' => 'sometext'
), ],
array( [
'type' => 'entry', 'type' => 'entry',
'data' => array( 'data' => [
'title' => 'sometitle', 'title' => 'sometitle',
'entries' => array('key1') 'entries' => ['key1']
) ]
) ]
) ]
); ];
$this->assertEquals($expected, $data); $this->assertEquals($expected, $data);
} }
@ -180,10 +180,10 @@ class PdfStructTest extends TestCase {
* Tests import in PDFEntrySection. * Tests import in PDFEntrySection.
*/ */
public function testImportPDFEntrySection() { public function testImportPDFEntrySection() {
$data = array( $data = [
'title' => 'mytitle', 'title' => 'mytitle',
'entries' => array('e1', 'e2') 'entries' => ['e1', 'e2']
); ];
$section = new PDFEntrySection(null); $section = new PDFEntrySection(null);
$section->import($data); $section->import($data);
@ -199,24 +199,24 @@ class PdfStructTest extends TestCase {
* Tests the import in PDFStructure. * Tests the import in PDFStructure.
*/ */
public function testImportPDFStructure() { public function testImportPDFStructure() {
$data = array( $data = [
'title' => 'mytitle', 'title' => 'mytitle',
'foldingMarks' => PDFStructure::FOLDING_STANDARD, 'foldingMarks' => PDFStructure::FOLDING_STANDARD,
'logo' => 'logo', 'logo' => 'logo',
'sections' => array( 'sections' => [
array( [
'type' => 'text', 'type' => 'text',
'data' => 'textvalue' 'data' => 'textvalue'
), ],
array( [
'type' => 'entry', 'type' => 'entry',
'data' => array( 'data' => [
'title' => 'etitle', 'title' => 'etitle',
'entries' => array('e1', 'e2') 'entries' => ['e1', 'e2']
) ]
), ],
) ]
); ];
$structure = new PDFStructure(); $structure = new PDFStructure();
$structure->import($data); $structure->import($data);

View file

@ -11,7 +11,7 @@ use \Webauthn\TrustPath\CertificateTrustPath;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2019 - 2021 Roland Gruber Copyright (C) 2019 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -40,9 +40,9 @@ require_once __DIR__ . '/../../lib/webauthn.inc';
class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase { class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLite * @var PublicKeyCredentialSourceRepositorySQLite
*/ */
private $database; private PublicKeyCredentialSourceRepositorySQLiteTestDb $database;
protected function setUp(): void { protected function setUp(): void {
$this->database = new PublicKeyCredentialSourceRepositorySQLiteTestDb(); $this->database = new PublicKeyCredentialSourceRepositorySQLiteTestDb();
@ -73,9 +73,9 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
$source1 = new PublicKeyCredentialSource( $source1 = new PublicKeyCredentialSource(
"id1", "id1",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p1", "p1",
"uh1", "uh1",
@ -84,9 +84,9 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
$source2 = new PublicKeyCredentialSource( $source2 = new PublicKeyCredentialSource(
"id2", "id2",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p2", "p2",
"uh1", "uh1",
@ -95,9 +95,9 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
$source3 = new PublicKeyCredentialSource( $source3 = new PublicKeyCredentialSource(
"id3", "id3",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p3", "p3",
"uh2", "uh2",
@ -120,9 +120,9 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
$source1 = new PublicKeyCredentialSource( $source1 = new PublicKeyCredentialSource(
"id1", "id1",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p1", "p1",
"uh1", "uh1",
@ -135,9 +135,9 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
$source1 = new PublicKeyCredentialSource( $source1 = new PublicKeyCredentialSource(
"id1", "id1",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p1", "p1",
"uh1", "uh1",
@ -152,9 +152,9 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
$source1 = new PublicKeyCredentialSource( $source1 = new PublicKeyCredentialSource(
"id1", "id1",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p1", "p1",
"uh1", "uh1",
@ -168,12 +168,12 @@ class PublicKeyCredentialSourceRepositorySQLiteTest extends TestCase {
class PublicKeyCredentialSourceRepositorySQLiteTestDb extends PublicKeyCredentialSourceRepositorySQLite { class PublicKeyCredentialSourceRepositorySQLiteTestDb extends PublicKeyCredentialSourceRepositorySQLite {
private $pdo; private PDO $pdo;
public function __construct() { public function __construct() {
$this->pdo = new PDO($this->getPdoUrl(), null, null, array( $this->pdo = new PDO($this->getPdoUrl(), null, null, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
)); ]);
parent::__construct(); parent::__construct();
} }
protected function getPDO(): PDO { protected function getPDO(): PDO {

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2014 - 2016 Roland Gruber Copyright (C) 2014 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -58,52 +58,52 @@ class SecurityTest extends TestCase {
public function testMinLength() { public function testMinLength() {
$this->cfg->passwordMinLength = 5; $this->cfg->passwordMinLength = 5;
$this->checkPwd(array('55555', '666666'), array('1', '22', '333', '4444')); $this->checkPwd(['55555', '666666'], ['1', '22', '333', '4444']);
$this->serverProfile->setPwdPolicyMinLength('7'); $this->serverProfile->setPwdPolicyMinLength('7');
$this->checkPwd(array('7777777'), array('1', '22', '333', '4444', '55555', '666666')); $this->checkPwd(['7777777'], ['1', '22', '333', '4444', '55555', '666666']);
$this->serverProfile->setPwdPolicyMinLength('3'); $this->serverProfile->setPwdPolicyMinLength('3');
$this->checkPwd(array('333', '4444', '55555', '666666', '7777777'), array('1', '22')); $this->checkPwd(['333', '4444', '55555', '666666', '7777777'], ['1', '22']);
} }
public function testMinUpper() { public function testMinUpper() {
$this->cfg->passwordMinUpper = 3; $this->cfg->passwordMinUpper = 3;
$this->checkPwd(array('55A5AA55', '6BB666BB66', 'ABC'), array ('1A', '2C2C', 'AB3', '44BB')); $this->checkPwd(['55A5AA55', '6BB666BB66', 'ABC'], ['1A', '2C2C', 'AB3', '44BB']);
$this->serverProfile->setPwdPolicyMinUppercase('5'); $this->serverProfile->setPwdPolicyMinUppercase('5');
$this->checkPwd(array('5AA5AAA5', '6BBB66BBB6', 'ABCDE'), array ('1A', '2C2C', 'AB3', '44BB')); $this->checkPwd(['5AA5AAA5', '6BBB66BBB6', 'ABCDE'], ['1A', '2C2C', 'AB3', '44BB']);
$this->serverProfile->setPwdPolicyMinUppercase('2'); $this->serverProfile->setPwdPolicyMinUppercase('2');
$this->checkPwd(array('5555A5A5', '6BBB666666', 'AB'), array ('1A', '2C22', 'A33', '444B')); $this->checkPwd(['5555A5A5', '6BBB666666', 'AB'], ['1A', '2C22', 'A33', '444B']);
} }
public function testMinLower() { public function testMinLower() {
$this->cfg->passwordMinLower = 3; $this->cfg->passwordMinLower = 3;
$this->checkPwd(array('55a5aa55', '6bb666bb66', 'abc'), array ('1a', '2c2c', 'ab3', '44bbABC')); $this->checkPwd(['55a5aa55', '6bb666bb66', 'abc'], ['1a', '2c2c', 'ab3', '44bbABC']);
$this->serverProfile->setPwdPolicyMinLowercase('5'); $this->serverProfile->setPwdPolicyMinLowercase('5');
$this->checkPwd(array('5aa5aaa5', '6bbb66bb66', 'abcde'), array ('1abcd', '2c2c', 'ab3', '44bbABC')); $this->checkPwd(['5aa5aaa5', '6bbb66bb66', 'abcde'], ['1abcd', '2c2c', 'ab3', '44bbABC']);
$this->serverProfile->setPwdPolicyMinLowercase('2'); $this->serverProfile->setPwdPolicyMinLowercase('2');
$this->checkPwd(array('5555aa55', '6bb6666b66', 'ab'), array ('1a', '2c23', 'a13', '441bABC')); $this->checkPwd(['5555aa55', '6bb6666b66', 'ab'], ['1a', '2c23', 'a13', '441bABC']);
} }
public function testMinNumeric() { public function testMinNumeric() {
$this->cfg->passwordMinNumeric = 3; $this->cfg->passwordMinNumeric = 3;
$this->checkPwd(array('333', '4444'), array('1', '22', '33A', '44bb')); $this->checkPwd(['333', '4444'], ['1', '22', '33A', '44bb']);
$this->serverProfile->setPwdPolicyMinNumeric('5'); $this->serverProfile->setPwdPolicyMinNumeric('5');
$this->checkPwd(array('55555'), array('1', '22', '33A', '44bb', '333', '4444')); $this->checkPwd(['55555'], ['1', '22', '33A', '44bb', '333', '4444']);
$this->serverProfile->setPwdPolicyMinNumeric('2'); $this->serverProfile->setPwdPolicyMinNumeric('2');
$this->checkPwd(array('22', '33A', '44bb', '333', '4444'), array('1', 'X')); $this->checkPwd(['22', '33A', '44bb', '333', '4444'], ['1', 'X']);
} }
public function testMinSymbol() { public function testMinSymbol() {
$this->cfg->passwordMinSymbol = 3; $this->cfg->passwordMinSymbol = 3;
$this->checkPwd(array('---', '++++'), array('1.', '2.2.', '3+3+A', '44bb')); $this->checkPwd(['---', '++++'], ['1.', '2.2.', '3+3+A', '44bb']);
$this->serverProfile->setPwdPolicyMinSymbolic('5'); $this->serverProfile->setPwdPolicyMinSymbolic('5');
$this->checkPwd(array('---++', '++--++'), array('1.', '2.2.', '3+3+A--', '44bb')); $this->checkPwd(['---++', '++--++'], ['1.', '2.2.', '3+3+A--', '44bb']);
$this->serverProfile->setPwdPolicyMinSymbolic('2'); $this->serverProfile->setPwdPolicyMinSymbolic('2');
$this->checkPwd(array('-1-', '+x++'), array('1.', '2.', '3+3A', '44bb')); $this->checkPwd(['-1-', '+x++'], ['1.', '2.', '3+3A', '44bb']);
} }
public function testMinClasses() { public function testMinClasses() {
$this->cfg->passwordMinClasses = 3; $this->cfg->passwordMinClasses = 3;
$this->checkPwd(array('aB.', 'aB.1', 'aa.B99'), array('1', '2.', '3+-', '44bb')); $this->checkPwd(['aB.', 'aB.1', 'aa.B99'], ['1', '2.', '3+-', '44bb']);
} }
public function testRulesCount() { public function testRulesCount() {
@ -114,26 +114,26 @@ class SecurityTest extends TestCase {
$this->cfg->passwordMinClasses = 3; $this->cfg->passwordMinClasses = 3;
// all rules // all rules
$this->cfg->checkedRulesCount = -1; $this->cfg->checkedRulesCount = -1;
$this->checkPwd(array('ABC---abc123', 'ABC123xxx.-.-'), array('1', '2.', '3+-', '44bb', 'ABCabc---22')); $this->checkPwd(['ABC---abc123', 'ABC123xxx.-.-'], ['1', '2.', '3+-', '44bb', 'ABCabc---22']);
// at least 3 rules // at least 3 rules
$this->cfg->checkedRulesCount = 3; $this->cfg->checkedRulesCount = 3;
$this->checkPwd(array('ABC---abc', 'ABC123.-.-', 'ABCabc-'), array('1', '2.', '3+-', '44bb', 'ABC--22')); $this->checkPwd(['ABC---abc', 'ABC123.-.-', 'ABCabc-'], ['1', '2.', '3+-', '44bb', 'ABC--22']);
} }
public function testUser() { public function testUser() {
$this->cfg->passwordMustNotContainUser = 'true'; $this->cfg->passwordMustNotContainUser = 'true';
$this->checkPwd(array('u', 'us', 'use', 'use1r'), array('user', '2user', 'user3'), 'user'); $this->checkPwd(['u', 'us', 'use', 'use1r'], ['user', '2user', 'user3'], 'user');
$this->checkPwd(array('u', 'us', 'use', 'use1r'), array('user', '2user', 'user3', 'test'), array('user', 'test')); $this->checkPwd(['u', 'us', 'use', 'use1r'], ['user', '2user', 'user3', 'test'], ['user', 'test']);
} }
public function testUserAttributes() { public function testUserAttributes() {
$this->cfg->passwordMustNotContain3Chars = 'true'; $this->cfg->passwordMustNotContain3Chars = 'true';
$this->checkPwd(array('u', 'us', 'us1e', 'us1er'), array('use', 'user', '2user', 'user3'), 'user'); $this->checkPwd(['u', 'us', 'us1e', 'us1er'], ['use', 'user', '2user', 'user3'], 'user');
$this->checkPwd( $this->checkPwd(
array('uf', 'usfi', 'us1ela3s', 'us1er.la#st'), ['uf', 'usfi', 'us1ela3s', 'us1er.la#st'],
array('use', 'user', '2user', 'user3', 'las', 'last', 'fir', 'first'), ['use', 'user', '2user', 'user3', 'las', 'last', 'fir', 'first'],
'user', 'user',
array('first', 'last')); ['first', 'last']);
} }
/** /**
@ -169,7 +169,7 @@ class SecurityTest extends TestCase {
$userName = 'username'; $userName = 'username';
} }
if ($otherUserAttrs == null) { if ($otherUserAttrs == null) {
$otherUserAttrs = array (); $otherUserAttrs = [];
} }
foreach ($pwdsToAccept as $pwd) { foreach ($pwdsToAccept as $pwd) {
$this->assertTrue(checkPasswordStrength($pwd, $userName, $otherUserAttrs)); $this->assertTrue(checkPasswordStrength($pwd, $userName, $otherUserAttrs));

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2019 - 2020 Roland Gruber Copyright (C) 2019 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -45,7 +45,7 @@ class SelfServiceProfileTest extends TestCase {
public function testImportExport() { public function testImportExport() {
$profile = new selfServiceProfile(); $profile = new selfServiceProfile();
$moduleSettings = array('x1' => 'y1', 'x2' => 'y2'); $moduleSettings = ['x1' => 'y1', 'x2' => 'y2'];
$profile->moduleSettings = $moduleSettings; $profile->moduleSettings = $moduleSettings;
$profile->baseColor = 'green'; $profile->baseColor = 'green';
$profile->language = 'de_DE@UTF8'; $profile->language = 'de_DE@UTF8';

View file

@ -6,7 +6,7 @@ use user;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2016 - 2021 Roland Gruber Copyright (C) 2016 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -37,21 +37,21 @@ class TypesTest extends TestCase {
private $type; private $type;
protected function setUp(): void { protected function setUp(): void {
$this->type = $this->getMockBuilder('ConfiguredType')->setMethods(array('getBaseType', 'getModules'))->getMock(); $this->type = $this->getMockBuilder('ConfiguredType')->setMethods(['getBaseType', 'getModules'])->getMock();
$scope = new user($this->type); $scope = new user($this->type);
$this->type->method('getBaseType')->willReturn($scope); $this->type->method('getBaseType')->willReturn($scope);
$this->type->method('getModules')->willReturn(array('posixAccount')); $this->type->method('getModules')->willReturn(['posixAccount']);
} }
public function testPreTranslated() { public function testPreTranslated() {
$attr = new ListAttribute('#uid'); $attr = new ListAttribute('#uid');
$this->assertEquals('User name', $attr->getAlias(array('uid' => _('User name')))); $this->assertEquals('User name', $attr->getAlias(['uid' => _('User name')]));
$this->assertEquals('uid', $attr->getAttributeName()); $this->assertEquals('uid', $attr->getAttributeName());
} }
public function testCustomAlias() { public function testCustomAlias() {
$attr = new ListAttribute('uid:My translation'); $attr = new ListAttribute('uid:My translation');
$this->assertEquals('My translation', $attr->getAlias(array('uid' => _('User name')))); $this->assertEquals('My translation', $attr->getAlias(['uid' => _('User name')]));
$this->assertEquals('uid', $attr->getAttributeName()); $this->assertEquals('uid', $attr->getAttributeName());
} }

View file

@ -14,7 +14,7 @@ use \Webauthn\TrustPath\CertificateTrustPath;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2019 - 2021 Roland Gruber Copyright (C) 2019 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -59,7 +59,7 @@ class WebauthnManagerTest extends TestCase {
protected function setup(): void { protected function setup(): void {
$this->database = $this $this->database = $this
->getMockBuilder(PublicKeyCredentialSourceRepositorySQLite::class) ->getMockBuilder(PublicKeyCredentialSourceRepositorySQLite::class)
->onlyMethods(array('getPdoUrl', 'findOneByCredentialId', 'findAllForUserEntity')) ->onlyMethods(['getPdoUrl', 'findOneByCredentialId', 'findAllForUserEntity'])
->getMock(); ->getMock();
$file = tmpfile(); $file = tmpfile();
$filePath = stream_get_meta_data($file)['uri']; $filePath = stream_get_meta_data($file)['uri'];
@ -68,7 +68,7 @@ class WebauthnManagerTest extends TestCase {
$this->manager = $this $this->manager = $this
->getMockBuilder(WebauthnManager::class) ->getMockBuilder(WebauthnManager::class)
->onlyMethods(array('getDatabase')) ->onlyMethods(['getDatabase'])
->getMock(); ->getMock();
$this->manager->method('getDatabase')->willReturn($this->database); $this->manager->method('getDatabase')->willReturn($this->database);
@ -85,7 +85,7 @@ class WebauthnManagerTest extends TestCase {
} }
public function test_getAuthenticationObject() { public function test_getAuthenticationObject() {
$this->database->method('findAllForUserEntity')->willReturn(array()); $this->database->method('findAllForUserEntity')->willReturn([]);
$authenticationObj = $this->manager->getAuthenticationObject('uid=test,o=test', false); $authenticationObj = $this->manager->getAuthenticationObject('uid=test,o=test', false);
$this->assertEquals(32, strlen($authenticationObj->getChallenge())); $this->assertEquals(32, strlen($authenticationObj->getChallenge()));
@ -99,25 +99,23 @@ class WebauthnManagerTest extends TestCase {
} }
public function test_isRegistered_notRegistered() { public function test_isRegistered_notRegistered() {
$this->database->method('findAllForUserEntity')->willReturn(array()); $this->database->method('findAllForUserEntity')->willReturn([]);
$isRegistered = $this->manager->isRegistered('uid=test,o=test'); $isRegistered = $this->manager->isRegistered('uid=test,o=test');
$this->assertFalse($isRegistered); $this->assertFalse($isRegistered);
} }
public function test_isRegistered_registered() { public function test_isRegistered_registered() {
$this->database->method('findAllForUserEntity')->willReturn(array( $this->database->method('findAllForUserEntity')->willReturn([new PublicKeyCredentialSource(
new PublicKeyCredentialSource(
"id1", "id1",
PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY, PublicKeyCredentialDescriptor::CREDENTIAL_TYPE_PUBLIC_KEY,
array(), [],
"atype", "atype",
new CertificateTrustPath(array('x5c' => 'test')), new CertificateTrustPath(['x5c' => 'test']),
\Ramsey\Uuid\Uuid::uuid1(), \Ramsey\Uuid\Uuid::uuid1(),
"p1", "p1",
"uh1", "uh1",
1) 1)]);
));
$isRegistered = $this->manager->isRegistered('uid=test,o=test'); $isRegistered = $this->manager->isRegistered('uid=test,o=test');
$this->assertTrue($isRegistered); $this->assertTrue($isRegistered);

View file

@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 Roland Gruber Copyright (C) 2020 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -63,20 +63,20 @@ class WebauthnProviderTest extends TestCase {
$this->config->twoFactorAuthenticationOptional = true; $this->config->twoFactorAuthenticationOptional = true;
$manager = $this $manager = $this
->getMockBuilder(WebauthnManager::class) ->getMockBuilder(WebauthnManager::class)
->setMethods(array('isRegistered')) ->setMethods(['isRegistered'])
->getMock(); ->getMock();
$manager->method('isRegistered')->willReturn(false); $manager->method('isRegistered')->willReturn(false);
$provider = $this $provider = $this
->getMockBuilder(WebauthnProvider::class) ->getMockBuilder(WebauthnProvider::class)
->setConstructorArgs(array($this->config)) ->setConstructorArgs([$this->config])
->setMethods(array('getWebauthnManager')) ->setMethods(['getWebauthnManager'])
->getMock(); ->getMock();
$provider->method('getWebauthnManager')->willReturn($manager); $provider->method('getWebauthnManager')->willReturn($manager);
$row = new \htmlResponsiveRow(); $row = new \htmlResponsiveRow();
$provider->addCustomInput($row, 'userDn'); $provider->addCustomInput($row, 'userDn');
ob_start(); ob_start();
$row->generateHTML(null, array(), array(), false, null); $row->generateHTML(null, [], [], false, null);
$html = ob_get_contents(); $html = ob_get_contents();
ob_end_clean(); ob_end_clean();
$this->assertStringContainsString('skip_webauthn', $html); $this->assertStringContainsString('skip_webauthn', $html);

View file

@ -2,7 +2,7 @@
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2017 - 2021 Roland Gruber Copyright (C) 2017 - 2023 Roland Gruber
*/ */
if (is_readable('lam/lib/modules/customFields.inc')) { if (is_readable('lam/lib/modules/customFields.inc')) {
@ -24,9 +24,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '((Uid))456'; $originalStart = '((Uid))456';
$originalEnd = '123((uid))'; $originalEnd = '123((uid))';
$originalMultiple = '123((uid))456((uid))789'; $originalMultiple = '123((uid))456((uid))789';
$attributesSet = array('uid' => array('111')); $attributesSet = ['uid' => ['111']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -50,9 +50,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '%Uid%456'; $originalStart = '%Uid%456';
$originalEnd = '123%uid%'; $originalEnd = '123%uid%';
$originalMultiple = '123%uid%456%uid%789'; $originalMultiple = '123%uid%456%uid%789';
$attributesSet = array('uid' => array('111')); $attributesSet = ['uid' => ['111']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -76,9 +76,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '@Uid@456'; $originalStart = '@Uid@456';
$originalEnd = '123@uid@'; $originalEnd = '123@uid@';
$originalMultiple = '123@uid@456@uid@789'; $originalMultiple = '123@uid@456@uid@789';
$attributesSet = array('uid' => array('aBc')); $attributesSet = ['uid' => ['aBc']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -102,9 +102,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '?Uid?456'; $originalStart = '?Uid?456';
$originalEnd = '123?uid?'; $originalEnd = '123?uid?';
$originalMultiple = '123?uid?456?uid?789'; $originalMultiple = '123?uid?456?uid?789';
$attributesSet = array('uid' => array('Abc')); $attributesSet = ['uid' => ['Abc']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -128,9 +128,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '!Uid!456'; $originalStart = '!Uid!456';
$originalEnd = '123!uid!'; $originalEnd = '123!uid!';
$originalMultiple = '123!uid!456!uid!789'; $originalMultiple = '123!uid!456!uid!789';
$attributesSet = array('uid' => array('abc')); $attributesSet = ['uid' => ['abc']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -154,9 +154,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '??Uid??456'; $originalStart = '??Uid??456';
$originalEnd = '123??uid??'; $originalEnd = '123??uid??';
$originalMultiple = '123??uid??456??uid??789'; $originalMultiple = '123??uid??456??uid??789';
$attributesSet = array('uid' => array('Abc')); $attributesSet = ['uid' => ['Abc']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -180,9 +180,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '!!Uid!!456'; $originalStart = '!!Uid!!456';
$originalEnd = '123!!uid!!'; $originalEnd = '123!!uid!!';
$originalMultiple = '123!!uid!!456!!uid!!789'; $originalMultiple = '123!!uid!!456!!uid!!789';
$attributesSet = array('uid' => array('abc')); $attributesSet = ['uid' => ['abc']];
$attributesNotSet = array('uid' => array('')); $attributesNotSet = ['uid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -206,9 +206,9 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
$originalStart = '§MemberUid|, §456'; $originalStart = '§MemberUid|, §456';
$originalEnd = '123§memberUid|, §'; $originalEnd = '123§memberUid|, §';
$originalMultiple = '123§memberUid|, §456§memberUid|;§789'; $originalMultiple = '123§memberUid|, §456§memberUid|;§789';
$attributesSet = array('memberUid' => array('abc', 'cde')); $attributesSet = ['memberUid' => ['abc', 'cde']];
$attributesNotSet = array('memberUid' => array('')); $attributesNotSet = ['memberUid' => ['']];
$attributesNotSet2 = array(); $attributesNotSet2 = [];
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet, $originalMiddle));
$this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle)); $this->assertEquals('123456', customFieldsConstantEntry::replaceWildcards($attributesNotSet2, $originalMiddle));
@ -228,11 +228,11 @@ if (is_readable('lam/lib/modules/customFields.inc')) {
} }
public function testReplaceWildcardsMixed() { public function testReplaceWildcardsMixed() {
$attributes = array( $attributes = [
'uid' => array('myuser'), 'uid' => ['myuser'],
'street' => array('some street'), 'street' => ['some street'],
'memberUid' => array('abc', 'cde') 'memberUid' => ['abc', 'cde']
); ];
$this->assertEquals('myuser SOME STREET S abc- cde', customFieldsConstantEntry::replaceWildcards($attributes, '%uid% !!street!! !street! §memberuid|- §')); $this->assertEquals('myuser SOME STREET S abc- cde', customFieldsConstantEntry::replaceWildcards($attributes, '%uid% !!street!! !street! §memberuid|- §'));
$this->assertEquals(' MMYUSER', customFieldsConstantEntry::replaceWildcards($attributes, '((uid))!uid!!!uid!!')); $this->assertEquals(' MMYUSER', customFieldsConstantEntry::replaceWildcards($attributes, '((uid))!uid!!!uid!!'));

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2016 - 2019 Roland Gruber Copyright (C) 2016 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -38,27 +38,26 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
private $job; private $job;
const JOB_ID = 'jobID'; public const JOB_ID = 'jobID';
const WARNING = '14'; public const WARNING = '14';
const DEFAULT_POLICY = 'cn=default,dc=test'; public const DEFAULT_POLICY = 'cn=default,dc=test';
const NOEXPIRE_POLICY = 'cn=noexpire,dc=test'; public const NOEXPIRE_POLICY = 'cn=noexpire,dc=test';
const ONE_YEAR_POLICY = 'cn=policy1,dc=test'; public const ONE_YEAR_POLICY = 'cn=policy1,dc=test';
private $options = array(); private array $options = [];
private $resultLog; private $resultLog;
protected function setUp(): void { protected function setUp(): void {
$this->job = $this->getMockBuilder('PPolicyPasswordNotifyJob') $this->job = $this->getMockBuilder('PPolicyPasswordNotifyJob')
->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', ->setMethods(['getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix', 'getPolicyOptions'])
'findUsers', 'getConfigPrefix', 'getPolicyOptions'))
->getMock(); ->getMock();
$this->job->method('getConfigPrefix')->willReturn('test'); $this->job->method('getConfigPrefix')->willReturn('test');
$this->job->method('sendMail')->willReturn(true); $this->job->method('sendMail')->willReturn(true);
$this->job->method('getPolicyOptions')->willReturn(array( $this->job->method('getPolicyOptions')->willReturn([
PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY => array('pwdmaxage' => 365 * 3600 * 24), PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY => ['pwdmaxage' => 365 * 3600 * 24],
PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => array('pwdmaxage' => 14 * 3600 * 24), PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => ['pwdmaxage' => 14 * 3600 * 24],
PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => array('pwdmaxage' => 0), PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => ['pwdmaxage' => 0],
)); ]);
$this->options['test_mailNotificationPeriod' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::WARNING; $this->options['test_mailNotificationPeriod' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::WARNING;
$this->options['test_mailDefaultPolicy' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY; $this->options['test_mailDefaultPolicy' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY;
$this->resultLog = new \LAM\JOB\JobResultLog(); $this->resultLog = new \LAM\JOB\JobResultLog();
@ -66,58 +65,58 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
} }
public function testNoAccounts() { public function testNoAccounts() {
$this->job->method('findUsers')->willReturn(array()); $this->job->method('findUsers')->willReturn([]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
public function testAccountDoesNotExpire() { public function testAccountDoesNotExpire() {
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=noexpire,dc=dn', 'dn' => 'cn=noexpire,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY],
'pwdchangedtime' => array('20000101112233Z') 'pwdchangedtime' => ['20000101112233Z']
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
public function testAccountLocked() { public function testAccountLocked() {
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=locked,dc=dn', 'dn' => 'cn=locked,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY],
'pwdaccountlockedtime' => array('20010101112233Z'), 'pwdaccountlockedtime' => ['20010101112233Z'],
'pwdchangedtime' => array('20000101112233Z') 'pwdchangedtime' => ['20000101112233Z']
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
public function testAccountExpired() { public function testAccountExpired() {
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=expired,dc=dn', 'dn' => 'cn=expired,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY],
'pwdchangedtime' => array('20000101112233Z'), 'pwdchangedtime' => ['20000101112233Z'],
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -127,16 +126,16 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$lastChangeNow = floor($now->format('U')/3600/24); $lastChangeNow = floor($now->format('U')/3600/24);
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
$date = new DateTime('now', new DateTimeZone('UTC')); $date = new DateTime('now', new DateTimeZone('UTC'));
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=notReached,dc=dn', 'dn' => 'cn=notReached,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY],
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), 'pwdchangedtime' => [$date->format('YmdHis') . 'Z'],
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -145,17 +144,17 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$date = new DateTime('now', new DateTimeZone('UTC')); $date = new DateTime('now', new DateTimeZone('UTC'));
$date->sub(new DateInterval('P360D')); $date->sub(new DateInterval('P360D'));
$this->job->method('getDBLastPwdChangeTime')->willReturn($date->format('YmdHis') . 'Z'); $this->job->method('getDBLastPwdChangeTime')->willReturn($date->format('YmdHis') . 'Z');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=alreadyWarned,dc=dn', 'dn' => 'cn=alreadyWarned,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY],
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), 'pwdchangedtime' => [$date->format('YmdHis') . 'Z'],
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -164,17 +163,17 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$date = new DateTime('now', new DateTimeZone('UTC')); $date = new DateTime('now', new DateTimeZone('UTC'));
$date->sub(new DateInterval('P360D')); $date->sub(new DateInterval('P360D'));
$this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z'); $this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=alreadyWarned,dc=dn', 'dn' => 'cn=alreadyWarned,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY],
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), 'pwdchangedtime' => [$date->format('YmdHis') . 'Z'],
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->once())->method('setDBLastPwdChangeTime'); $this->job->expects($this->once())->method('setDBLastPwdChangeTime');
$this->job->expects($this->once())->method('sendMail'); $this->job->expects($this->once())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -183,24 +182,24 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$date = new DateTime('now', new DateTimeZone('UTC')); $date = new DateTime('now', new DateTimeZone('UTC'));
$date->sub(new DateInterval('P360D')); $date->sub(new DateInterval('P360D'));
$this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z'); $this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=alreadyWarned,dc=dn', 'dn' => 'cn=alreadyWarned,dc=dn',
'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), 'pwdpolicysubentry' => [PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY],
'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), 'pwdchangedtime' => [$date->format('YmdHis') . 'Z'],
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true, $this->resultLog); $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
public function testGetWarningTimeInSeconds() { public function testGetWarningTimeInSeconds() {
$confDays = 7; $confDays = 7;
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); $policy = ['pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000];
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
@ -208,7 +207,7 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$confDays = -7; $confDays = -7;
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); $policy = ['pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000];
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
@ -216,7 +215,7 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$confDays = 0; $confDays = 0;
$policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); $policy = ['pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000];
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);
@ -224,7 +223,7 @@ if (is_readable('lam/lib/modules/ppolicyUser.inc')) {
$confDays = 7; $confDays = 7;
$policy = array('pwdmaxage' => 365 * 3600 * 24); $policy = ['pwdmaxage' => 365 * 3600 * 24];
$seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy);

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 - 2021 Roland Gruber Copyright (C) 2020 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@ include_once __DIR__ . '/../../../lib/modules/quota.inc';
class QuotaTest extends TestCase { class QuotaTest extends TestCase {
protected function setUp(): void { protected function setUp(): void {
$_SESSION = array('language' => 'en_GB.utf8'); $_SESSION = ['language' => 'en_GB.utf8'];
} }
public function testAddBlockUnits() { public function testAddBlockUnits() {

View file

@ -36,79 +36,79 @@ use PHPUnit\Framework\TestCase;
class ShadowAccountTest extends TestCase { class ShadowAccountTest extends TestCase {
public function test_isAccountExpired_noAttr() { public function test_isAccountExpired_noAttr() {
$attrs = array('objectClass' => array('shadowAccount')); $attrs = ['objectClass' => ['shadowAccount']];
$this->assertFalse(shadowAccount::isAccountExpired($attrs)); $this->assertFalse(shadowAccount::isAccountExpired($attrs));
} }
public function test_isAccountExpired_notExpired() { public function test_isAccountExpired_notExpired() {
$expire = intval(time() / (24*3600)) + 10000; $expire = intval(time() / (24*3600)) + 10000;
$attrs = array( $attrs = [
'objectClass' => array('shadowAccount'), 'objectClass' => ['shadowAccount'],
'shadowexpire' => array(0 => $expire) 'shadowexpire' => [0 => $expire]
); ];
$this->assertFalse(shadowAccount::isAccountExpired($attrs)); $this->assertFalse(shadowAccount::isAccountExpired($attrs));
} }
public function test_isAccountExpired_expired() { public function test_isAccountExpired_expired() {
$expire = intval(time() / (24*3600)) - 10000; $expire = intval(time() / (24*3600)) - 10000;
$attrs = array( $attrs = [
'objectClass' => array('shadowAccount'), 'objectClass' => ['shadowAccount'],
'shadowexpire' => array(0 => $expire) 'shadowexpire' => [0 => $expire]
); ];
$this->assertTrue(shadowAccount::isAccountExpired($attrs)); $this->assertTrue(shadowAccount::isAccountExpired($attrs));
} }
public function test_isPasswordExpired_noAttr() { public function test_isPasswordExpired_noAttr() {
$attrs = array('objectClass' => array('shadowAccount')); $attrs = ['objectClass' => ['shadowAccount']];
$this->assertFalse(shadowAccount::isPasswordExpired($attrs)); $this->assertFalse(shadowAccount::isPasswordExpired($attrs));
} }
public function test_isPasswordExpired_notExpired() { public function test_isPasswordExpired_notExpired() {
$change = intval(time() / (24*3600)) - 10; $change = intval(time() / (24*3600)) - 10;
$attrs = array( $attrs = [
'objectClass' => array('shadowAccount'), 'objectClass' => ['shadowAccount'],
'shadowlastchange' => array(0 => $change), 'shadowlastchange' => [0 => $change],
'shadowmax' => array(0 => '14'), 'shadowmax' => [0 => '14'],
); ];
$this->assertFalse(shadowAccount::isPasswordExpired($attrs)); $this->assertFalse(shadowAccount::isPasswordExpired($attrs));
} }
public function test_isPasswordExpired_expired() { public function test_isPasswordExpired_expired() {
$change = intval(time() / (24*3600)) - 10; $change = intval(time() / (24*3600)) - 10;
$attrs = array( $attrs = [
'objectClass' => array('shadowAccount'), 'objectClass' => ['shadowAccount'],
'shadowlastchange' => array(0 => $change), 'shadowlastchange' => [0 => $change],
'shadowmax' => array(0 => '7'), 'shadowmax' => [0 => '7'],
); ];
$this->assertTrue(shadowAccount::isPasswordExpired($attrs)); $this->assertTrue(shadowAccount::isPasswordExpired($attrs));
} }
public function test_isPasswordExpired_notExpiredInactiveSet() { public function test_isPasswordExpired_notExpiredInactiveSet() {
$change = intval(time() / (24*3600)) - 10; $change = intval(time() / (24*3600)) - 10;
$attrs = array( $attrs = [
'objectClass' => array('shadowAccount'), 'objectClass' => ['shadowAccount'],
'shadowlastchange' => array(0 => $change), 'shadowlastchange' => [0 => $change],
'shadowmax' => array(0 => '7'), 'shadowmax' => [0 => '7'],
'shadowinactive' => array(0 => '14'), 'shadowinactive' => [0 => '14'],
); ];
$this->assertFalse(shadowAccount::isPasswordExpired($attrs)); $this->assertFalse(shadowAccount::isPasswordExpired($attrs));
} }
public function test_isPasswordExpired_expiredInactiveSet() { public function test_isPasswordExpired_expiredInactiveSet() {
$change = intval(time() / (24*3600)) - 10; $change = intval(time() / (24*3600)) - 10;
$attrs = array( $attrs = [
'objectClass' => array('shadowAccount'), 'objectClass' => ['shadowAccount'],
'shadowlastchange' => array(0 => $change), 'shadowlastchange' => [0 => $change],
'shadowmax' => array(0 => '7'), 'shadowmax' => [0 => '7'],
'shadowinactive' => array(0 => '2'), 'shadowinactive' => [0 => '2'],
); ];
$this->assertTrue(shadowAccount::isPasswordExpired($attrs)); $this->assertTrue(shadowAccount::isPasswordExpired($attrs));
} }
@ -127,15 +127,15 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
private $job; private $job;
const JOB_ID = 'jobID'; public const JOB_ID = 'jobID';
const WARNING = '14'; public const WARNING = '14';
private $options = array(); private array $options = [];
private $resultLog; private $resultLog;
public function setUp(): void { public function setUp(): void {
$this->job = $this->getMockBuilder('ShadowAccountPasswordNotifyJob') $this->job = $this->getMockBuilder('ShadowAccountPasswordNotifyJob')
->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix')) ->setMethods(['getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix'])
->getMock(); ->getMock();
$this->job->method('getConfigPrefix')->willReturn('test'); $this->job->method('getConfigPrefix')->willReturn('test');
$this->job->method('sendMail')->willReturn(true); $this->job->method('sendMail')->willReturn(true);
@ -144,42 +144,42 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
} }
public function testNoAccounts() { public function testNoAccounts() {
$this->job->method('findUsers')->willReturn(array()); $this->job->method('findUsers')->willReturn([]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
public function testAccountDoesNotExpire() { public function testAccountDoesNotExpire() {
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('0'), 'shadowmax' => ['0'],
'shadowlastchange' => array('1') 'shadowlastchange' => ['1']
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
public function testAccountExpired() { public function testAccountExpired() {
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('10'), 'shadowmax' => ['10'],
'shadowlastchange' => array('1') 'shadowlastchange' => ['1']
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -188,16 +188,16 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChangeNow = floor($now->format('U')/3600/24); $lastChangeNow = floor($now->format('U')/3600/24);
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('300'), 'shadowmax' => ['300'],
'shadowlastchange' => array($lastChangeNow) 'shadowlastchange' => [$lastChangeNow]
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -206,17 +206,17 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChangeNow = floor($now->format('U')/3600/24); $lastChangeNow = floor($now->format('U')/3600/24);
$this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow);
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('10'), 'shadowmax' => ['10'],
'shadowlastchange' => array($lastChangeNow) 'shadowlastchange' => [$lastChangeNow]
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -225,17 +225,17 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChange = floor($now->format('U')/3600/24) - 370; $lastChange = floor($now->format('U')/3600/24) - 370;
$this->job->method('getDBLastPwdChangeTime')->willReturn('1'); $this->job->method('getDBLastPwdChangeTime')->willReturn('1');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('365'), 'shadowmax' => ['365'],
'shadowlastchange' => array($lastChange) 'shadowlastchange' => [$lastChange]
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->once())->method('setDBLastPwdChangeTime'); $this->job->expects($this->once())->method('setDBLastPwdChangeTime');
$this->job->expects($this->once())->method('sendMail'); $this->job->expects($this->once())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -244,18 +244,18 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChange = floor($now->format('U')/3600/24) - 370; $lastChange = floor($now->format('U')/3600/24) - 370;
$this->job->method('getDBLastPwdChangeTime')->willReturn('1'); $this->job->method('getDBLastPwdChangeTime')->willReturn('1');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('365'), 'shadowmax' => ['365'],
'shadowwarning' => '10', 'shadowwarning' => '10',
'shadowlastchange' => array($lastChange) 'shadowlastchange' => [$lastChange]
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->once())->method('setDBLastPwdChangeTime'); $this->job->expects($this->once())->method('setDBLastPwdChangeTime');
$this->job->expects($this->once())->method('sendMail'); $this->job->expects($this->once())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -264,17 +264,17 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChange = floor($now->format('U')/3600/24) - 380; $lastChange = floor($now->format('U')/3600/24) - 380;
$this->job->method('getDBLastPwdChangeTime')->willReturn('1'); $this->job->method('getDBLastPwdChangeTime')->willReturn('1');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('365'), 'shadowmax' => ['365'],
'shadowwarning' => '10', 'shadowwarning' => '10',
'shadowlastchange' => array($lastChange) 'shadowlastchange' => [$lastChange]
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }
@ -283,18 +283,18 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChange = floor($now->format('U')/3600/24) - 373; $lastChange = floor($now->format('U')/3600/24) - 373;
$this->job->method('getDBLastPwdChangeTime')->willReturn('1'); $this->job->method('getDBLastPwdChangeTime')->willReturn('1');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('365'), 'shadowmax' => ['365'],
'shadowwarning' => '20', 'shadowwarning' => '20',
'shadowlastchange' => array($lastChange) 'shadowlastchange' => [$lastChange]
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->once())->method('setDBLastPwdChangeTime'); $this->job->expects($this->once())->method('setDBLastPwdChangeTime');
$this->job->expects($this->once())->method('sendMail'); $this->job->expects($this->once())->method('sendMail');
$pdo = array(); $pdo = [];
$this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = '-10'; $this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = '-10';
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
@ -304,17 +304,17 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChange = floor($now->format('U')/3600/24) - 377; $lastChange = floor($now->format('U')/3600/24) - 377;
$this->job->method('getDBLastPwdChangeTime')->willReturn('1'); $this->job->method('getDBLastPwdChangeTime')->willReturn('1');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('365'), 'shadowmax' => ['365'],
'shadowwarning' => '20', 'shadowwarning' => '20',
'shadowlastchange' => array($lastChange) 'shadowlastchange' => [$lastChange]
))); ]]);
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = '-10'; $this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = '-10';
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
@ -324,17 +324,17 @@ if (is_readable('lam/lib/passwordExpirationJob.inc')) {
$now = new DateTime('now', getTimeZone()); $now = new DateTime('now', getTimeZone());
$lastChangeNow = floor($now->format('U')/3600/24); $lastChangeNow = floor($now->format('U')/3600/24);
$this->job->method('getDBLastPwdChangeTime')->willReturn('1'); $this->job->method('getDBLastPwdChangeTime')->willReturn('1');
$this->job->method('findUsers')->willReturn(array(array( $this->job->method('findUsers')->willReturn([[
'dn' => 'cn=some,dc=dn', 'dn' => 'cn=some,dc=dn',
'shadowmax' => array('10'), 'shadowmax' => ['10'],
'shadowlastchange' => array($lastChangeNow) 'shadowlastchange' => [$lastChangeNow]
))); ]]);
$this->job->expects($this->once())->method('getDBLastPwdChangeTime'); $this->job->expects($this->once())->method('getDBLastPwdChangeTime');
$this->job->expects($this->never())->method('setDBLastPwdChangeTime'); $this->job->expects($this->never())->method('setDBLastPwdChangeTime');
$this->job->expects($this->never())->method('sendMail'); $this->job->expects($this->never())->method('sendMail');
$pdo = array(); $pdo = [];
$this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true, $this->resultLog); $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true, $this->resultLog);
$this->assertFalse($this->resultLog->hasError()); $this->assertFalse($this->resultLog->hasError());
} }

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2014 - 2019 Roland Gruber Copyright (C) 2014 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -35,19 +35,19 @@ if (is_readable('lam/lib/modules/sudoRole.inc')) {
class SudoRoleTest extends TestCase { class SudoRoleTest extends TestCase {
public function testIsValidDate() { public function testIsValidDate() {
$valid = array('22.10.2014', '05.01.2013', '1.3.2014', '10.5.2014', '4.12.2015', $valid = ['22.10.2014', '05.01.2013', '1.3.2014', '10.5.2014', '4.12.2015',
'05.01.2013 22:15', '1.3.2014 5:1', '10.5.2014 13:3', '4.12.2015 5:22'); '05.01.2013 22:15', '1.3.2014 5:1', '10.5.2014 13:3', '4.12.2015 5:22'];
foreach ($valid as $testDate) { foreach ($valid as $testDate) {
$this->assertTrue(sudoRole::isValidDate($testDate)); $this->assertTrue(sudoRole::isValidDate($testDate));
} }
$invalid = array('10.25.2014', 'abc', '2014-10-12', '10.022014', '10:12', '22.10.2014 12'); $invalid = ['10.25.2014', 'abc', '2014-10-12', '10.022014', '10:12', '22.10.2014 12'];
foreach ($invalid as $testDate) { foreach ($invalid as $testDate) {
$this->assertNotTrue(sudoRole::isValidDate($testDate), $testDate); $this->assertNotTrue(sudoRole::isValidDate($testDate), $testDate);
} }
} }
public function testEncodeDate() { public function testEncodeDate() {
$dates = array( $dates = [
'1.2.2014' => '20140201000000Z', '1.2.2014' => '20140201000000Z',
'10.2.2014' => '20140210000000Z', '10.2.2014' => '20140210000000Z',
'1.11.2014' => '20141101000000Z', '1.11.2014' => '20141101000000Z',
@ -56,14 +56,14 @@ if (is_readable('lam/lib/modules/sudoRole.inc')) {
'10.2.2014 1:10' => '20140210011000Z', '10.2.2014 1:10' => '20140210011000Z',
'1.11.2014 10:2' => '20141101100200Z', '1.11.2014 10:2' => '20141101100200Z',
'20.12.2014 10:12' => '20141220101200Z', '20.12.2014 10:12' => '20141220101200Z',
); ];
foreach ($dates as $input => $output) { foreach ($dates as $input => $output) {
$this->assertEquals($output, sudoRole::encodeDate($input), $input . ' ' . $output); $this->assertEquals($output, sudoRole::encodeDate($input), $input . ' ' . $output);
} }
} }
public function testDecodeDate() { public function testDecodeDate() {
$dates = array( $dates = [
'01.02.2014 00:00' => '20140201000000Z', '01.02.2014 00:00' => '20140201000000Z',
'10.02.2014 00:00' => '20140210000000Z', '10.02.2014 00:00' => '20140210000000Z',
'01.11.2014 00:00' => '20141101000000Z', '01.11.2014 00:00' => '20141101000000Z',
@ -72,7 +72,7 @@ if (is_readable('lam/lib/modules/sudoRole.inc')) {
'10.02.2014 01:10' => '20140210011000Z', '10.02.2014 01:10' => '20140210011000Z',
'01.11.2014 10:02' => '20141101100200Z', '01.11.2014 10:02' => '20141101100200Z',
'20.12.2014 10:12' => '20141220101200Z', '20.12.2014 10:12' => '20141220101200Z',
); ];
foreach ($dates as $output => $input) { foreach ($dates as $output => $input) {
$this->assertEquals($output, sudoRole::decodeDate($input), $input . ' ' . $output); $this->assertEquals($output, sudoRole::decodeDate($input), $input . ' ' . $output);
} }

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2017 - 2020 Roland Gruber Copyright (C) 2017 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -33,27 +33,27 @@ use PHPUnit\Framework\TestCase;
class WindowsUserTest extends TestCase { class WindowsUserTest extends TestCase {
public function test_isAccountExpired_noAttr() { public function test_isAccountExpired_noAttr() {
$attrs = array('objectClass' => array('user')); $attrs = ['objectClass' => ['user']];
$this->assertFalse(windowsUser::isAccountExpired($attrs)); $this->assertFalse(windowsUser::isAccountExpired($attrs));
} }
public function test_isAccountExpired_notExpired() { public function test_isAccountExpired_notExpired() {
$expire = $this->getTimeStamp(14); $expire = $this->getTimeStamp(14);
$attrs = array( $attrs = [
'objectClass' => array('user'), 'objectClass' => ['user'],
'accounTExpIRes' => array(0 => $expire) 'accounTExpIRes' => [0 => $expire]
); ];
$this->assertFalse(windowsUser::isAccountExpired($attrs)); $this->assertFalse(windowsUser::isAccountExpired($attrs));
} }
public function test_isAccountExpired_expired() { public function test_isAccountExpired_expired() {
$expire = $this->getTimeStamp(-14); $expire = $this->getTimeStamp(-14);
$attrs = array( $attrs = [
'objectClass' => array('user'), 'objectClass' => ['user'],
'accounTExpIRes' => array(0 => $expire) 'accounTExpIRes' => [0 => $expire]
); ];
$this->assertTrue(windowsUser::isAccountExpired($attrs)); $this->assertTrue(windowsUser::isAccountExpired($attrs));
} }

View file

@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2020 Roland Gruber Copyright (C) 2020 - 2023 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -44,9 +44,9 @@ class ExtraInvalidCredentialsTest extends TestCase {
public function test_getExtraMessage_noMessage() { public function test_getExtraMessage_noMessage() {
$extraInvalidCredentials = $this $extraInvalidCredentials = $this
->getMockBuilder(ExtraInvalidCredentials::class) ->getMockBuilder(ExtraInvalidCredentials::class)
->setMethods(array('getLdapData')) ->setMethods(['getLdapData'])
->getMock(); ->getMock();
$extraInvalidCredentials->method('getLdapData')->willReturn(array()); $extraInvalidCredentials->method('getLdapData')->willReturn([]);
$this->assertNull($extraInvalidCredentials->getExtraMessage(null, 'testDn')); $this->assertNull($extraInvalidCredentials->getExtraMessage(null, 'testDn'));
} }
@ -57,13 +57,13 @@ class ExtraInvalidCredentialsTest extends TestCase {
public function test_getExtraMessage_ppolicy() { public function test_getExtraMessage_ppolicy() {
$extraInvalidCredentials = $this $extraInvalidCredentials = $this
->getMockBuilder(ExtraInvalidCredentials::class) ->getMockBuilder(ExtraInvalidCredentials::class)
->setMethods(array('getLdapData')) ->setMethods(['getLdapData'])
->getMock(); ->getMock();
$extraInvalidCredentials->method('getLdapData')->willReturn( $extraInvalidCredentials->method('getLdapData')->willReturn(
array( [
'dn' => 'uid=test', 'dn' => 'uid=test',
'pwdaccountlockedtime' => array('1234') 'pwdaccountlockedtime' => ['1234']
) ]
); );
$this->assertNotNull($extraInvalidCredentials->getExtraMessage(null, 'testDn')); $this->assertNotNull($extraInvalidCredentials->getExtraMessage(null, 'testDn'));
@ -77,13 +77,13 @@ class ExtraInvalidCredentialsTest extends TestCase {
$time = $time->sub(new DateInterval('P1M')); $time = $time->sub(new DateInterval('P1M'));
$extraInvalidCredentials = $this $extraInvalidCredentials = $this
->getMockBuilder(ExtraInvalidCredentials::class) ->getMockBuilder(ExtraInvalidCredentials::class)
->setMethods(array('getLdapData')) ->setMethods(['getLdapData'])
->getMock(); ->getMock();
$extraInvalidCredentials->method('getLdapData')->willReturn( $extraInvalidCredentials->method('getLdapData')->willReturn(
array( [
'dn' => 'uid=test', 'dn' => 'uid=test',
'krbpasswordexpiration' => array($time->format('YmdHis') . 'Z') 'krbpasswordexpiration' => [$time->format('YmdHis') . 'Z']
) ]
); );
$this->assertNotNull($extraInvalidCredentials->getExtraMessage(null, 'testDn')); $this->assertNotNull($extraInvalidCredentials->getExtraMessage(null, 'testDn'));
@ -97,13 +97,13 @@ class ExtraInvalidCredentialsTest extends TestCase {
$time = $time->sub(new DateInterval('P1M')); $time = $time->sub(new DateInterval('P1M'));
$extraInvalidCredentials = $this $extraInvalidCredentials = $this
->getMockBuilder(ExtraInvalidCredentials::class) ->getMockBuilder(ExtraInvalidCredentials::class)
->setMethods(array('getLdapData')) ->setMethods(['getLdapData'])
->getMock(); ->getMock();
$extraInvalidCredentials->method('getLdapData')->willReturn( $extraInvalidCredentials->method('getLdapData')->willReturn(
array( [
'dn' => 'uid=test', 'dn' => 'uid=test',
'krbprincipalexpiration' => array($time->format('YmdHis') . 'Z') 'krbprincipalexpiration' => [$time->format('YmdHis') . 'Z']
) ]
); );
$this->assertNotNull($extraInvalidCredentials->getExtraMessage(null, 'testDn')); $this->assertNotNull($extraInvalidCredentials->getExtraMessage(null, 'testDn'));

View file

@ -24,7 +24,7 @@ namespace LAM\TOOLS\MULTI_EDIT;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
include_once (dirname(__FILE__) . '/../../../lib/multiEditTool.inc'); include_once (__DIR__ . '/../../../lib/multiEditTool.inc');
/** /**
* Checks code in multiEdit.php. * Checks code in multiEdit.php.
@ -35,30 +35,30 @@ include_once (dirname(__FILE__) . '/../../../lib/multiEditTool.inc');
class MultiEditTest extends TestCase { class MultiEditTest extends TestCase {
public function testExtractWildcards() { public function testExtractWildcards() {
$this->assertEquals(array('abc'), extractWildcards('((abc))')); $this->assertEquals(['abc'], extractWildcards('((abc))'));
$this->assertEquals(array('abc'), extractWildcards('%abc%')); $this->assertEquals(['abc'], extractWildcards('%abc%'));
$this->assertEquals(array('abc'), extractWildcards('@abc@')); $this->assertEquals(['abc'], extractWildcards('@abc@'));
$this->assertEquals(array('abc'), extractWildcards('??abc??')); $this->assertEquals(['abc'], extractWildcards('??abc??'));
$this->assertEquals(array('abc'), extractWildcards('!!abc!!')); $this->assertEquals(['abc'], extractWildcards('!!abc!!'));
$this->assertEquals(array('abc'), extractWildcards('?abc?')); $this->assertEquals(['abc'], extractWildcards('?abc?'));
$this->assertEquals(array('abc'), extractWildcards('!abc!')); $this->assertEquals(['abc'], extractWildcards('!abc!'));
$this->assertEquals(array('abc'), extractWildcards('§abc|;§')); $this->assertEquals(['abc'], extractWildcards('§abc|;§'));
$this->assertEquals(array('abc', 'xyz'), extractWildcards('%abc% %xyz%')); $this->assertEquals(['abc', 'xyz'], extractWildcards('%abc% %xyz%'));
$this->assertEquals(array('abc', 'xyz'), extractWildcards('%abc% ?xyz?')); $this->assertEquals(['abc', 'xyz'], extractWildcards('%abc% ?xyz?'));
$this->assertEquals(array('abc', 'xyz'), extractWildcards('adc %abc% %xyz% 123')); $this->assertEquals(['abc', 'xyz'], extractWildcards('adc %abc% %xyz% 123'));
$this->assertEquals(array('abc', 'xyz'), extractWildcards('adc %abc% ?xyz? 123')); $this->assertEquals(['abc', 'xyz'], extractWildcards('adc %abc% ?xyz? 123'));
} }
public function testReplaceWildcards() { public function testReplaceWildcards() {
$entry = array( $entry = [
'dn' => 'cn=admin,dc=example,dc=com', 'dn' => 'cn=admin,dc=example,dc=com',
'sn' => array('Steve'), 'sn' => array('Steve'),
'givenName' => array('Miller'), 'givenName' => array('Miller'),
'uid' => array('smiller'), 'uid' => array('smiller'),
'description' => array('line1', 'line2') 'description' => array('line1', 'line2')
); ];
$this->assertEquals('Steve', replaceWildcards('%Sn%', $entry)); $this->assertEquals('Steve', replaceWildcards('%Sn%', $entry));
$this->assertEquals('S', replaceWildcards('@Sn@', $entry)); $this->assertEquals('S', replaceWildcards('@Sn@', $entry));
$this->assertEquals('s', replaceWildcards('?Sn?', $entry)); $this->assertEquals('s', replaceWildcards('?Sn?', $entry));

View file

@ -29,6 +29,7 @@ parameters:
- '#Cannot access offset .* on mixed.#' - '#Cannot access offset .* on mixed.#'
- '#Cannot access offset .* on array\|int.#' - '#Cannot access offset .* on array\|int.#'
- '#Parameter \#1 \$haystack of function str_starts_with expects string, int\|string given.#' - '#Parameter \#1 \$haystack of function str_starts_with expects string, int\|string given.#'
- '#Parameter \#3 \$length of function substr expects int\|null, int<0, max>\|false given.#'
- '#Parameter \#1 \$string of function htmlspecialchars expects string, array<int, string>\|string given.#' - '#Parameter \#1 \$string of function htmlspecialchars expects string, array<int, string>\|string given.#'
- '#Parameter \#1 \$name of function LAM\\ACCOUNTLIST\\search_username expects string, array<int, string>\|string given.#' - '#Parameter \#1 \$name of function LAM\\ACCOUNTLIST\\search_username expects string, array<int, string>\|string given.#'
- '#Parameter \#1 \$array of function array_keys expects array, mixed given.#' - '#Parameter \#1 \$array of function array_keys expects array, mixed given.#'