Exemplo n.º 1
0
 /**
  * Event: core.postingsubmit_post_end
  *
  * After a posting we assign the tags to the topic
  */
 public function submit_post_end($event)
 {
     if ($this->auth->acl_get(permissions::USE_TAGS, permissions::ADMIN_EDIT_TAGS, permissions::MOD_EDIT_TAGS)) {
         $event_data = $event->get_data();
         $data = $event_data['data'];
         $mode = $event_data['mode'];
         if ($this->is_new_topic($mode) || $this->is_edit_first_post($mode, $data)) {
             $tags = $this->get_tags_from_post_request();
             $all_tags = $this->tags_manager->split_valid_tags($tags);
             $valid_tags = $all_tags['valid'];
             $this->tags_manager->assign_tags_to_topic($data['topic_id'], $valid_tags);
         }
     }
 }
Exemplo n.º 2
0
 public function test_get_topics_by_tags()
 {
     // uses auth, so we set up the mock/stub
     // to allow reading first forum
     $this->auth->expects($this->exactly(6))->method('acl_getf')->with($this->equalTo('f_read'))->willReturn(array(1 => array('f_read' => true)));
     $tags = array();
     $start = 0;
     $limit = 10;
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit);
     $this->assertEquals(0, sizeof($topics));
     $tags = array("tag1");
     $start = 0;
     $limit = 10;
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit);
     $this->assertEquals(1, sizeof($topics));
     // check that some values exist in the found topic-array
     $diff = array_diff_assoc(array("topic_id" => 1, "forum_id" => 1, "topic_title" => "Topic1"), $topics[0]);
     $this->assertEquals(0, sizeof($diff));
     // case sensitive
     $tags = array("tAg1");
     $start = 0;
     $limit = 10;
     $mode = 'AND';
     $casesensitive = true;
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit, $mode, $casesensitive);
     $this->assertEquals(0, sizeof($topics));
     $tags = array("tag1", "noneExistingTag");
     $start = 0;
     $limit = 10;
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit);
     $this->assertEquals(0, sizeof($topics));
     // case sensitive + utf8
     $topic_id = 4;
     $tags = array("tÄäg");
     $this->tags_manager->assign_tags_to_topic($topic_id, $tags);
     $start = 0;
     $limit = 10;
     $mode = 'AND';
     $casesensitive = true;
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit, $mode, $casesensitive);
     $this->assertEquals(1, sizeof($topics));
     $this->assertEquals($topic_id, $topics[0]['topic_id']);
     // case insensitive + utf8
     $topic_id = 4;
     $tags = array("tÄäg");
     $this->tags_manager->assign_tags_to_topic($topic_id, $tags);
     $tags = array("täÄg");
     $start = 0;
     $limit = 10;
     $mode = 'AND';
     $casesensitive = false;
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit, $mode, $casesensitive);
     $this->assertEquals(1, sizeof($topics));
     $this->assertEquals($topic_id, $topics[0]['topic_id']);
     // search with OR
     $tags = array("tag1", "noneExistingTag");
     $start = 0;
     $limit = 10;
     $mode = 'OR';
     $topics = $this->tags_manager->get_topics_by_tags($tags, $start, $limit, $mode);
     $this->assertEquals(1, sizeof($topics));
     // check that some values exist in the found topic-array
     $diff = array_diff_assoc(array("topic_id" => 1, "forum_id" => 1, "topic_title" => "Topic1"), $topics[0]);
     $this->assertEquals(0, sizeof($diff));
 }