summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-06-01 21:28:24 -0400
committerFrederic Guillot <fred@kanboard.net>2016-06-01 21:28:24 -0400
commitc50255813b1f2de3709b17492d32c9e4ce280236 (patch)
treebac9a31956c558526e831c05c74ef03c676e453b
parentca87b1b60f9b4b49c80920e5009d6fbe4e3fb514 (diff)
Added mail helper
-rw-r--r--app/Core/Helper.php1
-rw-r--r--app/Core/Tool.php20
-rw-r--r--app/Helper/MailHelper.php48
-rw-r--r--app/Model/SwimlaneModel.php16
-rw-r--r--app/ServiceProvider/HelperProvider.php1
-rw-r--r--tests/units/Core/ToolTest.php15
-rw-r--r--tests/units/Helper/MailHelperTest.php24
-rw-r--r--tests/units/Model/SwimlaneTest.php13
8 files changed, 103 insertions, 35 deletions
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
@@ -13,26 +13,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
*
* @static
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 @@
+<?php
+
+namespace Kanboard\Helper;
+
+use Kanboard\Core\Base;
+
+/**
+ * Class MailHelper
+ *
+ * @package Kanboard\Helper
+ * @author Frederic Guillot
+ */
+class MailHelper extends Base
+{
+ /**
+ * Get the mailbox hash from an email address
+ *
+ * @access public
+ * @param string $email
+ * @return string
+ */
+ public function getMailboxHash($email)
+ {
+ if (! strpos($email, '@') || ! strpos($email, '+')) {
+ return '';
+ }
+
+ list($localPart, ) = explode('@', $email);
+ list(, $identifier) = explode('+', $localPart);
+
+ return $identifier;
+ }
+
+ /**
+ * Filter mail subject
+ *
+ * @access public
+ * @param string $subject
+ * @return string
+ */
+ public function filterSubject($subject)
+ {
+ $subject = str_replace('RE: ', '', $subject);
+ $subject = str_replace('FW: ', '', $subject);
+
+ return $subject;
+ }
+}
diff --git a/app/Model/SwimlaneModel.php b/app/Model/SwimlaneModel.php
index 87591b99..35e39879 100644
--- a/app/Model/SwimlaneModel.php
+++ b/app/Model/SwimlaneModel.php
@@ -90,6 +90,22 @@ class SwimlaneModel extends Base
}
/**
+ * 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
*
* @access public
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 @@
-<?php
-
-require_once __DIR__.'/../Base.php';
-
-use Kanboard\Core\Tool;
-
-class ToolTest extends Base
-{
- public function testMailboxHash()
- {
- $this->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 @@
+<?php
+
+require_once __DIR__.'/../Base.php';
+
+use Kanboard\Helper\MailHelper;
+
+class MailHelperTest extends Base
+{
+ public function testMailboxHash()
+ {
+ $helper = new MailHelper($this->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);