From d862ff63006b3ba626d524805e42c884ca677365 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 11:05:30 +0100 Subject: [PATCH 1/9] phpunit --- phpunit.xml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 phpunit.xml diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..666c4a2b --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,8 @@ + + + + + lam/tests + + + \ No newline at end of file From 949bc2ad1b7c1da73b75d4a8d1d4fe586cae6dc8 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 17:51:15 +0100 Subject: [PATCH 2/9] PHPUnit --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5eba071b..cdd389d7 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require-dev" : { - "phpunit/phpunit" : "5.5.*", + "phpunit/phpunit" : "4.5.0", "squizlabs/php_codesniffer" : "2.7.1" } } \ No newline at end of file From 56bc52a7a740a3f3b340a0f87a1c34358cab24da Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 18:01:08 +0100 Subject: [PATCH 3/9] changed include paths --- lam/tests/lib/LAMConfigTest.php | 2 +- lam/tests/lib/modules/ppolicyUserTest.php | 8 ++++---- lam/tests/lib/modules/sambaSamAccountTest.php | 8 ++++---- lam/tests/lib/modules/shadowAccountTest.php | 8 ++++---- lam/tests/lib/modules/sudoRoleTest.php | 4 ++-- lam/tests/lib/securityTest.php | 4 ++-- lam/tests/lib/typesTest.php | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lam/tests/lib/LAMConfigTest.php b/lam/tests/lib/LAMConfigTest.php index 2b114efd..c4790bde 100644 --- a/lam/tests/lib/LAMConfigTest.php +++ b/lam/tests/lib/LAMConfigTest.php @@ -21,7 +21,7 @@ */ -include_once (dirname ( __FILE__ ) . '/../utils/configuration.inc'); +include_once 'lam/tests/utils/configuration.inc'; /** * LAMConfig test case. diff --git a/lam/tests/lib/modules/ppolicyUserTest.php b/lam/tests/lib/modules/ppolicyUserTest.php index e17596b9..08751d55 100644 --- a/lam/tests/lib/modules/ppolicyUserTest.php +++ b/lam/tests/lib/modules/ppolicyUserTest.php @@ -21,10 +21,10 @@ */ -include_once '../../../lib/baseModule.inc'; -include_once '../../../lib/modules.inc'; -include_once '../../../lib/passwordExpirationJob.inc'; -include_once '../../../lib/modules/ppolicyUser.inc'; +include_once 'lam/lib/baseModule.inc'; +include_once 'lam/lib/modules.inc'; +include_once 'lam/lib/passwordExpirationJob.inc'; +include_once 'lam/lib/modules/ppolicyUser.inc'; /** * Checks the ppolicy expire job. diff --git a/lam/tests/lib/modules/sambaSamAccountTest.php b/lam/tests/lib/modules/sambaSamAccountTest.php index 2fb419c3..be42f93a 100644 --- a/lam/tests/lib/modules/sambaSamAccountTest.php +++ b/lam/tests/lib/modules/sambaSamAccountTest.php @@ -21,10 +21,10 @@ */ -include_once (dirname ( __FILE__ ) . '/../../../lib/baseModule.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/modules.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/passwordExpirationJob.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/modules/sambaSamAccount.inc'); +include_once 'lam/lib/baseModule.inc'; +include_once 'lam/lib/modules.inc'; +include_once 'lam/lib/passwordExpirationJob.inc'; +include_once 'lam/lib/modules/sambaSamAccount.inc'; /** * Checks the shadow expire job. diff --git a/lam/tests/lib/modules/shadowAccountTest.php b/lam/tests/lib/modules/shadowAccountTest.php index 77051a07..6eec3e90 100644 --- a/lam/tests/lib/modules/shadowAccountTest.php +++ b/lam/tests/lib/modules/shadowAccountTest.php @@ -21,10 +21,10 @@ */ -include_once (dirname ( __FILE__ ) . '/../../../lib/baseModule.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/modules.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/passwordExpirationJob.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/modules/shadowAccount.inc'); +include_once 'lam/lib/baseModule.inc'; +include_once 'lam/lib/modules.inc'; +include_once 'lam/lib/passwordExpirationJob.inc'; +include_once 'lam/lib/modules/shadowAccount.inc'; /** * Checks the shadow expire job. diff --git a/lam/tests/lib/modules/sudoRoleTest.php b/lam/tests/lib/modules/sudoRoleTest.php index 0c542e3e..fc03eb81 100644 --- a/lam/tests/lib/modules/sudoRoleTest.php +++ b/lam/tests/lib/modules/sudoRoleTest.php @@ -21,8 +21,8 @@ $Id$ */ -include_once (dirname ( __FILE__ ) . '/../../../lib/baseModule.inc'); -include_once (dirname ( __FILE__ ) . '/../../../lib/modules/sudoRole.inc'); +include_once 'lam/lib/baseModule.inc'; +include_once 'lam/lib/modules/sudoRole.inc'; /** * Checks sudo role functions. diff --git a/lam/tests/lib/securityTest.php b/lam/tests/lib/securityTest.php index c391ee2d..9fcf4e38 100644 --- a/lam/tests/lib/securityTest.php +++ b/lam/tests/lib/securityTest.php @@ -23,8 +23,8 @@ $Id$ $_SERVER ['REMOTE_ADDR'] = '127.0.0.1'; -include_once (dirname ( __FILE__ ) . '/../utils/configuration.inc'); -include_once (dirname ( __FILE__ ) . '/../../lib/security.inc'); +include_once 'lam/tests/utils/configuration.inc'; +include_once 'lam/lib/security.inc'; /** * Checks password checking functions. diff --git a/lam/tests/lib/typesTest.php b/lam/tests/lib/typesTest.php index a0f9c3c4..38941ffa 100644 --- a/lam/tests/lib/typesTest.php +++ b/lam/tests/lib/typesTest.php @@ -21,7 +21,7 @@ $Id$ */ -require_once '../../lib/types.inc'; +require_once 'lam/lib/types.inc'; /** * Checks ListAttribute. From 39fdc3e5d2000368ab241e480f70bb94d3a6160c Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 18:06:18 +0100 Subject: [PATCH 4/9] include path --- phpunit.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpunit.xml b/phpunit.xml index 666c4a2b..8354e8e3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,4 +5,7 @@ lam/tests + + . + \ No newline at end of file From 4417e5aff7837c1df938a0d66f07f43815c22f9b Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 18:16:49 +0100 Subject: [PATCH 5/9] check if tests can be run --- lam/tests/lib/modules/ppolicyUserTest.php | 305 +++++++++--------- lam/tests/lib/modules/sambaSamAccountTest.php | 1 - lam/tests/lib/modules/shadowAccountTest.php | 225 ++++++------- lam/tests/lib/modules/sudoRoleTest.php | 100 +++--- 4 files changed, 320 insertions(+), 311 deletions(-) diff --git a/lam/tests/lib/modules/ppolicyUserTest.php b/lam/tests/lib/modules/ppolicyUserTest.php index 08751d55..cc6b4086 100644 --- a/lam/tests/lib/modules/ppolicyUserTest.php +++ b/lam/tests/lib/modules/ppolicyUserTest.php @@ -21,200 +21,203 @@ */ -include_once 'lam/lib/baseModule.inc'; -include_once 'lam/lib/modules.inc'; -include_once 'lam/lib/passwordExpirationJob.inc'; -include_once 'lam/lib/modules/ppolicyUser.inc'; +if (is_readable('lam/lib/modules/ppolicyUser.inc')) { -/** - * Checks the ppolicy expire job. - * - * @author Roland Gruber - * - */ -class PPolicyUserPasswordNotifyJobTest extends PHPUnit_Framework_TestCase { + include_once 'lam/lib/baseModule.inc'; + include_once 'lam/lib/modules.inc'; + include_once 'lam/lib/passwordExpirationJob.inc'; + include_once 'lam/lib/modules/ppolicyUser.inc'; - private $job; + /** + * Checks the ppolicy expire job. + * + * @author Roland Gruber + * + */ + class PPolicyUserPasswordNotifyJobTest extends PHPUnit_Framework_TestCase { - const JOB_ID = 'jobID'; - const WARNING = '14'; - const DEFAULT_POLICY = 'cn=default,dc=test'; - const NOEXPIRE_POLICY = 'cn=noexpire,dc=test'; - const ONE_YEAR_POLICY = 'cn=policy1,dc=test'; + private $job; - private $options = array(); + const JOB_ID = 'jobID'; + const WARNING = '14'; + const DEFAULT_POLICY = 'cn=default,dc=test'; + const NOEXPIRE_POLICY = 'cn=noexpire,dc=test'; + const ONE_YEAR_POLICY = 'cn=policy1,dc=test'; - public function setUp() { - $this->job = $this->getMockBuilder('PPolicyPasswordNotifyJob') - ->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', - 'findUsers', 'getConfigPrefix', 'getPolicyOptions')) - ->getMock(); - $this->job->method('getConfigPrefix')->willReturn('test'); - $this->job->method('sendMail')->willReturn(true); - $this->job->method('getPolicyOptions')->willReturn(array( - PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY => array('pwdmaxage' => 365 * 3600 * 24), - PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => array('pwdmaxage' => 14 * 3600 * 24), - PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => array('pwdmaxage' => 0), - )); - $this->options['test_mailNotificationPeriod' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::WARNING; - $this->options['test_mailDefaultPolicy' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY; - } + private $options = array(); - public function testNoAccounts() { - $this->job->method('findUsers')->willReturn(array()); + public function setUp() { + $this->job = $this->getMockBuilder('PPolicyPasswordNotifyJob') + ->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', + 'findUsers', 'getConfigPrefix', 'getPolicyOptions')) + ->getMock(); + $this->job->method('getConfigPrefix')->willReturn('test'); + $this->job->method('sendMail')->willReturn(true); + $this->job->method('getPolicyOptions')->willReturn(array( + PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY => array('pwdmaxage' => 365 * 3600 * 24), + PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY => array('pwdmaxage' => 14 * 3600 * 24), + PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY => array('pwdmaxage' => 0), + )); + $this->options['test_mailNotificationPeriod' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::WARNING; + $this->options['test_mailDefaultPolicy' . PPolicyUserPasswordNotifyJobTest::JOB_ID][0] = PPolicyUserPasswordNotifyJobTest::DEFAULT_POLICY; + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testNoAccounts() { + $this->job->method('findUsers')->willReturn(array()); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAccountDoesNotExpire() { - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=noexpire,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY), - 'pwdchangedtime' => array('20000101112233Z') - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAccountDoesNotExpire() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=noexpire,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::NOEXPIRE_POLICY), + 'pwdchangedtime' => array('20000101112233Z') + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAccountLocked() { - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=locked,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), - 'pwdaccountlockedtime' => array('20010101112233Z'), - 'pwdchangedtime' => array('20000101112233Z') - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAccountLocked() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=locked,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdaccountlockedtime' => array('20010101112233Z'), + 'pwdchangedtime' => array('20000101112233Z') + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAccountExpired() { - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=expired,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), - 'pwdchangedtime' => array('20000101112233Z'), - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAccountExpired() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=expired,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdchangedtime' => array('20000101112233Z'), + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testWarningNotReached() { - $now = new DateTime('now', getTimeZone()); - $lastChangeNow = floor($now->format('U')/3600/24); - $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); - $date = new DateTime('now', new DateTimeZone('UTC')); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=notReached,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), - 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testWarningNotReached() { + $now = new DateTime('now', getTimeZone()); + $lastChangeNow = floor($now->format('U')/3600/24); + $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); + $date = new DateTime('now', new DateTimeZone('UTC')); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=notReached,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAlreadyWarned() { - $now = new DateTime('now', getTimeZone()); - $date = new DateTime('now', new DateTimeZone('UTC')); - $date->sub(new DateInterval('P360D')); - $this->job->method('getDBLastPwdChangeTime')->willReturn($date->format('YmdHis') . 'Z'); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=alreadyWarned,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), - 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAlreadyWarned() { + $now = new DateTime('now', getTimeZone()); + $date = new DateTime('now', new DateTimeZone('UTC')); + $date->sub(new DateInterval('P360D')); + $this->job->method('getDBLastPwdChangeTime')->willReturn($date->format('YmdHis') . 'Z'); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=alreadyWarned,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testWarning() { - $now = new DateTime('now', getTimeZone()); - $date = new DateTime('now', new DateTimeZone('UTC')); - $date->sub(new DateInterval('P360D')); - $this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z'); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=alreadyWarned,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), - 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); - $this->job->expects($this->once())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->once())->method('sendMail'); + public function testWarning() { + $now = new DateTime('now', getTimeZone()); + $date = new DateTime('now', new DateTimeZone('UTC')); + $date->sub(new DateInterval('P360D')); + $this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z'); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=alreadyWarned,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); + $this->job->expects($this->once())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->once())->method('sendMail'); - public function testWarningDryRun() { - $now = new DateTime('now', getTimeZone()); - $date = new DateTime('now', new DateTimeZone('UTC')); - $date->sub(new DateInterval('P360D')); - $this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z'); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=alreadyWarned,dc=dn', - 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), - 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), - ))); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testWarningDryRun() { + $now = new DateTime('now', getTimeZone()); + $date = new DateTime('now', new DateTimeZone('UTC')); + $date->sub(new DateInterval('P360D')); + $this->job->method('getDBLastPwdChangeTime')->willReturn('20001111101010Z'); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=alreadyWarned,dc=dn', + 'pwdpolicysubentry' => array(PPolicyUserPasswordNotifyJobTest::ONE_YEAR_POLICY), + 'pwdchangedtime' => array($date->format('YmdHis') . 'Z'), + ))); - $pdo = array(); - $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true); - } + $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testGetWarningTimeInSeconds() { - $confDays = 7; - $policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); + $pdo = array(); + $this->job->execute(PPolicyUserPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true); + } - $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); + public function testGetWarningTimeInSeconds() { + $confDays = 7; + $policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); - $this->assertEquals((7*3600*24 + 10000), $seconds); + $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); + + $this->assertEquals((7*3600*24 + 10000), $seconds); - $confDays = 0; - $policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); + $confDays = 0; + $policy = array('pwdmaxage' => 365 * 3600 * 24, 'pwdexpirewarning' => 10000); - $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); + $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); - $this->assertEquals(10000, $seconds); + $this->assertEquals(10000, $seconds); - $confDays = 7; - $policy = array('pwdmaxage' => 365 * 3600 * 24); + $confDays = 7; + $policy = array('pwdmaxage' => 365 * 3600 * 24); - $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); + $seconds = $this->job->getWarningTimeInSeconds($confDays, $policy); - $this->assertEquals(7*3600*24, $seconds); + $this->assertEquals(7*3600*24, $seconds); + + } } } - ?> \ No newline at end of file diff --git a/lam/tests/lib/modules/sambaSamAccountTest.php b/lam/tests/lib/modules/sambaSamAccountTest.php index be42f93a..a9da3b76 100644 --- a/lam/tests/lib/modules/sambaSamAccountTest.php +++ b/lam/tests/lib/modules/sambaSamAccountTest.php @@ -23,7 +23,6 @@ include_once 'lam/lib/baseModule.inc'; include_once 'lam/lib/modules.inc'; -include_once 'lam/lib/passwordExpirationJob.inc'; include_once 'lam/lib/modules/sambaSamAccount.inc'; /** diff --git a/lam/tests/lib/modules/shadowAccountTest.php b/lam/tests/lib/modules/shadowAccountTest.php index 6eec3e90..bfcacd30 100644 --- a/lam/tests/lib/modules/shadowAccountTest.php +++ b/lam/tests/lib/modules/shadowAccountTest.php @@ -21,145 +21,148 @@ */ -include_once 'lam/lib/baseModule.inc'; -include_once 'lam/lib/modules.inc'; -include_once 'lam/lib/passwordExpirationJob.inc'; -include_once 'lam/lib/modules/shadowAccount.inc'; +if (is_readable('lam/lib/passwordExpirationJob.inc')) { -/** - * Checks the shadow expire job. - * - * @author Roland Gruber - * - */ -class ShadowAccountPasswordNotifyJobTest extends PHPUnit_Framework_TestCase { + include_once 'lam/lib/baseModule.inc'; + include_once 'lam/lib/modules.inc'; + include_once 'lam/lib/passwordExpirationJob.inc'; + include_once 'lam/lib/modules/shadowAccount.inc'; - private $job; + /** + * Checks the shadow expire job. + * + * @author Roland Gruber + * + */ + class ShadowAccountPasswordNotifyJobTest extends PHPUnit_Framework_TestCase { - const JOB_ID = 'jobID'; - const WARNING = '14'; + private $job; - private $options = array(); + const JOB_ID = 'jobID'; + const WARNING = '14'; - public function setUp() { - $this->job = $this->getMockBuilder('ShadowAccountPasswordNotifyJob') - ->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix')) - ->getMock(); - $this->job->method('getConfigPrefix')->willReturn('test'); - $this->job->method('sendMail')->willReturn(true); - $this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = ShadowAccountPasswordNotifyJobTest::WARNING; - } + private $options = array(); - public function testNoAccounts() { - $this->job->method('findUsers')->willReturn(array()); + public function setUp() { + $this->job = $this->getMockBuilder('ShadowAccountPasswordNotifyJob') + ->setMethods(array('getDBLastPwdChangeTime', 'setDBLastPwdChangeTime', 'sendMail', 'findUsers', 'getConfigPrefix')) + ->getMock(); + $this->job->method('getConfigPrefix')->willReturn('test'); + $this->job->method('sendMail')->willReturn(true); + $this->options['test_mailNotificationPeriod' . ShadowAccountPasswordNotifyJobTest::JOB_ID][0] = ShadowAccountPasswordNotifyJobTest::WARNING; + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testNoAccounts() { + $this->job->method('findUsers')->willReturn(array()); - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAccountDoesNotExpire() { - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=some,dc=dn', - 'shadowmax' => array('0'), - 'shadowlastchange' => array('1') - ))); + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAccountDoesNotExpire() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=some,dc=dn', + 'shadowmax' => array('0'), + 'shadowlastchange' => array('1') + ))); - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAccountExpired() { - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=some,dc=dn', - 'shadowmax' => array('10'), - 'shadowlastchange' => array('1') - ))); + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAccountExpired() { + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=some,dc=dn', + 'shadowmax' => array('10'), + 'shadowlastchange' => array('1') + ))); - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testWarningNotReached() { - $now = new DateTime('now', getTimeZone()); - $lastChangeNow = floor($now->format('U')/3600/24); - $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=some,dc=dn', - 'shadowmax' => array('300'), - 'shadowlastchange' => array($lastChangeNow) - ))); + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testWarningNotReached() { + $now = new DateTime('now', getTimeZone()); + $lastChangeNow = floor($now->format('U')/3600/24); + $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=some,dc=dn', + 'shadowmax' => array('300'), + 'shadowlastchange' => array($lastChangeNow) + ))); - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testAlreadyWarned() { - $now = new DateTime('now', getTimeZone()); - $lastChangeNow = floor($now->format('U')/3600/24); - $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=some,dc=dn', - 'shadowmax' => array('10'), - 'shadowlastchange' => array($lastChangeNow) - ))); + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testAlreadyWarned() { + $now = new DateTime('now', getTimeZone()); + $lastChangeNow = floor($now->format('U')/3600/24); + $this->job->method('getDBLastPwdChangeTime')->willReturn($lastChangeNow); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=some,dc=dn', + 'shadowmax' => array('10'), + 'shadowlastchange' => array($lastChangeNow) + ))); - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); - public function testWarning() { - $now = new DateTime('now', getTimeZone()); - $lastChangeNow = floor($now->format('U')/3600/24); - $this->job->method('getDBLastPwdChangeTime')->willReturn('1'); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=some,dc=dn', - 'shadowmax' => array('10'), - 'shadowlastchange' => array($lastChangeNow) - ))); + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); - $this->job->expects($this->once())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->once())->method('sendMail'); + public function testWarning() { + $now = new DateTime('now', getTimeZone()); + $lastChangeNow = floor($now->format('U')/3600/24); + $this->job->method('getDBLastPwdChangeTime')->willReturn('1'); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=some,dc=dn', + 'shadowmax' => array('10'), + 'shadowlastchange' => array($lastChangeNow) + ))); - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); - } + $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); + $this->job->expects($this->once())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->once())->method('sendMail'); - public function testWarningDryRun() { - $now = new DateTime('now', getTimeZone()); - $lastChangeNow = floor($now->format('U')/3600/24); - $this->job->method('getDBLastPwdChangeTime')->willReturn('1'); - $this->job->method('findUsers')->willReturn(array(array( - 'dn' => 'cn=some,dc=dn', - 'shadowmax' => array('10'), - 'shadowlastchange' => array($lastChangeNow) - ))); + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, false); + } - $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); - $this->job->expects($this->never())->method('sendMail'); + public function testWarningDryRun() { + $now = new DateTime('now', getTimeZone()); + $lastChangeNow = floor($now->format('U')/3600/24); + $this->job->method('getDBLastPwdChangeTime')->willReturn('1'); + $this->job->method('findUsers')->willReturn(array(array( + 'dn' => 'cn=some,dc=dn', + 'shadowmax' => array('10'), + 'shadowlastchange' => array($lastChangeNow) + ))); + + $this->job->expects($this->once())->method('getDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('setDBLastPwdChangeTime'); + $this->job->expects($this->never())->method('sendMail'); + + $pdo = array(); + $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true); + } - $pdo = array(); - $this->job->execute(ShadowAccountPasswordNotifyJobTest::JOB_ID, $this->options, $pdo, true); } } - ?> \ No newline at end of file diff --git a/lam/tests/lib/modules/sudoRoleTest.php b/lam/tests/lib/modules/sudoRoleTest.php index fc03eb81..56630701 100644 --- a/lam/tests/lib/modules/sudoRoleTest.php +++ b/lam/tests/lib/modules/sudoRoleTest.php @@ -3,7 +3,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2014 Roland Gruber + Copyright (C) 2014 - 2016 Roland Gruber 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 @@ -21,59 +21,63 @@ $Id$ */ -include_once 'lam/lib/baseModule.inc'; -include_once 'lam/lib/modules/sudoRole.inc'; +if (is_readable('lam/lib/modules/sudoRole.inc')) { -/** - * Checks sudo role functions. - * - * @author Roland Gruber - * - */ -class SudoRoleTest extends PHPUnit_Framework_TestCase { + include_once 'lam/lib/baseModule.inc'; + include_once 'lam/lib/modules/sudoRole.inc'; - public function testIsValidDate() { - $valid = array('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'); - foreach ($valid as $testDate) { - $this->assertTrue(sudoRole::isValidDate($testDate)); - } - $invalid = array('10.25.2014', 'abc', '2014-10-12', '10.022014', '10:12', '22.10.2014 12'); - foreach ($invalid as $testDate) { - $this->assertNotTrue(sudoRole::isValidDate($testDate), $testDate); - } - } + /** + * Checks sudo role functions. + * + * @author Roland Gruber + * + */ + class SudoRoleTest extends PHPUnit_Framework_TestCase { - public function testEncodeDate() { - $dates = array( - '1.2.2014' => '20140201000000Z', - '10.2.2014' => '20140210000000Z', - '1.11.2014' => '20141101000000Z', - '20.12.2014' => '20141220000000Z', - '1.2.2014 1:2' => '20140201010200Z', - '10.2.2014 1:10' => '20140210011000Z', - '1.11.2014 10:2' => '20141101100200Z', - '20.12.2014 10:12' => '20141220101200Z', - ); - foreach ($dates as $input => $output) { - $this->assertEquals($output, sudoRole::encodeDate($input), $input . ' ' . $output); + public function testIsValidDate() { + $valid = array('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'); + foreach ($valid as $testDate) { + $this->assertTrue(sudoRole::isValidDate($testDate)); + } + $invalid = array('10.25.2014', 'abc', '2014-10-12', '10.022014', '10:12', '22.10.2014 12'); + foreach ($invalid as $testDate) { + $this->assertNotTrue(sudoRole::isValidDate($testDate), $testDate); + } } - } - public function testDecodeDate() { - $dates = array( - '01.02.2014 00:00' => '20140201000000Z', - '10.02.2014 00:00' => '20140210000000Z', - '01.11.2014 00:00' => '20141101000000Z', - '20.12.2014 00:00' => '20141220000000Z', - '01.02.2014 01:02' => '20140201010200Z', - '10.02.2014 01:10' => '20140210011000Z', - '01.11.2014 10:02' => '20141101100200Z', - '20.12.2014 10:12' => '20141220101200Z', - ); - foreach ($dates as $output => $input) { - $this->assertEquals($output, sudoRole::decodeDate($input), $input . ' ' . $output); + public function testEncodeDate() { + $dates = array( + '1.2.2014' => '20140201000000Z', + '10.2.2014' => '20140210000000Z', + '1.11.2014' => '20141101000000Z', + '20.12.2014' => '20141220000000Z', + '1.2.2014 1:2' => '20140201010200Z', + '10.2.2014 1:10' => '20140210011000Z', + '1.11.2014 10:2' => '20141101100200Z', + '20.12.2014 10:12' => '20141220101200Z', + ); + foreach ($dates as $input => $output) { + $this->assertEquals($output, sudoRole::encodeDate($input), $input . ' ' . $output); + } } + + public function testDecodeDate() { + $dates = array( + '01.02.2014 00:00' => '20140201000000Z', + '10.02.2014 00:00' => '20140210000000Z', + '01.11.2014 00:00' => '20141101000000Z', + '20.12.2014 00:00' => '20141220000000Z', + '01.02.2014 01:02' => '20140201010200Z', + '10.02.2014 01:10' => '20140210011000Z', + '01.11.2014 10:02' => '20141101100200Z', + '20.12.2014 10:12' => '20141220101200Z', + ); + foreach ($dates as $output => $input) { + $this->assertEquals($output, sudoRole::decodeDate($input), $input . ' ' . $output); + } + } + } } From fad7a009f024c012e81549abfc3d4a9b1e9bb7ad Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 18:31:55 +0100 Subject: [PATCH 6/9] html coverage --- phpunit.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpunit.xml b/phpunit.xml index 8354e8e3..6569f247 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,4 +8,7 @@ . + + + \ No newline at end of file From 0bf870276318f94f3adf163bb989f86a40f9c54d Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 18:41:22 +0100 Subject: [PATCH 7/9] new type API --- lam/lib/tools/ouEditor.inc | 51 +++++++++++++++++---------------- lam/lib/tools/pdfEdit.inc | 51 +++++++++++++++++---------------- lam/lib/tools/profileEditor.inc | 51 +++++++++++++++++---------------- lam/templates/ou_edit.php | 22 ++++++++++---- 4 files changed, 94 insertions(+), 81 deletions(-) diff --git a/lam/lib/tools/ouEditor.inc b/lam/lib/tools/ouEditor.inc index 81769e63..5f49143f 100644 --- a/lam/lib/tools/ouEditor.inc +++ b/lam/lib/tools/ouEditor.inc @@ -1,20 +1,21 @@ get_ActiveTypes()) > 0); } - + /** * Returns if a tool may be hidden by configuration in the LAM server profile. - * + * * @return boolean hideable */ function isHideable() { return true; } - + } ?> \ No newline at end of file diff --git a/lam/lib/tools/pdfEdit.inc b/lam/lib/tools/pdfEdit.inc index f3c36650..ed321650 100644 --- a/lam/lib/tools/pdfEdit.inc +++ b/lam/lib/tools/pdfEdit.inc @@ -1,20 +1,21 @@ get_ActiveTypes()) > 0); } - + /** * Returns if a tool may be hidden by configuration in the LAM server profile. - * + * * @return boolean hideable */ function isHideable() { return true; } - + } ?> \ No newline at end of file diff --git a/lam/lib/tools/profileEditor.inc b/lam/lib/tools/profileEditor.inc index 1771c4e4..36f88eed 100644 --- a/lam/lib/tools/profileEditor.inc +++ b/lam/lib/tools/profileEditor.inc @@ -1,20 +1,21 @@ get_ActiveTypes()) > 0); } - + /** * Returns if a tool may be hidden by configuration in the LAM server profile. - * + * * @return boolean hideable */ function isHideable() { return true; } - + } ?> \ No newline at end of file diff --git a/lam/templates/ou_edit.php b/lam/templates/ou_edit.php index 76207a73..aa9a2f72 100644 --- a/lam/templates/ou_edit.php +++ b/lam/templates/ou_edit.php @@ -1,4 +1,15 @@ get_ActiveTypes(); - // check if deletion was canceled if (isset($_POST['abort'])) { display_main(null, null); @@ -166,13 +175,14 @@ function display_main($message, $error) { $container->addElement($msg, true); } + $typeManager = new \LAM\TYPES\TypeManager(); + $typeList = $typeManager->getConfiguredTypes(); $types = array(); - $typeList = $_SESSION['config']->get_ActiveTypes(); - for ($i = 0; $i < sizeof($typeList); $i++) { - if (isAccountTypeHidden($typeList[$i]) || !checkIfWriteAccessIsAllowed($typeList[$i])) { + foreach ($typeList as $type) { + if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) { continue; } - $types[$typeList[$i]] = LAM\TYPES\getTypeAlias($typeList[$i]); + $types[$type->getId()] = $type->getAlias(); } natcasesort($types); $options = array(); From cbdd69f7f64d8570d250dba550526e7380c8c583 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 19:11:05 +0100 Subject: [PATCH 8/9] new type API --- lam/lib/tools/fileUpload.inc | 5 +-- lam/lib/tools/multiEdit.inc | 51 +++++++++++++++--------------- lam/lib/tools/schemaBrowser.inc | 49 +++++++++++++++-------------- lam/lib/tools/serverInfo.inc | 51 +++++++++++++++--------------- lam/lib/tools/tests.inc | 55 +++++++++++++++++---------------- lam/templates/multiEdit.php | 28 +++++++++++++++-- 6 files changed, 133 insertions(+), 106 deletions(-) diff --git a/lam/lib/tools/fileUpload.inc b/lam/lib/tools/fileUpload.inc index a2943cee..8839b736 100644 --- a/lam/lib/tools/fileUpload.inc +++ b/lam/lib/tools/fileUpload.inc @@ -1,9 +1,10 @@ \ No newline at end of file diff --git a/lam/lib/tools/schemaBrowser.inc b/lam/lib/tools/schemaBrowser.inc index dbe9b38e..0a9d7b4b 100644 --- a/lam/lib/tools/schemaBrowser.inc +++ b/lam/lib/tools/schemaBrowser.inc @@ -1,4 +1,5 @@ \ No newline at end of file diff --git a/lam/lib/tools/serverInfo.inc b/lam/lib/tools/serverInfo.inc index 4f979f90..f65c1a36 100644 --- a/lam/lib/tools/serverInfo.inc +++ b/lam/lib/tools/serverInfo.inc @@ -1,20 +1,21 @@ \ No newline at end of file diff --git a/lam/lib/tools/tests.inc b/lam/lib/tools/tests.inc index f0a8be2f..e9ff660d 100644 --- a/lam/lib/tools/tests.inc +++ b/lam/lib/tools/tests.inc @@ -1,20 +1,21 @@ name = _("Lamdaemon test"); $lamdaemonTest->link = 'tests/lamdaemonTest.php'; $lamdaemonTest->description = _("Check if quotas and homedirectories can be managed."); $lamdaemonTest->image = 'lamdaemonSmall.png'; $return[] = $lamdaemonTest; - $schemaTest = new LAMSubTool(); + $schemaTest = new \LAMSubTool(); $schemaTest->name = _("Schema test"); $schemaTest->link = 'tests/schemaTest.php'; $schemaTest->description = _("Check if the LDAP schema fits the requirements of the selected account modules."); @@ -120,7 +121,7 @@ class toolTests implements LAMTool { $return[] = $schemaTest; return $return; } - + /** * Returns if the tool is visible in the menu. * @@ -129,16 +130,16 @@ class toolTests implements LAMTool { function isVisible() { return (sizeof($_SESSION['config']->get_ActiveTypes()) > 0); } - + /** * Returns if a tool may be hidden by configuration in the LAM server profile. - * + * * @return boolean hideable */ function isHideable() { return true; } - + } ?> \ No newline at end of file diff --git a/lam/templates/multiEdit.php b/lam/templates/multiEdit.php index 22547ba6..274d0ce9 100644 --- a/lam/templates/multiEdit.php +++ b/lam/templates/multiEdit.php @@ -1,4 +1,22 @@ addElement(new htmlOutputText(_('LDAP suffix'))); $suffixGroup = new htmlTable(); - $types = $_SESSION['config']->get_ActiveTypes(); + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); $suffixes = array(); foreach ($types as $type) { - $suffixes[LAM\TYPES\getTypeAlias($type)] = $_SESSION['config']->get_Suffix($type); - $hideRules[$_SESSION['config']->get_Suffix($type)] = array('otherSuffix'); + if ($type->isHidden()) { + continue; + } + $suffixes[$type->getAlias()] = $type->getSuffix(); + $hideRules[$type->getSuffix()] = array('otherSuffix'); } $treeSuffix = $_SESSION['config']->get_Suffix('tree'); if (!empty($treeSuffix)) { From 294ab941b1b179e850af7b1a0a4bf990bb951619 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 26 Dec 2016 19:28:34 +0100 Subject: [PATCH 9/9] new type API --- lam/lib/tools/fileUpload.inc | 4 +++- lam/lib/tools/ouEditor.inc | 4 +++- lam/lib/tools/pdfEdit.inc | 4 +++- lam/lib/tools/profileEditor.inc | 4 +++- lam/lib/tools/tests.inc | 4 +++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lam/lib/tools/fileUpload.inc b/lam/lib/tools/fileUpload.inc index 8839b736..e0f108cf 100644 --- a/lam/lib/tools/fileUpload.inc +++ b/lam/lib/tools/fileUpload.inc @@ -115,7 +115,9 @@ class toolFileUpload implements \LAMTool { * @return boolean visible */ function isVisible() { - return (sizeof($_SESSION['config']->get_ActiveTypes()) > 0); + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); + return (sizeof($types) > 0); } /** diff --git a/lam/lib/tools/ouEditor.inc b/lam/lib/tools/ouEditor.inc index 5f49143f..4c8c3ef4 100644 --- a/lam/lib/tools/ouEditor.inc +++ b/lam/lib/tools/ouEditor.inc @@ -115,7 +115,9 @@ class toolOUEditor implements \LAMTool { * @return boolean visible */ function isVisible() { - return (sizeof($_SESSION['config']->get_ActiveTypes()) > 0); + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); + return (sizeof($types) > 0); } /** diff --git a/lam/lib/tools/pdfEdit.inc b/lam/lib/tools/pdfEdit.inc index ed321650..584cd429 100644 --- a/lam/lib/tools/pdfEdit.inc +++ b/lam/lib/tools/pdfEdit.inc @@ -115,7 +115,9 @@ class toolPDFEditor implements \LAMTool { * @return boolean visible */ function isVisible() { - return (sizeof($_SESSION['config']->get_ActiveTypes()) > 0); + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); + return (sizeof($types) > 0); } /** diff --git a/lam/lib/tools/profileEditor.inc b/lam/lib/tools/profileEditor.inc index 36f88eed..d75fb953 100644 --- a/lam/lib/tools/profileEditor.inc +++ b/lam/lib/tools/profileEditor.inc @@ -115,7 +115,9 @@ class toolProfileEditor implements \LAMTool { * @return boolean visible */ function isVisible() { - return (sizeof($_SESSION['config']->get_ActiveTypes()) > 0); + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); + return (sizeof($types) > 0); } /** diff --git a/lam/lib/tools/tests.inc b/lam/lib/tools/tests.inc index e9ff660d..c2cc4d61 100644 --- a/lam/lib/tools/tests.inc +++ b/lam/lib/tools/tests.inc @@ -128,7 +128,9 @@ class toolTests implements \LAMTool { * @return boolean visible */ function isVisible() { - return (sizeof($_SESSION['config']->get_ActiveTypes()) > 0); + $typeManager = new \LAM\TYPES\TypeManager(); + $types = $typeManager->getConfiguredTypes(); + return (sizeof($types) > 0); } /**