public function test_can_restore_deleted_section()
 {
     $interrogator = new Interrogator();
     $this->createTestQuestion($interrogator);
     $interrogator->deleteSection(1);
     $this->assertTrue(Section::withTrashed()->first()->trashed());
     $this->assertTrue(Group::withTrashed()->first()->trashed());
     $this->assertTrue(Question::withTrashed()->first()->trashed());
     $interrogator->restoreSection(1);
     $this->assertFalse(Section::first()->trashed());
     $this->assertFalse(Group::first()->trashed());
     $this->assertFalse(Question::first()->trashed());
 }
Exemple #2
0
 /**
  * Resolves Section object regardless of given identifier.
  *
  * @param $section
  * @param bool $withTrashed
  * @return null
  * @throws SectionNotFoundException
  */
 public static function resolveSelf($section, $withTrashed = false)
 {
     if (is_null($section)) {
         return null;
     }
     if (!$section instanceof Section) {
         if (is_numeric($section)) {
             try {
                 if ($withTrashed) {
                     $section = Section::withTrashed()->findOrFail($section);
                 } else {
                     $section = Section::findOrFail($section);
                 }
             } catch (ModelNotFoundException $e) {
                 throw new SectionNotFoundException('Section not found with the given ID.');
             }
         } else {
             try {
                 if ($withTrashed) {
                     $section = Section::withTrashed()->whereSlug($section)->firstOrFail();
                 } else {
                     $section = Section::whereSlug($section)->firstOrFail();
                 }
             } catch (ModelNotFoundException $e) {
                 throw new SectionNotFoundException('Section not found with the given slug.');
             }
         }
     }
     return $section;
 }