Exemplo n.º 1
0
 public function testGetTitle()
 {
     $wn = new WebNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($this->container);
     $f = new File($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
     $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
     $task = $tf->getDetails(1);
     $subtask = $s->getById(1, true);
     $comment = $c->getById(1);
     $file = $c->getById(1);
     $this->assertNotEmpty($task);
     $this->assertNotEmpty($subtask);
     $this->assertNotEmpty($comment);
     $this->assertNotEmpty($file);
     foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event_name => $values) {
         $title = $wn->getTitleFromEvent($event_name, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array()));
         $this->assertNotEmpty($title);
     }
     $this->assertNotEmpty($wn->getTitleFromEvent(Task::EVENT_OVERDUE, array('tasks' => array(array('id' => 1)))));
     $this->assertNotEmpty($wn->getTitleFromEvent('unkown', array()));
 }
Exemplo n.º 2
0
 public static function perform(Comment $comment)
 {
     if ($comment->comment_id) {
         return;
     }
     $article = $comment->article()->find_one();
     if ($article->user_id != $comment->user_id) {
         Notify::dispense()->create(array('user_id' => $article->user_id, 'from_user_id' => $comment->user_id, 'type' => Notify::REPLY, 'object_type' => $article->type(), 'object_id' => $article->id, 'message' => $comment->text))->save();
     }
     if (!preg_match_all('/@(\\w+)/', $comment->text, $match)) {
         return;
     }
     $users = array();
     foreach ($match[1] as $username) {
         if (isset($users[$username])) {
             continue;
         }
         if (!($user = User::dispense()->where('name', $username)->find_one())) {
             continue;
         }
         // If mention in reply, ignore mention notify
         if ($user->id == $article->user_id) {
             continue;
         }
         $users[$username] = $user->id;
     }
     foreach ($users as $user_id) {
         Notify::dispense()->create(array('user_id' => $user_id, 'from_user_id' => $comment->user_id, 'type' => Notify::MENTION, 'object_type' => $article->type(), 'object_id' => $article->id, 'message' => $comment->text))->save();
     }
 }
Exemplo n.º 3
0
 public function testGetMailContent()
 {
     $en = new EmailNotification($this->container);
     $p = new Project($this->container);
     $tf = new TaskFinder($this->container);
     $tc = new TaskCreation($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($this->container);
     $f = new File($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1)));
     $this->assertEquals(1, $s->create(array('title' => 'test', 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'test', 'task_id' => 1, 'user_id' => 1)));
     $this->assertEquals(1, $f->create(1, 'test', 'blah', 123));
     $task = $tf->getDetails(1);
     $subtask = $s->getById(1, true);
     $comment = $c->getById(1);
     $file = $c->getById(1);
     $this->assertNotEmpty($task);
     $this->assertNotEmpty($subtask);
     $this->assertNotEmpty($comment);
     $this->assertNotEmpty($file);
     foreach (Subscriber\NotificationSubscriber::getSubscribedEvents() as $event => $values) {
         $this->assertNotEmpty($en->getMailContent($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())));
         $this->assertNotEmpty($en->getMailSubject($event, array('task' => $task, 'comment' => $comment, 'subtask' => $subtask, 'file' => $file, 'changes' => array())));
     }
 }
Exemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     $this->left = View::template('v_left.php');
     $this->post = MPost::app();
     $this->image = MImage::app();
     $this->tag = MTag::app();
     $this->comment = MComment::app();
 }
 public function testWithNoUser()
 {
     $action = new Action\CommentCreation($this->container, 1, GithubWebhook::EVENT_ISSUE_COMMENT);
     // We create a task in the first column
     $tc = new TaskCreation($this->container);
     $p = new Project($this->container);
     $c = new Comment($this->container);
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('title' => 'test', 'project_id' => 1, 'column_id' => 1)));
     // We create an event to move the task to the 2nd column
     $event = array('project_id' => 1, 'task_id' => 1, 'user_id' => 0, 'comment' => 'youpi');
     // Our event should be executed
     $this->assertTrue($action->execute(new GenericEvent($event)));
     $comment = $c->getById(1);
     $this->assertNotEmpty($comment);
     $this->assertEquals(1, $comment['task_id']);
     $this->assertEquals(0, $comment['user_id']);
     $this->assertEquals('youpi', $comment['comment']);
 }
