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; self::$album_image = Site_Test::setup_album_image(self::$member_id, null, 1); self::$album = Model_Album::find(self::$album_image->album_id); self::$album_image_comment = \Site_Test::save_comment('album_image', self::$album_image->id, 2); $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_AlbumImageCommentLike::change_registered_status4unique_key(array('album_image_comment_id' => self::$album_image_comment->id, 'member_id' => 4)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$album_image_comment->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, self::$album_image_comment->id, \Notice\Site_Util::get_notice_type(self::$type_key))); // イイねを取り消し $is_liked = (bool) Model_AlbumImageCommentLike::change_registered_status4unique_key(array('album_image_comment_id' => self::$album_image_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, self::$album_image_comment->id, \Notice\Site_Util::get_notice_type(self::$type_key))); // イイね実行 $is_liked = (bool) Model_AlbumImageCommentLike::change_registered_status4unique_key(array('album_image_comment_id' => self::$album_image_comment->id, 'member_id' => 4)); $notice = \Notice\Model_Notice::get_last4foreign_data(self::$foreign_table, self::$album_image_comment->id, \Notice\Site_Util::get_notice_type(self::$type_key)); $this->assertNotNull($notice); // album_image_comment 削除 self::$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()); // 再度 comment 投稿 self::$album_image_comment = \Site_Test::save_comment('album_image', self::$album_image->id, 2); // イイね実行 $is_liked = (bool) Model_AlbumImageCommentLike::change_registered_status4unique_key(array('album_image_comment_id' => self::$album_image_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()); // album_image 削除 self::$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->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, self::$album_image_comment->id, \Notice\Site_Util::get_notice_type(self::$type_key))); // 再度 album_image, comment 投稿 self::$album_image = Site_Test::setup_album_image(self::$member_id, null, 1, self::$album->id); self::$album_image_comment = \Site_Test::save_comment('album_image', self::$album_image->id, 2); // イイね実行 $is_liked = (bool) Model_AlbumImageCommentLike::change_registered_status4unique_key(array('album_image_comment_id' => self::$album_image_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()); // album 削除 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->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, self::$album_image_comment->id, \Notice\Site_Util::get_notice_type(self::$type_key))); }