예제 #1
0
 /**
  * Test migrate tables.
  */
 public function test_migrate_tables()
 {
     global $DB;
     $dbman = $DB->get_manager();
     // Rename some tables so they can be set back by the migrator.
     $oldtable = new \xmldb_table('local_elisprogram_cls');
     $dbman->rename_table($oldtable, 'local_elisprogram_aaa');
     $oldtable = new \xmldb_table('local_elisprogram_cls_enrol');
     $dbman->rename_table($oldtable, 'local_elisprogram_bbb');
     // Ensure tables have been renamed.
     $tables = $DB->get_tables(false);
     $this->assertFalse(isset($tables['local_elisprogram_cls']));
     $this->assertFalse(isset($tables['local_elisprogram_cls_enrol']));
     $this->assertTrue(isset($tables['local_elisprogram_aaa']));
     $this->assertTrue(isset($tables['local_elisprogram_bbb']));
     // Run migrator.
     $oldcomponent = 'oldcomponent';
     $newcomponent = 'newcomponent';
     $tablechanges = array('local_elisprogram_aaa' => 'local_elisprogram_cls', 'local_elisprogram_bbb' => 'local_elisprogram_cls_enrol');
     $migrator = new \local_eliscore\install\migration\migrator($oldcomponent, $newcomponent, '', $tablechanges);
     $migrator->migrate_tables();
     // Check tables.
     $tables = $DB->get_tables(false);
     $this->assertTrue(isset($tables['local_elisprogram_cls']));
     $this->assertTrue(isset($tables['local_elisprogram_cls_enrol']));
     $this->assertFalse(isset($tables['local_elisprogram_aaa']));
     $this->assertFalse(isset($tables['local_elisprogram_bbb']));
 }