/** * @dataProvider save_comment_provider */ public function test_save_comment($member_id, $body) { $timeline_id = self::$timeline_id; // timeline_comment save \Util_Develop::sleep(); $timeline_comment = self::save_comment($member_id, $body); $timeline = \DB::select()->from('timeline')->where('id', $timeline_id)->execute()->current(); // 件数 $comment_count = \Util_Orm::get_count_all('\\Timeline\\Model_TimelineComment', array('timeline_id' => $timeline_id)); $this->assertEquals(self::$timeline_comment_count + 1, $comment_count); // 値 $this->assertEquals($comment_count, $timeline['comment_count']); $this->assertEquals($timeline_comment->created_at, $timeline['sort_datetime']); $timeline_caches = \DB::select()->from('timeline_cache')->where('timeline_id', $timeline_id)->execute(); foreach ($timeline_caches as $timeline_cache) { $this->assertEquals($comment_count, $timeline_cache['comment_count']); } // timeline_cache が最新レコードになっているか $timeline_cache = \Util_Orm::get_last_row('\\Timeline\\Model_TimelineCache'); $this->assertEquals($timeline_id, $timeline_cache->timeline_id); // timeline view cache check if (self::$is_check_view_cache) { try { $view_cache = \Cache::get(\Timeline\Site_Util::get_cache_key($timeline_id), \Config::get('timeline.articles.cache.expir')); } catch (\CacheNotFoundException $e) { $view_cache = null; } $this->assertEquals(self::$view_cache_before, $view_cache); } }
/** * @dataProvider update_like_provider */ public function test_update_post_like($member_id) { $note_id = self::$note_id; $note_before = \DB::select()->from('note')->where('id', $note_id)->execute()->current(); // note_like save \Util_Develop::sleep(); $is_liked = (bool) Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => $member_id)); $note = \DB::select()->from('note')->where('id', $note_id)->execute()->current(); $note_like = \Util_Orm::get_last_row('\\Note\\Model_NoteLike', array('note_id' => $note_id)); // 件数 $like_count = \Util_Orm::get_count_all('\\Note\\Model_NoteLike', array('note_id' => $note_id)); $like_count_after = $is_liked ? self::$note_like_count + 1 : self::$note_like_count - 1; $this->assertEquals($like_count_after, $like_count); if (!$is_liked) { $this->assertNull($note_like); } // 値 $this->assertEquals($like_count, $note['like_count']); $this->assertEquals($note_before['sort_datetime'], $note['sort_datetime']); // timeline 関連 if (is_enabled('timeline')) { $timeline_id = self::$timeline_id; $timeline = \DB::select()->from('timeline')->where('id', $timeline_id)->execute()->current(); // 値 $this->assertEquals($like_count, $timeline['like_count']); $this->assertEquals(self::$timeline_before->sort_datetime, $timeline['sort_datetime']); $timeline_caches = \DB::select()->from('timeline_cache')->where('timeline_id', $timeline_id)->execute(); foreach ($timeline_caches as $timeline_cache) { $this->assertEquals($like_count, $timeline_cache['like_count']); } //// timeline_cache が最新レコードになっているか //$timeline_cache = \Util_Orm::get_last_row('\Timeline\Model_TimelineCache'); //$this->assertEquals($timeline_id, $timeline_cache->timeline_id); // timeline view cache check if (self::$is_check_view_cache) { try { $timeline_view_cache = \Cache::get(\Timeline\Site_Util::get_cache_key($timeline_id), \Config::get('timeline.articles.cache.expir')); } catch (\CacheNotFoundException $e) { $timeline_view_cache = null; } $this->assertEquals(self::$timeline_view_cache_before, $timeline_view_cache); } } }
public static function make_view_cache4foreign_table_and_foreign_id($foreign_table, $foreign_id, $type = null) { $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids($foreign_table, $foreign_id, $type); $timeline = array_shift($timelines); Site_Util::get_article_main_view($timeline->id); return \Cache::get(\Timeline\Site_Util::get_cache_key($timeline->id), \Config::get('timeline.articles.cache.expir')); }
public function test_delete() { $note_id = self::$note_id; $this->save_comment(1, 'Test comment1.'); $this->save_comment(1, 'Test comment2.'); $note_comment = $this->save_comment(1, 'Test comment3.'); // set before data. $note_before = \DB::select()->from('note')->where('id', $note_id)->execute()->current(); self::$note_comment_count = \Util_Orm::get_count_all('\\Note\\Model_NoteComment', array('note_id' => self::$note_id)); // note_comment delete \Util_Develop::sleep(); $note_comment->delete(); $note = \DB::select()->from('note')->where('id', $note_id)->execute()->current(); // 件数 $comment_count = \Util_Orm::get_count_all('\\Note\\Model_NoteComment', array('note_id' => $note_id)); $this->assertEquals(self::$note_comment_count - 1, $comment_count); // 値 $this->assertEquals($comment_count, $note['comment_count']); $this->assertEquals($note_before['sort_datetime'], $note['sort_datetime']); // timeline 関連 if (is_enabled('timeline')) { $timeline_id = self::$timeline_id; $timeline = \DB::select()->from('timeline')->where('id', $timeline_id)->execute()->current(); // 値 $this->assertEquals($comment_count, $timeline['comment_count']); $this->assertEquals($note_before['sort_datetime'], $timeline['sort_datetime']); // timeline_caches $timeline_caches = \DB::select()->from('timeline_cache')->where('timeline_id', $timeline_id)->execute(); $this->assertCount(2, $timeline_caches); foreach ($timeline_caches as $timeline_cache) { $this->assertEquals($comment_count, $timeline_cache['comment_count']); } // timeline view cache check if (self::$is_check_view_cache) { $timeline_view_cache = \Cache::get(\Timeline\Site_Util::get_cache_key($timeline_id), \Config::get('timeline.articles.cache.expir')); $this->assertEquals(self::$view_cache_before, $timeline_view_cache); } } }