Example #1
0
 /**
  * Empty all tables so they can be repopulated for tests
  *
  * @param Database $db|null Database to reset
  * @param array $tablesUsed Tables to reset
  */
 private function resetDB($db, $tablesUsed)
 {
     if ($db) {
         $userTables = ['user', 'user_groups', 'user_properties'];
         $coreDBDataTables = array_merge($userTables, ['page', 'revision']);
         // If any of the user tables were marked as used, we should clear all of them.
         if (array_intersect($tablesUsed, $userTables)) {
             $tablesUsed = array_unique(array_merge($tablesUsed, $userTables));
             TestUserRegistry::clear();
         }
         $truncate = in_array($db->getType(), ['oracle', 'mysql']);
         foreach ($tablesUsed as $tbl) {
             // TODO: reset interwiki table to its original content.
             if ($tbl == 'interwiki') {
                 continue;
             }
             if ($truncate) {
                 $db->query('TRUNCATE TABLE ' . $db->tableName($tbl), __METHOD__);
             } else {
                 $db->delete($tbl, '*', __METHOD__);
             }
             if ($tbl === 'page') {
                 // Forget about the pages since they don't
                 // exist in the DB.
                 LinkCache::singleton()->clear();
             }
         }
         if (array_intersect($tablesUsed, $coreDBDataTables)) {
             // Re-add core DB data that was deleted
             $this->addCoreDBData();
         }
     }
 }
 /**
  * Clear the registry.
  *
  * TestUsers created by this class will not be deleted, but any handles
  * to existing immutable TestUsers will be deleted, ensuring these users
  * are not reused. We don't reset the counter or random string by design.
  *
  * @since 1.28
  *
  * @param string[] $groups Groups the test user should be added to.
  * @return TestUser
  */
 public static function clear()
 {
     self::$testUsers = [];
 }