From 79ee5f82cb65984f4818b23df833cc09ba8e34dd Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Mon, 2 Mar 2020 09:55:44 +0000 Subject: [PATCH] add a far better MailboxHandler test case --- tests/MailboxHandlerTest.php | 115 ++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 2 deletions(-) diff --git a/tests/MailboxHandlerTest.php b/tests/MailboxHandlerTest.php index a6b53012..98b69079 100644 --- a/tests/MailboxHandlerTest.php +++ b/tests/MailboxHandlerTest.php @@ -1,6 +1,14 @@ assertTrue($list); - $results = $x->result(); $this->assertEmpty($results); $this->assertFalse($x->checkPasswordRecoveryCode('test', 'fake')); - $token = $x->getPasswordRecoveryCode('test.peraon.does.not.exist@example.com'); + $token = $x->getPasswordRecoveryCode('test.person.does.not.exist@example.com'); $this->assertFalse($token); } + + + public function testAddingDataEtc() { + + // Fake being an admin. + $_SESSION = [ + 'sessid' => [ + 'roles' => ['global-admin'] + ] + ]; + // Add example.com + $dh = new DomainHandler(1, 'admin', true); + + $dh->init('example.com'); + + $ret = $dh->set( + [ + 'domain' => 'example.com', + 'description' => 'test domain', + 'aliases' => 11, + 'mailboxes' => 12, + 'active' => 1, + 'backupmx' => 0, + 'default_aliases' => 1 + ] + ); + + + $this->assertEmpty($dh->errormsg); + $this->assertEmpty($dh->infomsg); + + $this->assertTrue($ret); + + $ret = $dh->store(); + + $this->assertTrue($ret); + + // Need to add 'admin' as a domain_admin + db_insert('domain_admins', ['username' => 'admin', 'domain' => 'example.com', 'created' => '2020-01-01', 'active' => 1], ['created'], true); + + $dh = new DomainHandler(0, 'admin', true); + $dh->getList(''); + $result = $dh->result(); + + $this->assertEmpty($dh->infomsg); + $this->assertEmpty($dh->errormsg); + + $this->assertNotEmpty($result); + + $this->assertEquals('example.com', $result['example.com']['domain']); + $this->assertEquals('test domain', $result['example.com']['description']); + + $this->assertEquals(11, $result['example.com']['aliases']); + $this->assertEquals(12, $result['example.com']['mailboxes']); // default aliases. + + $this->assertEquals(4, $result['example.com']['alias_count']); // default aliases. + $this->assertEquals(0, $result['example.com']['mailbox_count']); + $this->assertEquals(1, $result['example.com']['active']); + + $x = new MailboxHandler(1, 'admin', true); + + $values = [ + 'localpart' => 'david.test', + 'domain' => 'example.com', + 'active' => 1, + 'password' => 'test1234', + 'password2' => 'test1234', + 'name' => 'test person', + 'quota' => '', + 'welcome_mail' => 0, + 'email_other' => '', + 'username' => 'david.test@example.com', + + ]; + + $r = $x->init('david.test@example.com'); + $this->assertTrue($r); + $x->getList(''); + $list = $x->result(); + $this->assertEquals(0, count($list)); + + $x->set($values); + $x->store(); + + $x->getList(''); + + $list = $x->result(); + $this->assertEquals(1, count($list)); + + $found = false; + + foreach ($list as $alias => $details) { + if ($alias == 'david.test@example.com') { + // Found! + $this->assertEquals('example.com', $details['domain']); + $this->assertEquals('david.test@example.com', $details['username']); + $this->assertEquals('test person', $details['name']); + $found = true; + break; + } + } + + $this->assertTrue($found, "check output : " . json_encode($list)); + } } /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */