Exemplo n.º 1
0
 public function test_deleting_section_soft_deletes_its_topics()
 {
     // GIVEN we have a user
     $user = factory(User::class, 1)->create();
     // AND we have a section
     $section = factory(Section::class, 1)->create(['parent_id' => null, 'user_id' => $user->id]);
     // AND that section has topics
     factory(Topic::class, 10)->create(['section_id' => $section->id]);
     $topicsInSectionCount = $section->topics->count();
     $topicCount = Topic::all()->count();
     // WHEN we delete that section
     $section->delete();
     // THEN the total number of topics is reduced by the number of topics
     // belonging to the original section
     $topicCountAfterDeletion = Topic::all()->count();
     $this->assertEquals($topicCount - $topicsInSectionCount, $topicCountAfterDeletion);
     // AND the count of topics for that section is now zero
     $this->assertEquals(Topic::where('section_id', $section->id)->count(), 0);
     // BUT that section has soft deleted topics with match the orignal count
     $this->assertEquals(Topic::withTrashed()->where('section_id', $section->id)->count(), $topicsInSectionCount);
 }