only imports conflicted
This commit is contained in:
Lesstat
2015-07-11 11:44:26 +02:00
95 changed files with 2041 additions and 794 deletions

View File

@@ -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);

View File

@@ -56,6 +56,12 @@ class DateParserTest extends Base
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014-03-05')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('2014_03_05')));
$this->assertEquals('2014-03-05', date('Y-m-d', $d->getTimestamp('03/05/2014')));
$this->assertEquals('2014-03-25 17:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18 pm')));
$this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18 am')));
$this->assertEquals('2014-03-25 05:18', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 5:18am')));
$this->assertEquals('2014-03-25 23:14', date('Y-m-d H:i', $d->getTimestamp('03/25/2014 23:14')));
$this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $d->getTimestamp('2014_03_29 23:14')));
$this->assertEquals('2014-03-29 23:14', date('Y-m-d H:i', $d->getTimestamp('2014-03-29 23:14')));
}
public function testConvert()

View File

@@ -2,13 +2,13 @@
require_once __DIR__.'/Base.php';
use Helper\Datetime;
use Helper\Dt;
class DatetimeHelperTest extends Base
{
public function testAge()
{
$h = new Datetime($this->container);
$h = new Dt($this->container);
$this->assertEquals('<15m', $h->age(0, 30));
$this->assertEquals('<30m', $h->age(0, 1000));
@@ -20,7 +20,7 @@ class DatetimeHelperTest extends Base
public function testGetDayHours()
{
$h = new Datetime($this->container);
$h = new Dt($this->container);
$slots = $h->getDayHours();
@@ -36,7 +36,7 @@ class DatetimeHelperTest extends Base
public function testGetWeekDays()
{
$h = new Datetime($this->container);
$h = new Dt($this->container);
$slots = $h->getWeekDays();
@@ -48,7 +48,7 @@ class DatetimeHelperTest extends Base
public function testGetWeekDay()
{
$h = new Datetime($this->container);
$h = new Dt($this->container);
$this->assertEquals('Monday', $h->getWeekDay(1));
$this->assertEquals('Sunday', $h->getWeekDay(7));

View File

@@ -3,17 +3,17 @@
require_once __DIR__.'/Base.php';
use Model\Project;
use Model\ProjectDailySummary;
use Model\ProjectDailyColumnStats;
use Model\Task;
use Model\TaskCreation;
use Model\TaskStatus;
class ProjectDailySummaryTest extends Base
class ProjectDailyColumnStatsTest extends Base
{
public function testUpdateTotals()
{
$p = new Project($this->container);
$pds = new ProjectDailySummary($this->container);
$pds = new ProjectDailyColumnStats($this->container);
$tc = new TaskCreation($this->container);
$ts = new TaskStatus($this->container);

View File

@@ -175,6 +175,28 @@ class TaskCreationTest extends Base
$this->assertEquals(1, $task['creator_id']);
}
public function testThatCreatorIsDefined()
{
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$_SESSION = array();
$_SESSION['user']['id'] = 1;
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertNotFalse($task);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['creator_id']);
$_SESSION = array();
}
public function testColumnId()
{
$p = new Project($this->container);
@@ -284,29 +306,35 @@ class TaskCreationTest extends Base
public function testDateStarted()
{
$date = '2014-11-23';
$timestamp = strtotime('+2days');
$p = new Project($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test')));
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $date)));
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => $timestamp)));
// Set only a date
$this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24')));
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertNotFalse($task);
$this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
$this->assertEquals(1, $task['id']);
$this->assertEquals($date, date('Y-m-d', $task['date_started']));
// Set a datetime
$this->assertEquals(2, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 16:25')));
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertNotFalse($task);
$this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
$this->assertEquals(2, $task['id']);
$this->assertEquals($timestamp, $task['date_started']);
// Set a datetime
$this->assertEquals(3, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '2014-11-24 6:25pm')));
$task = $tf->getById(3);
$this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
// Set a timestamp
$this->assertEquals(4, $tc->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));
$task = $tf->getById(4);
$this->assertEquals(time(), $task['date_started'], '', 1);
}
public function testTime()

View File

