示例#1
0
 function index()
 {
     $url = 'http://www.plurk.com/p/6esun8#response-1799208331';
     $annotation = $this->annotation->find('annotation_id', 1017);
     $this->unit->run($annotation->get_id(), 1017, '接受推薦之前,原本的標註還在');
     $annotation = new Annotation(1017);
     $original_annotation_id = $annotation->get_id();
     $original_note = $annotation->get_note();
     $recommend_annotation = new Annotation(783);
     $recommend = new Annotation_recommend();
     $recommend->set_webpage($url);
     $recommend->set_recommended($annotation);
     $recommend->set_recommend_by($recommend_annotation);
     $recommend->update();
     $this->unit->run($recommend->get_id(), 'is_int', '確認recommend有儲存進去');
     $annotation = new Annotation(1017);
     $recommend = $annotation->get_recommend();
     $this->unit->run($recommend->get_id(), 'is_int', '能從annotation中取得recommend嗎?');
     $this->unit->run($recommend->get_recommend_by()->get_id(), $recommend_annotation->get_id(), '從recommend中取出的recommend_by,跟先前推薦的一樣嗎?');
     $tips = $recommend->get_tips_text_array();
     $this->unit->run(count($tips), 'is_int', '從recommend中取出的get_tips_text_array(),有提示嗎?');
     foreach ($tips as $key => $tip) {
         $this->unit->run($tip, 'is_string', '從recommend中取出的get_tips_text_array(),看一下第' . $key . '個提示');
     }
     //-----------------------------------------------
     $length = $annotation->get_scope_length();
     $recommend_length = $recommend_annotation->get_scope_length();
     $this->unit->run_false($length, $recommend_length, '測試看看,標註跟推薦標註兩個的長度應該不一樣才對');
     $recommend = $annotation->get_recommend();
     $annotation = $recommend->set_accept(TRUE);
     $length = $annotation->get_scope_length();
     $this->unit->run($length, $recommend_length, '接受推薦之後,標註跟推薦標註兩個的長度應該一樣才對');
     $this->unit->run_false($annotation->get_id(), $original_annotation_id, '接受推薦之後,這個標註應該跟上面的不一樣');
     $this->unit->run_false($annotation->get_score(0)->get_score() . '', '0', '接受推薦之後,修改過後的標註應該有分數?');
     $this->unit->run($annotation->get_note(), $original_note, '接受推薦之後,修改過後的標註應該有原本的筆記?');
     $recommend = $annotation->get_recommend();
     $this->unit->run($recommend, NULL, '接受推薦之後,標註就沒有推薦了');
     $annotation = $this->annotation->find('annotation_id', 1017);
     $this->unit->run($annotation, NULL, '接受推薦之後,原本的標註就被刪掉了才對');
     //        $this->unit->run($test_result
     //                , $expected_result
     //                , $test_name);
     //context_complete();
     unit_test_report($this, __METHOD__);
 }
示例#2
-1
 /**
  * 設定推薦
  * @param Annotation $annotation
  * @return \Annotation_tutor
  */
 public function setup_recommend(Annotation $annotation)
 {
     //test_msg('Annotation_tutor->setup_recommend()', 1);
     $threshold = $this->_get_recommended_threshold();
     $score = $this->_get_integrated_score($annotation);
     //test_msg('Annotation_tutor->setup_recommend()', 2);
     if ($score < $threshold) {
         //test_msg('Annotation_tutor->setup_recommend()', 3);
         //如果分數到達門檻,才進行推薦,否則不作推薦
         $recommend_annotation = $this->_find_recommend_annotation($annotation);
         $this->_CI_load('library', 'recommend/Annotation_recommend', 'annotation_recommend');
         $cond = array('recommended_annotation_id' => $annotation->get_id(), 'recommended_webpage_id' => $this->webpage->get_id());
         $recommend = $this->CI->annotation_recommend->find($cond);
         //test_msg('Annotation_tutor->setup_recommend()', 4);
         if (is_null($recommend)) {
             $recommend = new Annotation_recommend();
             $recommend->set_webpage($this->webpage);
             $recommend->set_recommended($annotation);
         }
         //test_msg('Annotation_tutor->setup_recommend()', 5);
         if (isset($recommend_annotation)) {
             $recommend->set_recommend_by($recommend_annotation);
         }
         //test_msg('Annotation_tutor->setup_recommend() 6', 6);
         // @TODO #170 20140410 這個步驟會出錯
         $recommend->update();
         //加入通知
         $trigger_resource = $annotation;
         $association_user = $annotation->get_user();
         //test_msg('Annotation_tutor->setup_recommend()', 7);
         $this->_CI_load('library', 'kals_actor/Notification_recommended', 'ntification_recommended');
         $notification = $this->CI->ntification_recommended->create_notification($association_user, $trigger_resource);
         if (is_null($notification)) {
             handle_error($this->lang->line('notification.recommend.create_notification.exception'));
         }
         //test_msg('Annotation_tutor->setup_recommend()', 8);
         $annotation->set_recommend($recommend);
         //test_msg('Annotation_tutor->setup_recommend()', 9);
     }
     return $this;
 }