From c50255813b1f2de3709b17492d32c9e4ce280236 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 1 Jun 2016 21:28:24 -0400 Subject: Added mail helper --- app/Core/Helper.php | 1 + app/Core/Tool.php | 20 -------------- app/Helper/MailHelper.php | 48 ++++++++++++++++++++++++++++++++++ app/Model/SwimlaneModel.php | 16 ++++++++++++ app/ServiceProvider/HelperProvider.php | 1 + tests/units/Core/ToolTest.php | 15 ----------- tests/units/Helper/MailHelperTest.php | 24 +++++++++++++++++ tests/units/Model/SwimlaneTest.php | 13 +++++++++ 8 files changed, 103 insertions(+), 35 deletions(-) create mode 100644 app/Helper/MailHelper.php delete mode 100644 tests/units/Core/ToolTest.php create mode 100644 tests/units/Helper/MailHelperTest.php diff --git a/app/Core/Helper.php b/app/Core/Helper.php index f34b6190..43151be8 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -27,6 +27,7 @@ use Pimple\Container; * @property \Kanboard\Helper\LayoutHelper $layout * @property \Kanboard\Helper\ProjectHeaderHelper $projectHeader * @property \Kanboard\Helper\ProjectActivityHelper $projectActivity + * @property \Kanboard\Helper\MailHelper $mail */ class Helper { diff --git a/app/Core/Tool.php b/app/Core/Tool.php index 3423998d..bfa6c955 100644 --- a/app/Core/Tool.php +++ b/app/Core/Tool.php @@ -12,26 +12,6 @@ use Pimple\Container; */ class Tool { - /** - * Get the mailbox hash from an email address - * - * @static - * @access public - * @param string $email - * @return string - */ - public static function getMailboxHash($email) - { - if (! strpos($email, '@') || ! strpos($email, '+')) { - return ''; - } - - list($local_part, ) = explode('@', $email); - list(, $identifier) = explode('+', $local_part); - - return $identifier; - } - /** * Build dependency injection container from an array * diff --git a/app/Helper/MailHelper.php b/app/Helper/MailHelper.php new file mode 100644 index 00000000..6c7eeff0 --- /dev/null +++ b/app/Helper/MailHelper.php @@ -0,0 +1,48 @@ +findOne(); } + /** + * Get first active swimlane for a project + * + * @access public + * @param integer $project_id + * @return array + */ + public function getFirstActiveSwimlane($project_id) + { + return $this->db->table(self::TABLE) + ->eq('is_active', self::ACTIVE) + ->eq('project_id', $project_id) + ->orderBy('position', 'asc') + ->findOne(); + } + /** * Get default swimlane properties * diff --git a/app/ServiceProvider/HelperProvider.php b/app/ServiceProvider/HelperProvider.php index 114212d2..a909e3cf 100644 --- a/app/ServiceProvider/HelperProvider.php +++ b/app/ServiceProvider/HelperProvider.php @@ -37,6 +37,7 @@ class HelperProvider implements ServiceProviderInterface $container['helper']->register('avatar', '\Kanboard\Helper\AvatarHelper'); $container['helper']->register('projectHeader', '\Kanboard\Helper\ProjectHeaderHelper'); $container['helper']->register('projectActivity', '\Kanboard\Helper\ProjectActivityHelper'); + $container['helper']->register('mail', '\Kanboard\Helper\MailHelper'); $container['template'] = new Template($container['helper']); diff --git a/tests/units/Core/ToolTest.php b/tests/units/Core/ToolTest.php deleted file mode 100644 index 2422d73c..00000000 --- a/tests/units/Core/ToolTest.php +++ /dev/null @@ -1,15 +0,0 @@ -assertEquals('test1', Tool::getMailboxHash('a+test1@localhost')); - $this->assertEquals('', Tool::getMailboxHash('test1@localhost')); - $this->assertEquals('', Tool::getMailboxHash('test1')); - } -} diff --git a/tests/units/Helper/MailHelperTest.php b/tests/units/Helper/MailHelperTest.php new file mode 100644 index 00000000..9975dd29 --- /dev/null +++ b/tests/units/Helper/MailHelperTest.php @@ -0,0 +1,24 @@ +container); + $this->assertEquals('test1', $helper->getMailboxHash('a+test1@localhost')); + $this->assertEquals('', $helper->getMailboxHash('test1@localhost')); + $this->assertEquals('', $helper->getMailboxHash('test1')); + } + + public function testFilterSubject() + { + $helper = new MailHelper($this->container); + $this->assertEquals('Test', $helper->filterSubject('Test')); + $this->assertEquals('Test', $helper->filterSubject('RE: Test')); + $this->assertEquals('Test', $helper->filterSubject('FW: Test')); + } +} diff --git a/tests/units/Model/SwimlaneTest.php b/tests/units/Model/SwimlaneTest.php index 2594b17a..cf0be169 100644 --- a/tests/units/Model/SwimlaneTest.php +++ b/tests/units/Model/SwimlaneTest.php @@ -30,6 +30,19 @@ class SwimlaneTest extends Base $this->assertEquals('', $s->getNameById(23)); } + public function testGetFirstActiveSwimlane() + { + $projectModel = new ProjectModel($this->container); + $swimlaneModel = new SwimlaneModel($this->container); + + $this->assertEquals(1, $projectModel->create(array('name' => 'UnitTest'))); + $this->assertEquals(1, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #1', 'is_active' => 0))); + $this->assertEquals(2, $swimlaneModel->create(array('project_id' => 1, 'name' => 'Swimlane #2'))); + + $swimlane = $swimlaneModel->getFirstActiveSwimlane(1); + $this->assertEquals(2, $swimlane['id']); + } + public function testGetList() { $p = new ProjectModel($this->container); -- cgit v1.2.3