@@ -15,6 +15,36 @@ use Model\Swimlane;
class TaskDuplicationTest extends Base
{
public function testThatDuplicateDefineCreator()
{
$td = new TaskDuplication($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'test1')));
$this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
$task = $tf->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['position']);
$this->assertEquals(1, $task['project_id']);
$this->assertEquals(0, $task['creator_id']);
$_SESSION = array();
$_SESSION['user']['id'] = 1;
// We duplicate our task
$this->assertEquals(2, $td->duplicate(1));
// Check the values of the duplicated task
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(1, $task['creator_id']);
$_SESSION = array();
}
public function testDuplicateSameProject()
{
$td = new TaskDuplication($this->container);

View File

@@ -9,9 +9,60 @@ use Model\TaskCreation;
use Model\DateParser;
use Model\Category;
use Model\Subtask;
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);
@@ -441,19 +492,13 @@ class TaskFilterTest extends Base
$this->assertEquals('my task title is awesome', $tasks[0]['title']);
$this->assertEquals('my task title is amazing', $tasks[1]['title']);
$tf->search('assignee:nobody');
$tasks = $tf->findAll();
$this->assertNotEmpty($tasks);
$this->assertCount(1, $tasks);
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
$this->assertEquals('my task title is amazing', $tasks[0]['title']);
}
public function testCopy()
{
$tf = new TaskFilter($this->container);

View File

@@ -202,15 +202,29 @@ class TaskModificationTest extends Base
$task = $tf->getById(1);
$this->assertEquals(0, $task['date_started']);
// Set only a date
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24')));
$task = $tf->getById(1);
$this->assertEquals('2014-11-24', date('Y-m-d', $task['date_started']));
$this->assertEquals('2014-11-24 '.date('H:i'), date('Y-m-d H:i', $task['date_started']));
// Set a datetime
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24 16:25')));
$task = $tf->getById(1);
$this->assertEquals('2014-11-24 16:25', date('Y-m-d H:i', $task['date_started']));
// Set a datetime
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => '2014-11-24 6:25pm')));
$task = $tf->getById(1);
$this->assertEquals('2014-11-24 18:25', date('Y-m-d H:i', $task['date_started']));
// Set a timestamp
$this->assertTrue($tm->update(array('id' => 1, 'date_started' => time())));
$task = $tf->getById(1);
$this->assertEquals(date('Y-m-d'), date('Y-m-d', $task['date_started']));
$this->assertEquals(time(), $task['date_started'], '', 1);
}
public function testChangeTimeEstimated()

View File

@@ -11,49 +11,88 @@ use Model\Swimlane;
class TaskPositionTest extends Base
{
public function testCalculatePositionBadPosition()
public function testMoveTaskToWrongPosition()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$this->assertFalse($tp->calculatePositions(1, 1, 2, 0));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 0
$this->assertFalse($tp->movePosition(1, 1, 3, 0));
// Check tasks position
$task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
$task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
}
public function testCalculatePositionBadColumn()
public function testMoveTaskToGreaterPosition()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$this->assertFalse($tp->calculatePositions(1, 1, 10, 1));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the position 42
$this->assertTrue($tp->movePosition(1, 1, 1, 42));
// Check tasks position
$task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(2, $task['position']);
$task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
}
public function testCalculatePositions()
public function testMoveTaskToEmptyColumn()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1)));
$positions = $tp->calculatePositions(1, 1, 2, 1);
$this->assertNotFalse($positions);
$this->assertNotEmpty($positions);
$this->assertEmpty($positions[1]);
$this->assertEmpty($positions[3]);
$this->assertEmpty($positions[4]);
$this->assertEquals(array(1), $positions[2]);
$this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'column_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1, 'column_id' => 1)));
// We move the task 2 to the column 3
$this->assertTrue($tp->movePosition(1, 1, 3, 1));
// Check tasks position
$task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(3, $task['column_id']);
$this->assertEquals(1, $task['position']);
$task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(1, $task['column_id']);
$this->assertEquals(1, $task['position']);
}
public function testMoveTaskWithColumnThatNotChange()
public function testMoveTaskToAnotherColumn()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
@@ -116,40 +155,6 @@ class TaskPositionTest extends Base
$this->assertEquals(3, $task['position']);
}
public function testMoveTaskWithBadPreviousPosition()
{
$tp = new TaskPosition($this->container);
$tc = new TaskCreation($this->container);
$tf = new TaskFinder($this->container);
$p = new Project($this->container);
$this->assertEquals(1, $p->create(array('name' => 'Project #1')));
$this->assertEquals(1, $this->container['db']->table('tasks')->insert(array('title' => 'A', 'column_id' => 1, 'project_id' => 1, 'position' => 1)));
// Both tasks have the same position
$this->assertEquals(2, $this->container['db']->table('tasks')->insert(array('title' => 'B', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
$this->assertEquals(3, $this->container['db']->table('tasks')->insert(array('title' => 'C', 'column_id' => 2, 'project_id' => 1, 'position' => 1)));
// Move the first column to the last position of the 2nd column
$this->assertTrue($tp->movePosition(1, 1, 2, 3));
// Check tasks position
$task = $tf->getById(2);
$this->assertEquals(2, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(1, $task['position']);
$task = $tf->getById(3);
$this->assertEquals(3, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(2, $task['position']);
$task = $tf->getById(1);
$this->assertEquals(1, $task['id']);
$this->assertEquals(2, $task['column_id']);
$this->assertEquals(3, $task['position']);
}
public function testMoveTaskTop()
{
$tp = new TaskPosition($this->container);

View File

@@ -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/'));