public function testNotifyProjectWithWebhookNotConfigured() { $this->container['httpClient']->expects($this->never())->method('postFormAsync'); $projectModel = new ProjectModel($this->container); $taskCreationModel = new TaskCreationModel($this->container); $taskFinderModel = new TaskFinderModel($this->container); $handler = new RocketChat($this->container); $this->assertEquals(1, $projectModel->create(array('name' => 'test'))); $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); $this->container['projectMetadataModel']->save(1, array('rocketchat_webhook_url' => '')); $project = $projectModel->getById(1); $task = $taskFinderModel->getDetails(1); $event = array('task' => $task); $event['task']['task_id'] = $task['id']; $handler->notifyProject($project, TaskModel::EVENT_MOVE_COLUMN, $event); }
public function testHandlePush() { $this->container['dispatcher']->addListener(WebhookHandler::EVENT_COMMIT, array($this, 'onCommit')); $tc = new TaskCreationModel($this->container); $p = new ProjectModel($this->container); $handler = new WebhookHandler($this->container); $payload = json_decode(file_get_contents(__DIR__ . '/fixtures/push.json'), true); $this->assertEquals(1, $p->create(array('name' => 'test'))); $handler->setProjectId(1); // No task $this->assertFalse($handler->parsePayload('push', $payload)); // Create task with the wrong id $this->assertEquals(1, $tc->create(array('title' => 'test1', 'project_id' => 1))); $this->assertFalse($handler->parsePayload('push', $payload)); // Create task with the right id $this->assertEquals(2, $tc->create(array('title' => 'test2', 'project_id' => 1))); $this->assertTrue($handler->parsePayload('push', $payload)); $called = $this->container['dispatcher']->getCalledListeners(); $this->assertArrayHasKey(WebhookHandler::EVENT_COMMIT . '.WebhookHandlerTest::onCommit', $called); }
public function testCommentCreatedWithUser() { $this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_COMMENT, array($this, 'onCommentCreatedWithUser')); $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'foobar'))); $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 1268888, 'project_id' => 1))); $u = new UserModel($this->container); $this->assertEquals(2, $u->create(array('username' => 'kanboard'))); $pp = new ProjectUserRoleModel($this->container); $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $g = new WebhookHandler($this->container); $g->setProjectId(1); $this->assertNotFalse($g->parsePayload(json_decode(file_get_contents(__DIR__ . '/fixtures/gitlab_comment_created.json'), true))); }
public function testPush() { $this->container['dispatcher']->addListener(WebhookHandler::EVENT_COMMIT, array($this, 'onPush')); $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'foobar'))); $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $tc->create(array('title' => 'boo', 'project_id' => 1))); $g = new WebhookHandler($this->container); $g->setProjectId(1); $this->assertNotFalse($g->parsePayload('push', json_decode(file_get_contents(__DIR__ . '/fixtures/github_push.json'), true))); }
public function testIssueAssignedWithNoTask() { $this->container['dispatcher']->addListener(WebhookHandler::EVENT_ISSUE_ASSIGNEE_CHANGE, function () { }); $p = new ProjectModel($this->container); $this->assertEquals(1, $p->create(array('name' => 'foobar'))); $tc = new TaskCreationModel($this->container); $this->assertEquals(1, $tc->create(array('title' => 'boo', 'reference' => 43, 'project_id' => 1))); $g = new WebhookHandler($this->container); $g->setProjectId(1); $this->assertFalse($g->parsePayload('issue:updated', json_decode(file_get_contents(__DIR__ . '/fixtures/bitbucket_issue_assigned.json'), true))); $this->assertEmpty($this->container['dispatcher']->getCalledListeners()); }