private static function delete_notice_member_from($notice_id, $member_id) { if (!($notice_member_from = \Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_id, $member_id))) { return false; } return $notice_member_from->delete(); }
public function test_delete_notice() { // 事前準備 $config_type_key = 'like'; \Model_MemberConfig::set_value(1, \Notice\Form_MemberConfig::get_name('comment'), 0); \Model_MemberConfig::set_value(2, \Notice\Form_MemberConfig::get_name($config_type_key), 1); \Model_MemberConfig::set_value(2, \Notice\Site_Util::get_member_config_name_for_watch_content('comment'), 0); self::$member_id = 1; $note = self::set_note(); $note_comment = self::save_comment(self::$note_id, 2); self::$note_comment_id = $note_comment->id; $note_id = self::$note_id; $foreign_id = self::$note_comment_id; $notice_count_all_before = \Notice\Model_Notice::get_count(); $notice_status_count_all_before = \Notice\Model_NoticeStatus::get_count(); $notice_member_from_count_all_before = \Notice\Model_NoticeMemberFrom::get_count(); // イイね実行 $is_liked = (bool) Model_NoteCommentLike::change_registered_status4unique_key(array('note_comment_id' => self::$note_comment_id, 'member_id' => 4)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $foreign_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 4)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $foreign_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // イイねを取り消し $is_liked = (bool) Model_NoteCommentLike::change_registered_status4unique_key(array('note_comment_id' => self::$note_comment_id, 'member_id' => 4)); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 4)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $foreign_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // イイね実行 $is_liked = (bool) Model_NoteCommentLike::change_registered_status4unique_key(array('note_comment_id' => self::$note_comment_id, 'member_id' => 4)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $foreign_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // note_comment 削除 $note_comment->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); // 再度 comment 投稿 $note_comment = self::save_comment(self::$note_id, 2); self::$note_comment_id = $note_comment->id; // イイね実行 $is_liked = (bool) Model_NoteCommentLike::change_registered_status4unique_key(array('note_comment_id' => self::$note_comment_id, 'member_id' => 4)); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); // note 削除 $note->delete_with_relations(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 4)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $foreign_id, \Notice\Site_Util::get_notice_type(self::$type_key))); }
public function test_delete_notice() { // 事前準備 \Model_MemberConfig::set_value(2, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(2, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); self::$member_id = 1; self::set_note(); $note_id = self::$note_id; $foreign_id = self::$note_id; $notice_count_all_before = \Notice\Model_Notice::get_count(); $notice_status_count_all_before = \Notice\Model_NoticeStatus::get_count(); $notice_member_from_count_all_before = \Notice\Model_NoticeMemberFrom::get_count(); $member_watch_content_count_all_before = \Notice\Model_MemberWatchContent::get_count(); // 他人がイイね $like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // イイねを取り消し $like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2)); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // watch は解除されない // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2)); // watch は解除されない $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 他人のイイね+自分がコメント $note_like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2)); self::save_comment(1, 'Test comment1.'); $notice_like = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $notice_comment = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type('comment')); $this->assertNotNull($notice_like); $this->assertNotNull($notice_comment); // 件数確認 $this->assertEquals($notice_count_all_before + 2, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 2, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 2, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice_comment->id)); $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice_like->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_like->id, 2)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_comment->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, self::$member_id)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // イイねを取り消し $like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 2)); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // watch は解除されない // 関連テーブルのレコードが削除されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice_comment->id)); $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice_like->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_like->id, 2)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_comment->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 2)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, self::$member_id)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 他人がイイね $note_like_id = Model_NoteLike::change_registered_status4unique_key(array('note_id' => $note_id, 'member_id' => 3)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // note 削除 $note = Model_Note::find($note_id); $note->delete_with_relations(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $note_id, 3)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $note_id, \Notice\Site_Util::get_notice_type(self::$type_key))); }
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_notice() { // 事前準備 \Model_MemberConfig::set_value(2, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(2, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); self::$member_id = 1; self::$album_image = \Album\Site_Test::setup_album_image(self::$member_id, null, 1); self::$album = Model_Album::find(self::$album_image->album_id); $album_image_id = self::$album_image->id; $foreign_id = self::$album_image->id; $notice_count_all_before = \Notice\Model_Notice::get_count(); $notice_status_count_all_before = \Notice\Model_NoticeStatus::get_count(); $notice_member_from_count_all_before = \Notice\Model_NoticeMemberFrom::get_count(); $member_watch_content_count_all_before = \Notice\Model_MemberWatchContent::get_count(); // liked from others. $like_id = Model_AlbumImageLike::change_registered_status4unique_key(array('album_image_id' => $album_image_id, 'member_id' => 2)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // check count $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // check created related table records. $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // undo like. $like_id = Model_AlbumImageLike::change_registered_status4unique_key(array('album_image_id' => $album_image_id, 'member_id' => 2)); // check count $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // keep watched // check deleted related table records. $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); // keep watched $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // others execute like and coment myself. $album_image_like_id = Model_AlbumImageLike::change_registered_status4unique_key(array('album_image_id' => $album_image_id, 'member_id' => 2)); \Site_Test::save_comment('album_image', $album_image_id, 1, 'Test comment1.'); $notice_like = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $notice_comment = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type('comment')); $this->assertNotNull($notice_like); $this->assertNotNull($notice_comment); // check count $this->assertEquals($notice_count_all_before + 2, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 2, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 2, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // check created related table records. $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice_comment->id)); $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice_like->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_like->id, 2)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_comment->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, self::$member_id)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // undo like. $like_id = Model_AlbumImageLike::change_registered_status4unique_key(array('album_image_id' => $album_image_id, 'member_id' => 2)); // check count $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // keep watch // check created related table records. $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice_comment->id)); $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice_like->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_like->id, 2)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice_comment->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, self::$member_id)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // others execute like. $album_image_like_id = Model_AlbumImageLike::change_registered_status4unique_key(array('album_image_id' => $album_image_id, 'member_id' => 3)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // delete album_image. $album_image = Model_AlbumImage::find($album_image_id); $album_image->delete(); // check count $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count()); // check deleted related table records. $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 3)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // album delete test // setup self::$album_image = \Album\Site_Test::setup_album_image(self::$member_id, null, 1, self::$album->id); $foreign_id = self::$album_image->id; $album_image_id = self::$album_image->id; // others execute like. $album_image_like_id = Model_AlbumImageLike::change_registered_status4unique_key(array('album_image_id' => $album_image_id, 'member_id' => 4)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // delete album_image self::$album->delete(); // check count $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count()); // check deleted related table records. $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 3)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); }
public function test_delete_notice() { // prepare test \Model_MemberConfig::set_value(1, \Notice\Form_MemberConfig::get_name('comment'), 1); \Model_MemberConfig::set_value(2, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(2, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); $notice_count_all_before = \Notice\Model_Notice::get_count(); $notice_status_count_all_before = \Notice\Model_NoticeStatus::get_count(); $notice_member_from_count_all_before = \Notice\Model_NoticeMemberFrom::get_count(); $member_watch_content_count_all_before = \Notice\Model_MemberWatchContent::get_count(); self::$member_id = 1; self::$album_image = self::set_album_image(); $foreign_id = self::$album_image->id; $album_image_id = self::$album_image->id; // 他人がコメント $album_image_comment = $this->save_comment(2, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // コメントを削除 $album_image_comment->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // keep watch count // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); // keep watch count $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 自分もコメント $album_image_comment = $this->save_comment(2, 'Test comment2-2.'); $this->save_comment(1, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 2, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 2, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // コメントを削除 $album_image_comment->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // watch は解除されない // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 2)); // watch は解除されない $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 他人がコメント $album_image_comment = $this->save_comment(3, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // delete album_image $album_image = Model_AlbumImage::find($album_image_id); $album_image->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 3)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // album delete test // setup self::$album_image = self::set_album_image(null, 1, self::$album->id); $foreign_id = self::$album_image->id; $album_image_id = self::$album_image->id; // comment athers $album_image_comment = $this->save_comment(3, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // delete album_image self::$album->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, $album_image_id, 3)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, $album_image_id, \Notice\Site_Util::get_notice_type(self::$type_key))); }
public function test_delete_notice() { // 事前準備 \Model_MemberConfig::set_value(1, \Notice\Form_MemberConfig::get_name('comment'), 1); \Model_MemberConfig::set_value(2, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(2, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Form_MemberConfig::get_name(self::$type_key), 1); \Model_MemberConfig::set_value(3, \Notice\Site_Util::get_member_config_name_for_watch_content(self::$type_key), 1); self::$member_id = 1; self::set_timeline(); $timeline_id = self::$timeline_id; $foreign_id = self::$timeline_id; $notice_count_all_before = \Notice\Model_Notice::get_count(); $notice_status_count_all_before = \Notice\Model_NoticeStatus::get_count(); $notice_member_from_count_all_before = \Notice\Model_NoticeMemberFrom::get_count(); $member_watch_content_count_all_before = \Notice\Model_MemberWatchContent::get_count(); // 他人がコメント $timeline_comment = self::save_comment(2, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 1, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 1, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, self::$timeline_id, 2)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // コメントを削除 $timeline_comment->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // watch は解除されない // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, self::$timeline_id, 2)); // watch は解除されない $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 自分もコメント $timeline_comment = self::save_comment(2, 'Test comment2-2.'); self::save_comment(1, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // 件数確認 $this->assertEquals($notice_count_all_before + 1, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before + 2, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before + 2, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが作成されていることを確認 $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNotNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, self::$timeline_id, 2)); $this->assertNotNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // コメントを削除 $timeline_comment->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before + 1, \Notice\Model_MemberWatchContent::get_count()); // watch は解除されない // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(2, $notice->id)); $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 2)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, self::$member_id)); $this->assertNotNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, self::$timeline_id, 2)); // watch は解除されない $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 他人がコメント $timeline_comment = self::save_comment(3, 'Test comment1.'); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // timeline 削除 $timeline = Model_Timeline::find($timeline_id); $timeline->delete(); // 件数確認 $this->assertEquals($notice_count_all_before, \Notice\Model_Notice::get_count()); $this->assertEquals($notice_status_count_all_before, \Notice\Model_NoticeStatus::get_count()); $this->assertEquals($notice_member_from_count_all_before, \Notice\Model_NoticeMemberFrom::get_count()); $this->assertEquals($member_watch_content_count_all_before, \Notice\Model_MemberWatchContent::get_count()); // 関連テーブルのレコードが削除されていることを確認 $this->assertNull(\Notice\Model_NoticeStatus::get4member_id_and_notice_id(self::$member_id, $notice->id)); $this->assertNull(\Notice\Model_NoticeMemberFrom::get4notice_id_and_member_id($notice->id, 3)); $this->assertNull(\Notice\Model_MemberWatchContent::get_one4foreign_data_and_member_id(self::$foreign_table, self::$timeline_id, 3)); $this->assertNull(\Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$timeline_id, \Notice\Site_Util::get_notice_type(self::$type_key))); }