public function testSendWithEmailAddress() { $en = new Mail($this->container); $p = new Project($this->container); $tf = new TaskFinder($this->container); $tc = new TaskCreation($this->container); $u = new User($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost'))); $this->container['emailClient'] = $this->getMockBuilder('\\Kanboard\\Core\\Mail\\Client')->setConstructorArgs(array($this->container))->setMethods(array('send'))->getMock(); $this->container['emailClient']->expects($this->once())->method('send')->with($this->equalTo('test@localhost'), $this->equalTo('admin'), $this->equalTo('[test][New task] test (#1)'), $this->stringContains('test')); $en->notifyUser($u->getById(1), Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); }
public function testSuccess() { $userModel = new User($this->container); $projectModel = new Project($this->container); $taskCreationModel = new TaskCreation($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->assertTrue($userModel->update(array('id' => 1, 'email' => 'admin@localhost'))); $event = new GenericEvent(array('project_id' => 1, 'task_id' => 1, 'column_id' => 2)); $action = new TaskEmail($this->container); $action->setProjectId(1); $action->setParam('column_id', 2); $action->setParam('user_id', 1); $action->setParam('subject', 'My email subject'); $this->container['emailClient']->expects($this->once())->method('send')->with($this->equalTo('admin@localhost'), $this->equalTo('admin'), $this->equalTo('My email subject'), $this->stringContains('test')); $this->assertTrue($action->execute($event, Task::EVENT_CLOSE)); }
public function testIcalEventsWithAssigneeAndDueDate() { $dp = new DateParser($this->container); $p = new Project($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFilterICalendarFormatter($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')))); $ics = $tf->create()->filterByDueDateRange(strtotime('-1 month'), strtotime('+1 month'))->setFullDay()->setCalendar(new Calendar('Kanboard'))->setColumns('date_due')->addFullDayEvents()->format(); $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;CN=admin:MAILTO:bob@localhost', $ics); $this->assertContains('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE', $ics); }
public function testUpdate() { $u = new User($this->container); $this->assertEquals(2, $u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto'))); $this->assertEquals(3, $u->create(array('username' => 'plop', 'gitlab_id' => '123'))); $this->assertTrue($u->update(array('id' => 2, 'username' => 'biloute'))); $this->assertTrue($u->update(array('id' => 3, 'gitlab_id' => ''))); $user = $u->getById(2); $this->assertNotFalse($user); $this->assertTrue(is_array($user)); $this->assertEquals('biloute', $user['username']); $this->assertEquals('Toto', $user['name']); $this->assertEquals(Role::APP_USER, $user['role']); $this->assertEquals(0, $user['is_ldap_user']); $user = $u->getById(3); $this->assertNotEmpty($user); $this->assertEquals(null, $user['gitlab_id']); }
public function testTaskClose() { $action = new TaskEmail($this->container, 1, Task::EVENT_CLOSE); $action->setParam('column_id', 2); $action->setParam('user_id', 1); $action->setParam('subject', 'My email subject'); // We create a task in the first column $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $p = new Project($this->container); $u = new User($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1))); $this->assertTrue($u->update(array('id' => 1, 'email' => 'admin@localhost'))); // We create an event $event = array('project_id' => 1, 'task_id' => 1, 'column_id' => 2); // Email should be sent $this->container['emailClient']->expects($this->once())->method('send')->with($this->equalTo('admin@localhost'), $this->equalTo('admin'), $this->equalTo('My email subject'), $this->stringContains('test')); // Our event should be executed $this->assertTrue($action->execute(new GenericEvent($event))); }
public function testSendNotifications() { $u = new User($this->container); $n = new UserNotification($this->container); $p = new Project($this->container); $tc = new TaskCreation($this->container); $tf = new TaskFinder($this->container); $pp = new ProjectPermission($this->container); $this->assertEquals(1, $p->create(array('name' => 'UnitTest1', 'is_everybody_allowed' => 1))); $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1))); $this->assertTrue($u->update(array('id' => 1, 'email' => 'test@localhost'))); $this->assertTrue($pp->isEverybodyAllowed(1)); $n->saveSettings(1, array('notifications_enabled' => 1, 'notifications_filter' => UserNotificationFilter::FILTER_NONE, 'notification_types' => array('web' => 1, 'email' => 1))); $notifier = $this->getMockBuilder('Stdclass')->setMethods(array('notifyUser'))->getMock(); $notifier->expects($this->exactly(2))->method('notifyUser'); $this->container['userNotificationType']->expects($this->at(0))->method('getSelectedTypes')->will($this->returnValue(array('email', 'web'))); $this->container['userNotificationType']->expects($this->at(1))->method('getType')->with($this->equalTo('email'))->will($this->returnValue($notifier)); $this->container['userNotificationType']->expects($this->at(2))->method('getType')->with($this->equalTo('web'))->will($this->returnValue($notifier)); $n->sendNotifications(Task::EVENT_CREATE, array('task' => $tf->getDetails(1))); }