diff --git a/lng/english.lng.php b/lng/english.lng.php index 507799e7..d514eddc 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -226,7 +226,7 @@ $lng['error']['emailexistalready'] = 'The email-address %s already exists.'; $lng['error']['maindomainnonexist'] = 'The main-domain %s does not exist.'; $lng['error']['destinationnonexist'] = 'Please create your forwarder in the field \'Destination\'.'; $lng['error']['destinationalreadyexistasmail'] = 'The forwarder to %s already exists as active email-address.'; -$lng['error']['destinationalreadyexist'] = 'You have already defined a forwarder to %s .'; +$lng['error']['destinationalreadyexist'] = 'You have already defined a forwarder to "%s"'; $lng['error']['destinationiswrong'] = 'The forwarder %s contains invalid character(s) or is incomplete.'; $lng['error']['ticketnotaccessible'] = 'You cannot access this ticket.'; diff --git a/tests/Emails/EmailsTest.php b/tests/Emails/EmailsTest.php index 77f71c12..73287358 100644 --- a/tests/Emails/EmailsTest.php +++ b/tests/Emails/EmailsTest.php @@ -5,9 +5,12 @@ use PHPUnit\Framework\TestCase; * @covers ApiCommand * @covers ApiParameter * @covers Emails + * @covers EmailForwarders + * @covers EmailAccounts */ class MailsTest extends TestCase { + public function testCustomerEmailsAdd() { global $admin_userdata; @@ -27,7 +30,7 @@ class MailsTest extends TestCase $this->assertEquals("info@test2.local", $result['email_full']); $this->assertEquals(0, $result['iscatchall']); } - + public function testAdminEmailsAdd() { global $admin_userdata; @@ -42,4 +45,199 @@ class MailsTest extends TestCase $this->assertEquals("catchall@test2.local", $result['email_full']); $this->assertEquals(1, $result['iscatchall']); } + + public function testAdminEmailsUpdate() + { + global $admin_userdata; + $data = [ + 'emailaddr' => 'catchall@test2.local', + 'iscatchall' => 0, + 'customerid' => 1 + ]; + $json_result = Emails::getLocal($admin_userdata, $data)->update(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals(0, $result['iscatchall']); + } + + public function testCustomerEmailsUpdate() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'catchall@test2.local', + 'iscatchall' => 1 + ]; + $json_result = Emails::getLocal($customer_userdata, $data)->update(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals(1, $result['iscatchall']); + } + + public function testCustomerEmailForwardersAdd() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'destination' => 'other@domain.tld' + ]; + $json_result = EmailForwarders::getLocal($customer_userdata, $data)->add(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('other@domain.tld', $result['destination']); + } + + public function testCustomerEmailForwardersAddAnother() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'destination' => 'other2@domain.tld' + ]; + $json_result = EmailForwarders::getLocal($customer_userdata, $data)->add(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('other@domain.tld other2@domain.tld', $result['destination']); + } + + /** + * @depends testCustomerEmailForwardersAdd + */ + public function testCustomerEmailForwardersAddExistingAsMail() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'destination' => 'info@test2.local' + ]; + $this->expectExceptionMessage("The forwarder to info@test2.local already exists as active email-address."); + EmailForwarders::getLocal($customer_userdata, $data)->add(); + } + + /** + * @depends testCustomerEmailForwardersAdd + */ + public function testCustomerEmailForwardersAddExistingAsDestination() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'destination' => 'other@domain.tld' + ]; + $this->expectExceptionMessage('You have already defined a forwarder to "other@domain.tld"'); + EmailForwarders::getLocal($customer_userdata, $data)->add(); + } + + public function testCustomerEmailForwardersAddInvalid() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'destination' => '@domain.com' + ]; + $this->expectExceptionMessage("The forwarder domain.com contains invalid character(s) or is incomplete."); + EmailForwarders::getLocal($customer_userdata, $data)->add(); + } + + public function testAdminEmailForwadersUndefinedGet() + { + global $admin_userdata; + $this->expectExceptionCode(303); + EmailForwarders::getLocal($admin_userdata)->get(); + } + + public function testAdminEmailForwadersUndefinedUpdate() + { + global $admin_userdata; + $this->expectExceptionCode(303); + EmailForwarders::getLocal($admin_userdata)->update(); + } + + public function testAdminEmailForwadersUndefinedListing() + { + global $admin_userdata; + $this->expectExceptionCode(303); + EmailForwarders::getLocal($admin_userdata)->listing(); + } + + /** + * @depends testCustomerEmailForwardersAddAnother + */ + public function testCustomerEmailForwardersDelete() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'forwarderid' => 1 + ]; + $json_result = EmailForwarders::getLocal($customer_userdata, $data)->delete(); + $result = json_decode($json_result, true)['data']; + $this->assertEquals('other@domain.tld', $result['destination']); + } + + /** + * @depends testCustomerEmailForwardersAddAnother + */ + public function testCustomerEmailForwardersDeleteunknown() + { + global $admin_userdata; + + // get customer + $json_result = Customers::getLocal($admin_userdata, array( + 'loginname' => 'test1' + ))->get(); + $customer_userdata = json_decode($json_result, true)['data']; + + $data = [ + 'emailaddr' => 'info@test2.local', + 'forwarderid' => 1337 + ]; + $this->expectExceptionCode(404); + $this->expectExceptionMessage("Unknown forwarder id"); + EmailForwarders::getLocal($customer_userdata, $data)->delete(); + } }