Merge branch 'w38_MDL-35129_m24_dbmigration' of git://github.com/skodak/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 17 Sep 2012 23:12:17 +0000 (01:12 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Mon, 17 Sep 2012 23:12:17 +0000 (01:12 +0200)
1  2 
lib/dml/tests/dml_test.php

@@@ -51,6 -51,17 +51,6 @@@ class dml_testcase extends database_dri
          return new xmldb_table($tablename);
      }
  
 -    protected function enable_debugging() {
 -        ob_start(); // hide debug warning
 -    }
 -
 -    protected function get_debugging() {
 -        $debuginfo = ob_get_contents();
 -        ob_end_clean();
 -
 -        return $debuginfo;
 -    }
 -
      function test_diagnose() {
          $DB = $this->tdb;
          $result = $DB->diagnose();
          $conditions = array('onetext' => '1');
          try {
              $rs = $DB->get_recordset($tablename, $conditions);
 -            if (debugging()) {
 -                // only in debug mode - hopefully all devs test code in debug mode...
 -                $this->fail('An Exception is missing, expected due to equating of text fields');
 -            }
 +            $this->fail('An Exception is missing, expected due to equating of text fields');
          } catch (exception $e) {
              $this->assertTrue($e instanceof dml_exception);
              $this->assertEquals($e->errorcode, 'textconditionsnotallowed');
          // note: fetching nulls, empties, LOBs already tested by test_insert_record() no needed here
      }
  
+     public function test_export_table_recordset() {
+         $DB = $this->tdb;
+         $dbman = $DB->get_manager();
+         $table = $this->get_test_table();
+         $tablename = $table->getName();
+         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
+         $table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
+         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
+         $dbman->create_table($table);
+         $ids = array();
+         $ids[] = $DB->insert_record($tablename, array('course' => 3));
+         $ids[] = $DB->insert_record($tablename, array('course' => 5));
+         $ids[] = $DB->insert_record($tablename, array('course' => 4));
+         $ids[] = $DB->insert_record($tablename, array('course' => 3));
+         $ids[] = $DB->insert_record($tablename, array('course' => 2));
+         $ids[] = $DB->insert_record($tablename, array('course' => 1));
+         $ids[] = $DB->insert_record($tablename, array('course' => 0));
+         $rs = $DB->export_table_recordset($tablename);
+         $rids = array();
+         foreach ($rs as $record) {
+             $rids[] = $record->id;
+         }
+         $rs->close();
+         $this->assertEquals($ids, $rids, '', 0, 0, true);
+     }
      public function test_get_records() {
          $DB = $this->tdb;
          $dbman = $DB->get_manager();
      }
  
      public function test_get_records_sql() {
 +        global $CFG;
 +
          $DB = $this->tdb;
          $dbman = $DB->get_manager();
  
          $this->assertEquals($inskey4, next($records)->id);
  
          // Awful test, requires debug enabled and sent to browser. Let's do that and restore after test
 -        $this->enable_debugging();
          $records = $DB->get_records_sql("SELECT course AS id, course AS course FROM {{$tablename}}", null);
 -        $this->assertFalse($this->get_debugging() === '');
 +        $this->assertDebuggingCalled();
          $this->assertEquals(6, count($records));
 +        $CFG->debug = DEBUG_MINIMAL;
 +        $records = $DB->get_records_sql("SELECT course AS id, course AS course FROM {{$tablename}}", null);
 +        $this->assertDebuggingNotCalled();
 +        $this->assertEquals(6, count($records));
 +        $CFG->debug = DEBUG_DEVELOPER;
  
          // negative limits = no limits
          $records = $DB->get_records_sql("SELECT * FROM {{$tablename}} ORDER BY id", null, -1, -1);
      }
  
      public function test_get_record_sql() {
 +        global $CFG;
 +
          $DB = $this->tdb;
          $dbman = $DB->get_manager();
  
              $this->assertTrue(true);
          }
  
 -        $this->enable_debugging();
          $this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MISSING));
 -        $this->assertFalse($this->get_debugging() === '');
 +        $this->assertDebuggingCalled();
 +        $CFG->debug = DEBUG_MINIMAL;
 +        $this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MISSING));
 +        $this->assertDebuggingNotCalled();
 +        $CFG->debug = DEBUG_DEVELOPER;
  
          // multiple matches ignored
          $this->assertNotEmpty($DB->get_record_sql("SELECT * FROM {{$tablename}}", array(), IGNORE_MULTIPLE));
              $this->assertTrue(true);
          }
  
 -        $this->enable_debugging();
          $this->assertEquals(5, $DB->get_field($tablename, 'course', array('course' => 5), IGNORE_MULTIPLE));
 -        $this->assertSame($this->get_debugging(), '');
 +        $this->assertDebuggingNotCalled();
  
 -        $this->enable_debugging();
          $this->assertEquals(5, $DB->get_field($tablename, 'course', array('course' => 5), IGNORE_MISSING));
 -        $this->assertFalse($this->get_debugging() === '');
 +        $this->assertDebuggingCalled();
  
          // test for exception throwing on text conditions being compared. (MDL-24863, unwanted auto conversion of param to int)
          $conditions = array('onetext' => '1');