public function testRelatedPagesModule()
 {
     $module = RelatedPagesModule::create();
     $module->ShowSearch = true;
     $module->HasCategories = true;
     $module->ShowCategories = true;
     $module->UseChildren = true;
     $module->write();
     $this->assertTrue($module->ID > 0);
     $page = Page::create();
     $page->Title = 'Test';
     $page->write();
     $module->Pages()->add($page);
     $this->assertEquals($module->Pages()->count(), 1);
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     //fix up pages which just used the parent
     $modules = RelatedPagesModule::get();
     if ($modules && $modules->count()) {
         foreach ($modules as $module) {
             if ($module->UseChildren && !$module->TopLevelPageID) {
                 //lookup page which has this module
                 $pageID = DB::query('SELECT "PageID" FROM "Page_ContentModules" WHERE "ContentModuleID" = ' . $module->ID)->value();
                 if ($pageID) {
                     $module->TopLevelPageID = $pageID;
                     $module->write();
                     $module->publish('Stage', 'Live');
                 }
             }
         }
     }
 }