Beispiel #1
0
 /**
  * Test the migrate_contextlevels function.
  */
 public function test_migrate_contextlevels()
 {
     global $DB;
     // Setup.
     $ctxoldnewmap = array(1001 => \local_eliscore\context\helper::get_level_from_name('curriculum'), 1002 => \local_eliscore\context\helper::get_level_from_name('track'), 1003 => \local_eliscore\context\helper::get_level_from_name('course'), 1004 => \local_eliscore\context\helper::get_level_from_name('class'), 1005 => \local_eliscore\context\helper::get_level_from_name('user'), 1006 => \local_eliscore\context\helper::get_level_from_name('cluster'));
     $createdrecs = array();
     foreach ($ctxoldnewmap as $oldlevel => $newlevel) {
         $context = new \stdClass();
         $context->contextlevel = $oldlevel;
         $context->instanceid = '1' . $oldlevel;
         $context->path = '/2/' . $oldlevel;
         $context->depth = 2;
         $context->id = $DB->insert_record('context', $context);
         $createdrecs['context'][$oldlevel] = $context->id;
         $fieldclevel = new \stdClass();
         $fieldclevel->fieldid = '2' . $oldlevel;
         $fieldclevel->contextlevel = $oldlevel;
         $fieldclevel->id = $DB->insert_record('local_eliscore_field_clevels', $fieldclevel);
         $createdrecs['local_eliscore_field_clevels'][$oldlevel] = $fieldclevel->id;
         $catctx = new \stdClass();
         $catctx->categoryid = '3' . $oldlevel;
         $catctx->contextlevel = $oldlevel;
         $catctx->id = $DB->insert_record('local_eliscore_fld_cat_ctx', $catctx);
         $createdrecs['local_eliscore_fld_cat_ctx'][$oldlevel] = $catctx->id;
         $rolectx = new \stdClass();
         $rolectx->roleid = '3' . $oldlevel;
         $rolectx->contextlevel = $oldlevel;
         $rolectx->id = $DB->insert_record('role_context_levels', $rolectx);
         $createdrecs['role_context_levels'][$oldlevel] = $rolectx->id;
     }
     // Migrate.
     $migrator = new \local_elisprogram\install\migration\elis26();
     $migrator->migrate_context_levels();
     // Check records.
     foreach ($createdrecs as $table => $recs) {
         foreach ($recs as $oldlevel => $recid) {
             $newlevel = $ctxoldnewmap[$oldlevel];
             $rec = $DB->get_record($table, array('id' => $recid));
             $this->assertEquals($newlevel, $rec->contextlevel);
         }
     }
 }