Exemplo n.º 6
0
 public function uninstall()
 {
     die('serious?');
     // clears all tables !!!
     \Model\Post::setdown();
     \Model\Tag::setdown();
     \Model\Comment::setdown();
     \Model\User::setdown();
     $cfg = new Config();
     $cfg->clear('ACTIVE_DB');
     $cfg->save();
     \Base::instance()->clear('SESSION');
     echo "goodbye!";
 }
Exemplo n.º 7
0
 public function testCommentCreation()
 {
     $c = new Config($this->container);
     $p = new Project($this->container);
     $tc = new TaskCreation($this->container);
     $cm = new Comment($this->container);
     $this->container['dispatcher']->addSubscriber(new WebhookSubscriber($this->container));
     $c->save(array('webhook_url' => 'http://localhost/comment'));
     $this->assertEquals(1, $p->create(array('name' => 'test')));
     $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test')));
     $this->assertEquals(1, $cm->create(array('task_id' => 1, 'comment' => 'test comment', 'user_id' => 1)));
     $this->assertStringStartsWith('http://localhost/comment?token=', $this->container['httpClient']->getUrl());
     $event = $this->container['httpClient']->getData();
     $this->assertNotEmpty($event);
     $this->assertArrayHasKey('event_name', $event);
     $this->assertArrayHasKey('event_data', $event);
     $this->assertEquals('comment.create', $event['event_name']);
     $this->assertNotEmpty($event['event_data']);
     $this->assertArrayHasKey('task_id', $event['event_data']);
     $this->assertArrayHasKey('user_id', $event['event_data']);
     $this->assertArrayHasKey('comment', $event['event_data']);
     $this->assertArrayHasKey('id', $event['event_data']);
     $this->assertEquals('test comment', $event['event_data']['comment']);
 }
Exemplo n.º 8
0
 public function testValidateModification()
 {
     $c = new Comment($this->registry);
     $result = $c->validateModification(array('id' => 1, 'comment' => 'bla'));
     $this->assertTrue($result[0]);
     $result = $c->validateModification(array('id' => 1, 'comment' => ''));
     $this->assertFalse($result[0]);
     $result = $c->validateModification(array('comment' => 'bla'));
     $this->assertFalse($result[0]);
     $result = $c->validateModification(array('id' => 'b', 'comment' => 'bla'));
     $this->assertFalse($result[0]);
     $result = $c->validateModification(array());
     $this->assertFalse($result[0]);
 }
Exemplo n.º 9
0
 public function testRemove()
 {
     $u = new User($this->container);
     $tc = new TaskCreation($this->container);
     $tf = new TaskFinder($this->container);
     $p = new Project($this->container);
     $s = new Subtask($this->container);
     $c = new Comment($this->container);
     $this->assertNotFalse($u->create(array('username' => 'toto', 'password' => '123456', 'name' => 'Toto')));
     $this->assertEquals(1, $p->create(array('name' => 'Project #1')));
     $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'owner_id' => 2)));
     $this->assertEquals(1, $s->create(array('title' => 'Subtask #1', 'user_id' => 2, 'task_id' => 1)));
     $this->assertEquals(1, $c->create(array('comment' => 'foobar', 'user_id' => 2, 'task_id' => 1)));
     $task = $tf->getById(1);
     $this->assertEquals(1, $task['id']);
     $this->assertEquals(2, $task['owner_id']);
     $this->assertTrue($u->remove(1));
     $this->assertTrue($u->remove(2));
     $this->assertFalse($u->remove(2));
     $this->assertFalse($u->remove(55));
     // Make sure that assigned tasks are unassigned after removing the user
     $task = $tf->getById(1);
     $this->assertEquals(1, $task['id']);
     $this->assertEquals(0, $task['owner_id']);
     // Make sure that assigned subtasks are unassigned after removing the user
     $subtask = $s->getById(1);
     $this->assertEquals(1, $subtask['id']);
     $this->assertEquals(0, $subtask['user_id']);
     // Make sure that comments are not related to the user anymore
     $comment = $c->getById(1);
     $this->assertEquals(1, $comment['id']);
     $this->assertEquals(0, $comment['user_id']);
     // Make sure that private projects are also removed
     $user_id1 = $u->create(array('username' => 'toto1', 'password' => '123456', 'name' => 'Toto'));
     $user_id2 = $u->create(array('username' => 'toto2', 'password' => '123456', 'name' => 'Toto'));
     $this->assertNotFalse($user_id1);
     $this->assertNotFalse($user_id2);
     $this->assertEquals(2, $p->create(array('name' => 'Private project #1', 'is_private' => 1), $user_id1, true));
     $this->assertEquals(3, $p->create(array('name' => 'Private project #2', 'is_private' => 1), $user_id2, true));
     $this->assertTrue($u->remove($user_id1));
     $this->assertNotEmpty($p->getById(1));
     $this->assertNotEmpty($p->getById(3));
     $this->assertEmpty($p->getById(2));
 }
