/** * @dataProvider update_like_provider */ public function test_update_like($member_id) { // timeline_like save $is_liked = (bool) Model_TimelineLike::change_registered_status4unique_key(array('timeline_id' => self::$timeline->id, 'member_id' => $member_id)); $timeline = \DB::select()->from('timeline')->where('id', self::$timeline->id)->execute()->current(); $timeline_like = \Util_Orm::get_last_row('\\Timeline\\Model_TimelineLike', array('timeline_id' => self::$timeline->id)); // 件数 $like_count = \Util_Orm::get_count_all('\\Timeline\\Model_TimelineLike', array('timeline_id' => self::$timeline->id)); $like_count_after = $is_liked ? self::$timeline_like_count + 1 : self::$timeline_like_count - 1; $this->assertEquals($like_count_after, $like_count); // 値 $this->assertEquals($like_count, $timeline['like_count']); if ($is_liked) { $this->assertEquals(self::$timeline_before->sort_datetime, $timeline['sort_datetime']); } else { $this->assertNull($timeline_like); } $timeline_caches = \DB::select()->from('timeline_cache')->where('timeline_id', self::$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(self::$timeline->id, $timeline_cache->timeline_id); // timeline view cache check if (self::$is_check_view_cache) { $this->assertEquals(self::$view_cache_before, \Timeline\Site_Util::get_view_cache(self::$timeline->id)); } }
/** * @dataProvider update_provider */ public function test_update($self_member_id, $values, $album_image_public_flag_expected, $timeline_public_flag_expected) { $album = $this->get_album(); $before = array('name' => $album->name, 'body' => $album->body, 'public_flag' => $album->public_flag); // timeline view cache 作成 if (self::$is_check_timeline_view_cache) { $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album')); } // album update list($album, $moved_files, $is_changed) = Model_Album::save_with_relations($values, $self_member_id, $album); self::$album = $album; // 返り値の確認 $this->assertNotEmpty($album); // 件数(増えていないことを確認) $this->assertEquals(self::$album_count, \Util_Orm::get_count_all('\\Album\\Model_Album')); // album_image の値を変更した場合の public_flag の確認 $album_images = Model_AlbumImage::get4album_id($album->id); $album_image = array_shift($album_images); if (!empty($values['is_update_children_public_flag'])) { $this->assertEquals($album_image_public_flag_expected, $album_image->public_flag); } // timeline 関連 if (is_enabled('timeline')) { // 件数(増えていないことを確認) $this->assertEquals(self::$timeline_count, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline')); $this->assertEquals(self::$timeline_cache_count, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache')); $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('album', $album->id, \Config::get('timeline.types.album')); $this->assertCount(1, $timelines); $timeline = array_shift($timelines); $this->assertEquals($album->member_id, $timeline->member_id); $this->assertEquals($timeline_public_flag_expected, $timeline->public_flag); $this->assertContains($timeline->created_at, \Util_Date::get_datetime_list($album->created_at)); if ($is_changed) { if (self::check_sort_datetime_change(self::$album, $before)) { $this->assertEquals($album->updated_at, $timeline->sort_datetime); } $this->assertContains($timeline->updated_at, \Util_Date::get_datetime_list($album->updated_at)); } // timeline view cache check if (self::$is_check_timeline_view_cache) { $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id)); } } }
/** * @dataProvider update_like_provider */ public function test_update_like($member_id) { // timeline_like save \Util_Develop::sleep(); $is_liked = self::execute_like(self::$timeline_comment->id, $member_id); self::$timeline_comment = Model_TimelineComment::find(self::$timeline_comment->id); $timeline_comment_like = \Util_Orm::get_last_row('\\Timeline\\Model_TimelineCommentLike', array('timeline_comment_id' => self::$timeline_comment->id)); // 件数 $like_count = \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCommentLike', array('timeline_comment_id' => self::$timeline_comment->id)); $like_count_expect = $is_liked ? self::$like_count + 1 : self::$like_count - 1; $this->assertEquals($like_count_expect, $like_count); // 値 $this->assertEquals($like_count, self::$timeline_comment->like_count); if (!$is_liked) { $this->assertNull($timeline_comment_like); } // timeline view cache check if (self::$is_check_view_cache) { $this->assertEquals(self::$view_cache_before, \Timeline\Site_Util::get_view_cache(self::$timeline->id)); } }
/** * @dataProvider save_provider */ public function test_save($is_update_test, $values) { $note = \Note\Model_Note::forge(); $before = array(); if ($is_update_test) { $note = $this->get_last_row(); $before = array('title' => $note->title, 'body' => $note->body, 'public_flag' => $note->public_flag, 'is_published' => $note->is_published, 'sort_datetime' => $note->sort_datetime, 'comment_count' => $note->comment_count, 'like_count' => $note->like_count); } // timeline view cache 作成 if (self::$is_check_timeline_view_cache) { $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('note', $note->id, \Config::get('timeline.types.note')); } // note save list($is_changed, $is_published, $moved_files) = $note->save_with_relations(self::$self_member_id, $values); // 返り値の確認 $this->assertEmpty($moved_files); if (!empty($values['is_draft'])) { $this->assertEquals(false, $is_published); } // 新規投稿 if (!$is_update_test) { $is_draft = !empty($values['is_draft']); // 件数 $this->assertEquals(self::$note_count + 1, \Util_Orm::get_count_all('\\Note\\Model_Note')); if (is_enabled('timeline')) { if ($is_draft) { $this->assertEquals(self::$timeline_count, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline')); $this->assertEquals(self::$timeline_cache_count, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache')); } else { $this->assertEquals(self::$timeline_count + 1, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline')); $this->assertEquals(self::$timeline_cache_count + 2, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache')); } } // 値 $this->assertEquals(0, $note->comment_count); $this->assertEquals($note->created_at, $note->sort_datetime); } else { // 件数 $this->assertEquals(self::$note_count, \Util_Orm::get_count_all('\\Note\\Model_Note')); if (is_enabled('timeline')) { if ($is_published) { $this->assertEquals(self::$timeline_count + 1, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline')); $this->assertEquals(self::$timeline_cache_count + 2, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache')); } else { $this->assertEquals(self::$timeline_count, \Util_Orm::get_count_all('\\Timeline\\Model_Timeline')); $this->assertEquals(self::$timeline_cache_count, \Util_Orm::get_count_all('\\Timeline\\Model_TimelineCache')); } } // 値 $this->assertEquals($before['comment_count'], $note->comment_count); if ($is_changed && self::check_sort_datetime_change($note, $before)) { $this->assertEquals($note->updated_at, $note->sort_datetime); } } // timeline 関連 if (is_enabled('timeline')) { // 公開済み日記 if ($note->is_published) { $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note->id, \Config::get('timeline.types.note')); $this->assertCount(1, $timelines); $timeline = array_shift($timelines); $this->assertEquals($note->member_id, $timeline->member_id); $this->assertEquals($note->public_flag, $timeline->public_flag); $this->assertEquals($note->sort_datetime, $timeline->sort_datetime); $this->assertEquals($note->comment_count, $timeline->comment_count); if ($is_published) { $this->assertEquals($note->updated_at, $timeline->created_at); } else { $this->assertEquals($note->created_at, $timeline->created_at); } // timeline view cache check if (self::$is_check_timeline_view_cache) { $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id)); } } else { $timelines = \Timeline\Model_Timeline::get4foreign_table_and_foreign_ids('note', $note->id, \Config::get('timeline.types.note')); $this->assertEmpty($timelines); } } }
public function test_delete_album_image_multiple4ids() { $timeline_ids = array_unique(\Util_Orm::conv_col2array(\Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image_id', self::$album_image->id), 'timeline_id')); $notices = array(); if (is_enabled('notice')) { $notice_ids = \Util_Orm::conv_col2array(\Notice\Model_Notice::get4foreign_data('album_image', self::$album_image->id), 'id'); $notice_ids += \Util_Orm::conv_col2array(\Notice\Model_Notice::get4parent_data('album_image', self::$album_image->id), 'id'); $notice_ids = array_unique($notice_ids); } $notice_statuses = \Notice\Model_NoticeStatus::query()->where('notice_id', 'in', $notice_ids)->get(); $file_name = self::$album_image->file_name; $file = \Model_File::get4name($file_name); $file_size = $file->filesize; $member_filesize_before = self::$member->filesize_total; // timeline view cache 作成 if (self::$is_check_timeline_view_cache) { $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album_image')); } // file if (conf('upload.storageType') == 'db') { $this->assertNotNull(\Model_FileBin::get4name(self::$album_image->file_name)); } // album_image delete. Site_NoOrmModel::delete_album_image_multiple4ids(self::$album_image->id, true); // 件数 $this->assertEmpty(Model_AlbumImage::query()->where('id', self::$album_image->id)->get()); $this->assertEmpty(Model_AlbumImageLike::query()->where('album_image_id', self::$album_image_comment->id)->get()); $this->assertEmpty(Model_AlbumImageComment::query()->where('album_image_id', self::$album_image->id)->get()); $this->assertEmpty(Model_AlbumImageCommentLike::query()->where('album_image_comment_id', self::$album_image_comment->id)->get()); // file $this->assertEmpty(\Model_File::get4name($file_name)); // meber_filesize $this->assertEquals($member_filesize_before - $file_size, self::get_member_filesize_total(self::$member_id)); // timeline if (is_enabled('timeline')) { $timeline_child_datas = \Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image', self::$album_image->id); $this->assertEmpty($timeline_child_datas); if ($timeline_ids) { $this->assertEmpty(\Timeline\Model_Timeline::query()->where('id', 'in', $timeline_ids)->get()); } // timeline view cache check if (self::$is_check_timeline_view_cache && $timeline_ids) { foreach ($timeline_ids as ${$timeline_id}) { $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline_id)); } } } // notice if (is_enabled('notice')) { $this->assertEmpty(\Notice\Model_MemberWatchContent::get4foreign_data('album_image', self::$album_image->id)); if ($notice_ids) { $this->assertEmpty(\Notice\Model_Notice::query()->where('id', 'in', $notice_ids)->get()); $this->assertEmpty(\Notice\Model_NoticeStatus::query()->where('notice_id', 'in', $notice_ids)->get()); $this->assertEmpty(\Notice\Model_NoticeMemberFrom::query()->where('notice_id', 'in', $notice_ids)->get()); } if (self::$is_check_notice_cache) { foreach ($notice_statuses as $notice_statuse) { $this->assertEmpty(\Notice\Site_Util::get_unread_count_cache($notice_statuse->member_id)); } } } }
public function test_delete() { if (!self::$album_image) { self::$album_image = $this->get_album_image(array('public_flag' => FBD_PUBLIC_FLAG_MEMBER)); } $album_image_id = self::$album_image->id; $file_name = self::$album_image->file_name; $file = \Model_File::get4name($file_name); $file_size = $file->filesize; $file_path = \Site_Upload::get_uploaded_file_path(self::$album_image->file_name); $member_filesize_before = self::get_member_filesize_total(self::$member_id); // set cover_album_image_id self::$album->cover_album_image_id = $album_image_id; // timeline view cache 作成 if (self::$is_check_timeline_view_cache) { $timeline_view_cache_before = \Timeline\Site_Util::make_view_cache4foreign_table_and_foreign_id('album', $album->id, \Config::get('timeline.types.album_image')); } // file if (conf('upload.storageType') == 'db') { $this->assertNotNull(\Model_FileBin::get4name(self::$album_image->file_name)); } elseif (conf('upload.storageType') == 'normal') { $this->assertTrue(file_exists($file_path)); } // album_image delete. self::$album_image->delete(); // 件数 $this->assertEquals(self::$total_count - 1, Model_AlbumImage::get_count()); // file $this->assertEmpty(\Model_File::get4name($file_name)); $this->assertFalse(file_exists($file_path)); // meber_filesize $this->assertEquals($member_filesize_before - $file_size, self::get_member_filesize_total(self::$member_id)); // check cover_album_image_id $this->assertEmpty(self::$album->cover_album_image_id); // timeline if (is_enabled('timeline')) { $timeline_child_datas = \Timeline\Model_TimelineChildData::get4foreign_table_and_foreign_ids('album_image', $album_image_id); $this->assertEmpty($timeline_child_datas); // timeline view cache check if (self::$is_check_timeline_view_cache) { $this->assertEmpty(\Timeline\Site_Util::get_view_cache($timeline->id)); } } }
public function test_delete() { $timeline_id = self::$timeline_id; self::save_comment(self::$member_id, 'Test comment1.'); self::save_comment(self::$member_id, 'Test comment2.'); $timeline_comment = self::save_comment(self::$member_id, 'Test comment3.'); // timeline_comment delete \Util_Develop::sleep(); $timeline_comment->delete(); $timeline = Model_Timeline::find($timeline_id); // 件数 $comment_count = \Util_Orm::get_count_all('\\Timeline\\Model_TimelineComment', array('timeline_id' => $timeline_id)); $this->assertEquals(self::$timeline_comment_count + 3 - 1, $comment_count); // 値 $this->assertEquals($comment_count, $timeline->comment_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($comment_count, $timeline_cache['comment_count']); } // timeline view cache check if (self::$is_check_view_cache) { $this->assertEquals(self::$view_cache_before, \Timeline\Site_Util::get_view_cache($timeline->id)); } }