diff --git a/lib/model/doctrine/PluginCommunityEvent.class.php b/lib/model/doctrine/PluginCommunityEvent.class.php index 6b090f0..02d3280 100644 --- a/lib/model/doctrine/PluginCommunityEvent.class.php +++ b/lib/model/doctrine/PluginCommunityEvent.class.php @@ -53,6 +53,19 @@ public function preSave($event) } } + public function preDelete($event) + { + foreach ($this->Images as $eventImage) + { + $eventImage->delete(); + } + + foreach ($this->CommunityEventComment as $eventComment) + { + $eventComment->delete(); + } + } + public function toggleEventMember($memberId) { if ($this->isClosed()) diff --git a/lib/model/doctrine/PluginCommunityEventComment.class.php b/lib/model/doctrine/PluginCommunityEventComment.class.php index 7936e5c..47b7755 100644 --- a/lib/model/doctrine/PluginCommunityEventComment.class.php +++ b/lib/model/doctrine/PluginCommunityEventComment.class.php @@ -32,6 +32,14 @@ public function preSave($event) } } + public function preDelete($event) + { + foreach ($this->Images as $eventCommentImage) + { + $eventCommentImage->delete(); + } + } + public function toggleEventMember($memberId) { $this->getCommunityEvent()->toggleEventMember($memberId); diff --git a/lib/model/doctrine/PluginCommunityTopic.class.php b/lib/model/doctrine/PluginCommunityTopic.class.php index a228312..9b720d6 100644 --- a/lib/model/doctrine/PluginCommunityTopic.class.php +++ b/lib/model/doctrine/PluginCommunityTopic.class.php @@ -47,6 +47,19 @@ public function preSave($event) } } + public function preDelete($event) + { + foreach ($this->Images as $topicImage) + { + $topicImage->delete(); + } + + foreach ($this->CommunityTopicComment as $topicComment) + { + $topicComment->delete(); + } + } + // for pager public function getImageFilename() { diff --git a/lib/model/doctrine/PluginCommunityTopicComment.class.php b/lib/model/doctrine/PluginCommunityTopicComment.class.php index 6afed79..60cf4fa 100644 --- a/lib/model/doctrine/PluginCommunityTopicComment.class.php +++ b/lib/model/doctrine/PluginCommunityTopicComment.class.php @@ -31,4 +31,12 @@ public function preSave($event) $this->setNumber(Doctrine::getTable('CommunityTopicComment')->getMaxNumber($this->getCommunityTopicId()) + 1); } } + + public function preDelete($event) + { + foreach ($this->Images as $topicCommentImage) + { + $topicCommentImage->delete(); + } + } } diff --git a/test/fixtures/999_test_data.yml b/test/fixtures/999_test_data.yml index 6c456ce..a152137 100644 --- a/test/fixtures/999_test_data.yml +++ b/test/fixtures/999_test_data.yml @@ -207,6 +207,7 @@ CommunityMemberPosition: CommunityTopic: community_topic_a_2: + id: 1 name: "_aトピ主" body: "こんにちは" Community: community_a @@ -253,8 +254,18 @@ CommunityTopic: Community: community_a Member: member_html_1 +CommunityTopicImage: + community_topic_a_2_image: + CommunityTopic: community_topic_a_2 + number: 1 + File: + name: dummy_community_topic_a_2_image + type: text/plain + FileBin: { bin: hogehoge } + CommunityTopicComment: community_topic_comment_a_2: + id: 1 body: "こんにちは" CommunityTopic: community_topic_a_2 Member: member_5 @@ -292,8 +303,18 @@ CommunityTopicComment: CommunityTopic: community_topic_html_1 Member: member_html_1 +CommunityTopicCommentImage: + community_topic_comment_a_2_image: + CommunityTopicComment: community_topic_comment_a_2 + number: 1 + File: + name: dummy_community_topic_comment_a_2_image + type: text/plain + FileBin: { bin: hogehoge } + CommunityEvent: community_event_a_2: + id: 1 Community: community_a Member: member_2 name: '_aイベ主' @@ -320,9 +341,18 @@ CommunityEvent: open_date: '2009-06-11' open_date_comment: "<&\"'>CommunityEvent.open_date_comment ESCAPING HTML TEST DATA" area: "<&\"'>CommunityEvent.area ESCAPING HTML TEST DATA" +CommunityEventImage: + community_event_a_2_image: + CommunityEvent: community_event_a_2 + number: 1 + File: + name: dummy_community_event_a_2_image + type: text/plain + FileBin: { bin: hogehoge } CommunityEventComment: community_event_comment_a_2: + id: 1 CommunityEvent: community_event_a_2 Member: member_5 body: 'こんにちは' @@ -336,6 +366,15 @@ CommunityEventComment: Member: member_html_1 body: "<&\"'>CommunityEventComment.body ESCAPING HTML TEST DATA" +CommunityEventCommentImage: + community_event_comment_a_2_image: + CommunityEventComment: community_event_comment_a_2 + number: 1 + File: + name: dummy_community_event_comment_a_2_image + type: text/plain + FileBin: { bin: hogehoge } + CommunityEventMember: community_event_member_a_1: CommunityEvent: community_event_a_2 diff --git a/test/unit/model/CommunityEventCommentTest.php b/test/unit/model/CommunityEventCommentTest.php new file mode 100644 index 0000000..7a5787a --- /dev/null +++ b/test/unit/model/CommunityEventCommentTest.php @@ -0,0 +1,26 @@ +getConnection(); + +//------------------------------------------------------------ +$t->diag('CommunityEventComment: Cascading Delete'); +$conn->beginTransaction(); + +$eventComment = $eventCommentTable->find(1); +$eventCommentImage = $eventComment->Images[0]; +$fileId = $eventCommentImage->file_id; + +$eventComment->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityEventComment')->find($eventComment->id), 'community_event_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventCommentImage')->find($eventCommentImage->id), 'community_event_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($fileId), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($fileId), 'file_bin is deleted.'); + +$conn->rollback(); diff --git a/test/unit/model/CommunityEventTest.php b/test/unit/model/CommunityEventTest.php new file mode 100644 index 0000000..afff016 --- /dev/null +++ b/test/unit/model/CommunityEventTest.php @@ -0,0 +1,40 @@ +diag('CommunityEvent: Cascading Delete'); +$conn->beginTransaction(); + +$event = Doctrine_Core::getTable('CommunityEvent')->find(1); +$eventImage = $event->Images[0]; +$file1Id = $eventImage->file_id; +$eventComment = Doctrine_Core::getTable('CommunityEventComment')->find(1); +$eventCommentImage = $eventComment->Images[0]; +$file2Id = $eventCommentImage->file_id; + +/* + * community_event + * |- community_event_image + * | +- file + * | +- file_bin + * +- community_event_comment + * +- community_event_comment_image + * +- file + * +- file_bin + */ +$event->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityEvent')->find($event->id), 'community_event is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventImage')->find($eventImage->id), 'community_event_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file1Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file1Id), 'file_bin is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventComment')->find($eventComment->id), 'community_event_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityEventCommentImage')->find($eventCommentImage->id), 'community_event_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file2Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file2Id), 'file_bin is deleted.'); + +$conn->rollback(); diff --git a/test/unit/model/CommunityTopicCommentTest.php b/test/unit/model/CommunityTopicCommentTest.php new file mode 100644 index 0000000..cb775f0 --- /dev/null +++ b/test/unit/model/CommunityTopicCommentTest.php @@ -0,0 +1,26 @@ +getConnection(); + +//------------------------------------------------------------ +$t->diag('CommunityTopicComment: Cascading Delete'); +$conn->beginTransaction(); + +$topicComment = $topicCommentTable->find(1); +$topicCommentImage = $topicComment->Images[0]; +$fileId = $topicCommentImage->file_id; + +$topicComment->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityTopicComment')->find($topicComment->id), 'community_topic_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicCommentImage')->find($topicCommentImage->id), 'community_topic_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($fileId), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($fileId), 'file_bin is deleted.'); + +$conn->rollback(); diff --git a/test/unit/model/CommunityTopicTest.php b/test/unit/model/CommunityTopicTest.php index c613b66..db24b22 100644 --- a/test/unit/model/CommunityTopicTest.php +++ b/test/unit/model/CommunityTopicTest.php @@ -3,7 +3,7 @@ include(dirname(__FILE__).'/../../bootstrap/unit.php'); include(dirname(__FILE__).'/../../bootstrap/database.php'); -$t = new lime_test(64, new lime_output_color()); +$t = new lime_test(72); $members = Doctrine::getTable('Member')->createQuery()->orderBy('id')->execute(); $communities = Doctrine::getTable('Community')->createQuery()->orderBy('id')->execute(); @@ -192,3 +192,37 @@ function getAcl($object) $t->cmp_ok($acl->isAllowed(1, null, 'view'), '===', true, 'returns true for the community admin'); $t->cmp_ok($acl->isAllowed(3, null, 'view'), '===', true, 'returns true for a community member'); $t->cmp_ok($acl->isAllowed(4, null, 'view'), '===', true, 'returns true for a non-community member'); + +//------------------------------------------------------------ +$t->diag('CommunityTopic: Cascading Delete'); +$conn->beginTransaction(); + +$topic = Doctrine_Core::getTable('CommunityTopic')->find(1); +$topicImage = $topic->Images[0]; +$file1Id = $topicImage->file_id; +$topicComment = Doctrine_Core::getTable('CommunityTopicComment')->find(1); +$topicCommentImage = $topicComment->Images[0]; +$file2Id = $topicCommentImage->file_id; + +/* + * community_topic + * |- community_topic_image + * | +- file + * | +- file_bin + * +- community_topic_comment + * +- community_topic_comment_image + * +- file + * +- file_bin + */ +$topic->delete($conn); + +$t->ok(!Doctrine_Core::getTable('CommunityTopic')->find($topic->id), 'community_topic is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicImage')->find($topicImage->id), 'community_topic_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file1Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file1Id), 'file_bin is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicComment')->find($topicComment->id), 'community_topic_comment is deleted.'); +$t->ok(!Doctrine_Core::getTable('CommunityTopicCommentImage')->find($topicCommentImage->id), 'community_topic_comment_image is deleted.'); +$t->ok(!Doctrine_Core::getTable('File')->find($file2Id), 'file is deleted.'); +$t->ok(!Doctrine_Core::getTable('FileBin')->find($file2Id), 'file_bin is deleted.'); + +$conn->rollback();