Exemplo n.º 10
0
 /**
  * Display the template show task (common between different actions)
  *
  * @access protected
  * @param  array  $task               Task data
  * @param  array  $comment_form       Comment form data
  * @param  array  $description_form   Description form data
  * @param  array  $comment_edit_form  Comment edit form data
  */
 protected function showTask(array $task, array $comment_form = array(), array $description_form = array(), array $comment_edit_form = array())
 {
     if (empty($comment_form)) {
         $comment_form = array('values' => array('task_id' => $task['id'], 'user_id' => $this->acl->getUserId()), 'errors' => array());
     }
     if (empty($description_form)) {
         $description_form = array('values' => array('id' => $task['id']), 'errors' => array());
     }
     if (empty($comment_edit_form)) {
         $comment_edit_form = array('values' => array('id' => 0), 'errors' => array());
     } else {
         $hide_comment_form = true;
     }
     $this->response->html($this->template->layout('task_show', array('hide_comment_form' => isset($hide_comment_form), 'comment_edit_form' => $comment_edit_form, 'comment_form' => $comment_form, 'description_form' => $description_form, 'comments' => $this->comment->getAll($task['id']), 'task' => $task, 'columns_list' => $this->board->getColumnsList($task['project_id']), 'colors_list' => $this->task->getColors(), 'menu' => 'tasks', 'title' => $task['title'])));
 }
Exemplo n.º 11
0
 /**
  * @expectedException Exception
  */
 public function testNoCollectionName()
 {
     \Model\Comment::getCollectionName();
 }
Exemplo n.º 12
0
use Model\Task;
use Model\User;
use Model\Config;
use Model\Category;
use Model\Comment;
use Model\SubTask;
use Model\Board;
use Model\Action;
use Model\Webhook;
use Model\Notification;
$config = new Config($registry);
$project = new Project($registry);
$task = new Task($registry);
$user = new User($registry);
$category = new Category($registry);
$comment = new Comment($registry);
$subtask = new SubTask($registry);
$board = new Board($registry);
$action = new Action($registry);
$webhook = new Webhook($registry);
$notification = new Notification($registry);
$action->attachEvents();
$project->attachEvents();
$webhook->attachEvents();
$notification->attachEvents();
// Load translations
$language = $config->get('language', 'en_US');
if ($language !== 'en_US') {
    Translator::load($language);
}
$server = new Server();
Exemplo n.º 13
0
 /**
  * This method redirects data to editing method in Comment object
  * @param $commentMsg
  * @param $pageID
  * @param $oldTimeStamp
  */
 public function editComment($commentMsg, $pageID, $oldTimeStamp)
 {
     $comment = new Comment($_SESSION['tastyRecipeUser'], $commentMsg, $pageID);
     $comment->edit($oldTimeStamp);
 }
Exemplo n.º 14
0
 /**
  * This method updates already written comment and its date in database
  * @param Comment $editedComment
  * @param mixed $oldTimestamp
  */
 public function editCommentInDB(Comment $editedComment, $oldTimestamp)
 {
     $query = $this->connect->prepare("UPDATE `" . self::TABLE_NAME . "` SET `" . self::COMMENT_COL . "` = ? , `" . self::DATE_COL . "` = ? WHERE `" . self::USER_ID_COL . "` = ? AND `" . self::DATE_COL . "` = ? AND `" . self::PAGE_ID_COL . "` = ?");
     $query->bind_param("sssss", $this->escape_string($editedComment->getCommentMsg()), $this->escape_string($editedComment->getDate()), $this->escape_string($editedComment->getUserID()), $this->escape_string($oldTimestamp), $this->escape_string($editedComment->getPageID()));
     $query->execute();
 }