diff options
-rw-r--r-- | app/Core/Helper.php | 32 | ||||
-rw-r--r-- | app/Helper/Url.php | 4 | ||||
-rw-r--r-- | app/Model/TaskFilter.php | 6 | ||||
-rw-r--r-- | tests/units/Base.php | 2 | ||||
-rw-r--r-- | tests/units/TaskFilterTest.php | 51 | ||||
-rw-r--r-- | tests/units/UrlHelperTest.php | 12 |
6 files changed, 94 insertions, 13 deletions
diff --git a/app/Core/Helper.php b/app/Core/Helper.php index 53084a7e..e4f225b0 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -2,6 +2,8 @@ namespace Core; +use Pimple\Container; + /** * Helper base class * @@ -19,16 +21,34 @@ namespace Core; * @property \Helper\Url $url * @property \Helper\User $user */ -class Helper extends Base +class Helper { /** * Helper instances * - * @static * @access private * @var array */ - private static $helpers = array(); + private $helpers = array(); + + /** + * Container instance + * + * @access protected + * @var \Pimple\Container + */ + protected $container; + + /** + * Constructor + * + * @access public + * @param \Pimple\Container $container + */ + public function __construct(Container $container) + { + $this->container = $container; + } /** * Load automatically helpers @@ -39,12 +59,12 @@ class Helper extends Base */ public function __get($name) { - if (! isset(self::$helpers[$name])) { + if (! isset($this->helpers[$name])) { $class = '\Helper\\'.ucfirst($name); - self::$helpers[$name] = new $class($this->container); + $this->helpers[$name] = new $class($this->container); } - return self::$helpers[$name]; + return $this->helpers[$name]; } /** diff --git a/app/Helper/Url.php b/app/Helper/Url.php index e133f195..8de63f8d 100644 --- a/app/Helper/Url.php +++ b/app/Helper/Url.php @@ -99,6 +99,10 @@ class Url extends \Core\Base */ public function server() { + if (empty($_SERVER['SERVER_NAME'])) { + return 'http://localhost/'; + } + $self = str_replace('\\', '/', dirname($_SERVER['PHP_SELF'])); $url = Request::isHTTPS() ? 'https://' : 'http://'; diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php index c88be830..082318f1 100644 --- a/app/Model/TaskFilter.php +++ b/app/Model/TaskFilter.php @@ -716,11 +716,11 @@ class TaskFilter extends Base $vEvent->setSummary(t('#%d', $task['id']).' '.$task['title']); $vEvent->setUrl($this->helper->url->base().$this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); - if (! empty($task['creator_id'])) { - $vEvent->setOrganizer('MAILTO:'.($task['creator_email'] ?: $task['creator_username'].'@kanboard.local')); + if (! empty($task['owner_id'])) { + $vEvent->setOrganizer('MAILTO:'.($task['assignee_email'] ?: $task['assignee_username'].'@kanboard.local')); } - if (! empty($task['owner_id'])) { + if (! empty($task['creator_id'])) { $attendees = new Attendees; $attendees->add('MAILTO:'.($task['creator_email'] ?: $task['creator_username'].'@kanboard.local')); $vEvent->setAttendees($attendees); diff --git a/tests/units/Base.php b/tests/units/Base.php index 7ad4e626..0a045a09 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -58,6 +58,8 @@ abstract class Base extends PHPUnit_Framework_TestCase public function setUp() { + date_default_timezone_set('UTC'); + if (DB_DRIVER === 'mysql') { $pdo = new PDO('mysql:host='.DB_HOSTNAME, DB_USERNAME, DB_PASSWORD); $pdo->exec('DROP DATABASE '.DB_NAME); diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php index af00b6fa..14a9b1c0 100644 --- a/tests/units/TaskFilterTest.php +++ b/tests/units/TaskFilterTest.php @@ -8,9 +8,60 @@ use Model\TaskFilter; use Model\TaskCreation; use Model\DateParser; use Model\Category; +use Model\Config; class TaskFilterTest extends Base { + public function testIcalEventsWithCreatorAndDueDate() + { + $dp = new DateParser($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFilter($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'creator_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('-2 days')))); + + $events = $tf->create()->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month'))->addAllDayIcalEvents(); + $ics = $events->render(); + + $this->assertContains('UID:task-#1-date_due', $ics); + $this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('-2 days')), $ics); + $this->assertContains('DTEND;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('-2 days')), $ics); + $this->assertContains('URL:http://localhost/?controller=task&action=show&task_id=1&project_id=1', $ics); + $this->assertContains('SUMMARY:#1 task1', $ics); + $this->assertContains('ATTENDEE:MAILTO:admin@kanboard.local', $ics); + $this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics); + } + + public function testIcalEventsWithAssigneeAndDueDate() + { + $dp = new DateParser($this->container); + $p = new Project($this->container); + $tc = new TaskCreation($this->container); + $tf = new TaskFilter($this->container); + $u = new User($this->container); + $c = new Config($this->container); + + $this->assertNotFalse($c->save(array('application_url' => 'http://kb/'))); + $this->assertEquals('http://kb/', $c->get('application_url')); + + $this->assertNotFalse($u->update(array('id' => 1, 'email' => 'bob@localhost'))); + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1', 'owner_id' => 1, 'date_due' => $dp->getTimestampFromIsoFormat('+5 days')))); + + $events = $tf->create()->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month'))->addAllDayIcalEvents(); + $ics = $events->render(); + + $this->assertContains('UID:task-#1-date_due', $ics); + $this->assertContains('DTSTART;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('+5 days')), $ics); + $this->assertContains('DTEND;TZID=UTC;VALUE=DATE:'.date('Ymd', strtotime('+5 days')), $ics); + $this->assertContains('URL:http://kb/?controller=task&action=show&task_id=1&project_id=1', $ics); + $this->assertContains('SUMMARY:#1 task1', $ics); + $this->assertContains('ORGANIZER:MAILTO:bob@localhost', $ics); + $this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics); + } + public function testSearchWithEmptyResult() { $dp = new DateParser($this->container); diff --git a/tests/units/UrlHelperTest.php b/tests/units/UrlHelperTest.php index d70842aa..3ef3402a 100644 --- a/tests/units/UrlHelperTest.php +++ b/tests/units/UrlHelperTest.php @@ -38,22 +38,26 @@ class UrlHelperTest extends Base { $h = new Url($this->container); + $this->assertEquals('http://localhost/', $h->server()); + $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'localhost'; + $_SERVER['SERVER_NAME'] = 'kb'; $_SERVER['SERVER_PORT'] = 1234; - $this->assertEquals('http://localhost:1234/', $h->server()); + $this->assertEquals('http://kb:1234/', $h->server()); } public function testBase() { $h = new Url($this->container); + $this->assertEquals('http://localhost/', $h->base()); + $_SERVER['PHP_SELF'] = '/'; - $_SERVER['SERVER_NAME'] = 'localhost'; + $_SERVER['SERVER_NAME'] = 'kb'; $_SERVER['SERVER_PORT'] = 1234; - $this->assertEquals('http://localhost:1234/', $h->base()); + $this->assertEquals('http://kb:1234/', $h->base()); $c = new Config($this->container); $c->save(array('application_url' => 'https://mykanboard/')); |