Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 81... Línea 81...
81
            return str_replace('/', DIRECTORY_SEPARATOR, $source);
81
            return str_replace('/', DIRECTORY_SEPARATOR, $source);
82
        }
82
        }
83
        return $source; // No changes, so far.
83
        return $source; // No changes, so far.
84
    }
84
    }
Línea 85... Línea 85...
85
 
85
 
86
    public function test_diagnose() {
86
    public function test_diagnose(): void {
87
        $DB = $this->tdb;
87
        $DB = $this->tdb;
88
        $result = $DB->diagnose();
88
        $result = $DB->diagnose();
89
        $this->assertNull($result, 'Database self diagnostics failed %s');
89
        $this->assertNull($result, 'Database self diagnostics failed %s');
Línea 90... Línea 90...
90
    }
90
    }
91
 
91
 
92
    public function test_get_server_info() {
92
    public function test_get_server_info(): void {
93
        $DB = $this->tdb;
93
        $DB = $this->tdb;
94
        $result = $DB->get_server_info();
94
        $result = $DB->get_server_info();
95
        $this->assertIsArray($result);
95
        $this->assertIsArray($result);
96
        $this->assertArrayHasKey('description', $result);
96
        $this->assertArrayHasKey('description', $result);
Línea 97... Línea 97...
97
        $this->assertArrayHasKey('version', $result);
97
        $this->assertArrayHasKey('version', $result);
98
    }
98
    }
Línea 99... Línea 99...
99
 
99
 
Línea 100... Línea 100...
100
    public function test_get_in_or_equal() {
100
    public function test_get_in_or_equal(): void {
Línea 303... Línea 303...
303
        $key = key($params);
303
        $key = key($params);
304
        $this->assertSame('<> :'.$key, $usql);
304
        $this->assertSame('<> :'.$key, $usql);
305
        $this->assertSame($value, 'onevalue');
305
        $this->assertSame($value, 'onevalue');
306
    }
306
    }
Línea 307... Línea 307...
307
 
307
 
308
    public function test_fix_table_names() {
308
    public function test_fix_table_names(): void {
309
        $DB = new moodle_database_for_testing();
309
        $DB = new moodle_database_for_testing();
Línea 310... Línea 310...
310
        $prefix = $DB->get_prefix();
310
        $prefix = $DB->get_prefix();
311
 
311
 
Línea 325... Línea 325...
325
        $sql = "SELECT * FROM {user}, {funny_table_name}, {mdl_stupid_table} WHERE {user}.id = {funny_table_name}.userid";
325
        $sql = "SELECT * FROM {user}, {funny_table_name}, {mdl_stupid_table} WHERE {user}.id = {funny_table_name}.userid";
326
        $expected = "SELECT * FROM {$prefix}user, {$prefix}funny_table_name, {$prefix}mdl_stupid_table WHERE {$prefix}user.id = {$prefix}funny_table_name.userid";
326
        $expected = "SELECT * FROM {$prefix}user, {$prefix}funny_table_name, {$prefix}mdl_stupid_table WHERE {$prefix}user.id = {$prefix}funny_table_name.userid";
327
        $this->assertSame($expected, $DB->public_fix_table_names($sql));
327
        $this->assertSame($expected, $DB->public_fix_table_names($sql));
328
    }
328
    }
Línea 329... Línea 329...
329
 
329
 
330
    public function test_fix_sql_params() {
330
    public function test_fix_sql_params(): void {
331
        $DB = $this->tdb;
331
        $DB = $this->tdb;
Línea 332... Línea 332...
332
        $prefix = $DB->get_prefix();
332
        $prefix = $DB->get_prefix();
333
 
333
 
Línea 480... Línea 480...
480
    }
480
    }
Línea 481... Línea 481...
481
 
481
 
482
    /**
482
    /**
483
     * Test the database debugging as SQL comment.
483
     * Test the database debugging as SQL comment.
484
     */
484
     */
485
    public function test_add_sql_debugging() {
485
    public function test_add_sql_debugging(): void {
486
        global $CFG;
486
        global $CFG;
Línea 487... Línea 487...
487
        $DB = $this->tdb;
487
        $DB = $this->tdb;
488
 
488
 
Línea 531... Línea 531...
531
    /**
531
    /**
532
     * Test the database debugging as SQL comment in anon class
532
     * Test the database debugging as SQL comment in anon class
533
     *
533
     *
534
     * @covers ::add_sql_debugging
534
     * @covers ::add_sql_debugging
535
     */
535
     */
536
    public function test_sql_debugging_anon_class() {
536
    public function test_sql_debugging_anon_class(): void {
537
        global $CFG;
537
        global $CFG;
538
        $CFG->debugsqltrace = 100;
538
        $CFG->debugsqltrace = 100;
Línea 539... Línea 539...
539
 
539
 
540
        // A anon class.
540
        // A anon class.
Línea 551... Línea 551...
551
        $site = $another->get_site();
551
        $site = $another->get_site();
552
        $CFG->debugsqltrace = 0;
552
        $CFG->debugsqltrace = 0;
553
        $this->assertEquals(get_site(), $site);
553
        $this->assertEquals(get_site(), $site);
554
    }
554
    }
Línea 555... Línea 555...
555
 
555
 
556
    public function test_strtok() {
556
    public function test_strtok(): void {
557
        // Strtok was previously used by bound emulation, make sure it is not used any more.
557
        // Strtok was previously used by bound emulation, make sure it is not used any more.
558
        $DB = $this->tdb;
558
        $DB = $this->tdb;
Línea 559... Línea 559...
559
        $dbman = $this->tdb->get_manager();
559
        $dbman = $this->tdb->get_manager();
Línea 573... Línea 573...
573
        $DB->get_records($tablename, array('id'=>1));
573
        $DB->get_records($tablename, array('id'=>1));
Línea 574... Línea 574...
574
 
574
 
575
        $this->assertSame(strtok('?'), 'b');
575
        $this->assertSame(strtok('?'), 'b');
Línea 576... Línea 576...
576
    }
576
    }
Línea 577... Línea 577...
577
 
577
 
578
    public function test_tweak_param_names() {
578
    public function test_tweak_param_names(): void {
579
 
579
 
580
        // Note the tweak_param_names() method is only available in the oracle driver,
580
        // Note the tweak_param_names() method is only available in the oracle driver,
Línea 717... Línea 717...
717
        // Execute().
717
        // Execute().
718
        $DB->execute("DELETE FROM {{$tablename}} WHERE $select", (array)$rec1);
718
        $DB->execute("DELETE FROM {{$tablename}} WHERE $select", (array)$rec1);
719
        $this->assertEquals(0, $DB->count_records($tablename));
719
        $this->assertEquals(0, $DB->count_records($tablename));
720
    }
720
    }
Línea 721... Línea 721...
721
 
721
 
722
    public function test_get_tables() {
722
    public function test_get_tables(): void {
723
        $DB = $this->tdb;
723
        $DB = $this->tdb;
Línea 724... Línea 724...
724
        $dbman = $this->tdb->get_manager();
724
        $dbman = $this->tdb->get_manager();
725
 
725
 
Línea 737... Línea 737...
737
 
737
 
738
        $dbman->drop_table($table);
738
        $dbman->drop_table($table);
739
        $this->assertTrue(count($DB->get_tables()) == $original_count);
739
        $this->assertTrue(count($DB->get_tables()) == $original_count);
Línea 740... Línea 740...
740
    }
740
    }
741
 
741
 
742
    public function test_get_indexes() {
742
    public function test_get_indexes(): void {
Línea 743... Línea 743...
743
        $DB = $this->tdb;
743
        $DB = $this->tdb;
744
        $dbman = $this->tdb->get_manager();
744
        $dbman = $this->tdb->get_manager();
Línea 783... Línea 783...
783
     *
783
     *
784
     * Note that, strictly speaking, unique indexes on null columns are far from ideal. Both
784
     * Note that, strictly speaking, unique indexes on null columns are far from ideal. Both
785
     * conceptually and also in practice, because they cause DBs to use full scans in a
785
     * conceptually and also in practice, because they cause DBs to use full scans in a
786
     * number of situations. But if we support them, we need to ensure get_indexes() work on them.
786
     * number of situations. But if we support them, we need to ensure get_indexes() work on them.
787
     */
787
     */
788
    public function test_get_indexes_unique_mixed_nullability() {
788
    public function test_get_indexes_unique_mixed_nullability(): void {
789
        $DB = $this->tdb;
789
        $DB = $this->tdb;
790
        $dbman = $this->tdb->get_manager();
790
        $dbman = $this->tdb->get_manager();
791
        $table = $this->get_test_table();
791
        $table = $this->get_test_table();
792
        $tablename = $table->getName();
792
        $tablename = $table->getName();
Línea 808... Línea 808...
808
        $index = array_shift($indexes);
808
        $index = array_shift($indexes);
809
        $this->assertTrue($index['unique']);
809
        $this->assertTrue($index['unique']);
810
        $this->assertSame($indexcolumns, $index['columns']);
810
        $this->assertSame($indexcolumns, $index['columns']);
811
    }
811
    }
Línea 812... Línea 812...
812
 
812
 
813
    public function test_get_columns() {
813
    public function test_get_columns(): void {
814
        $DB = $this->tdb;
814
        $DB = $this->tdb;
Línea 815... Línea 815...
815
        $dbman = $this->tdb->get_manager();
815
        $dbman = $this->tdb->get_manager();
816
 
816
 
Línea 987... Línea 987...
987
 
987
 
988
        $columns = $DB->get_columns($tablename);
988
        $columns = $DB->get_columns($tablename);
989
        $this->assertFalse($columns['id']->auto_increment);
989
        $this->assertFalse($columns['id']->auto_increment);
Línea 990... Línea 990...
990
    }
990
    }
991
 
991
 
992
    public function test_get_manager() {
992
    public function test_get_manager(): void {
Línea 993... Línea 993...
993
        $DB = $this->tdb;
993
        $DB = $this->tdb;
994
        $dbman = $this->tdb->get_manager();
994
        $dbman = $this->tdb->get_manager();
Línea 995... Línea 995...
995
 
995
 
996
        $this->assertInstanceOf('database_manager', $dbman);
996
        $this->assertInstanceOf('database_manager', $dbman);
997
    }
997
    }
998
 
998
 
Línea 999... Línea 999...
999
    public function test_setup_is_unicodedb() {
999
    public function test_setup_is_unicodedb(): void {
1000
        $DB = $this->tdb;
1000
        $DB = $this->tdb;
1001
        $this->assertTrue($DB->setup_is_unicodedb());
1001
        $this->assertTrue($DB->setup_is_unicodedb());
Línea 1002... Línea 1002...
1002
    }
1002
    }
1003
 
1003
 
Línea 1034... Línea 1034...
1034
        $this->assertTrue($debuginfo === '');
1034
        $this->assertTrue($debuginfo === '');
Línea 1035... Línea 1035...
1035
 
1035
 
1036
        $DB->set_debug($prevdebug);
1036
        $DB->set_debug($prevdebug);
Línea 1037... Línea 1037...
1037
    }
1037
    }
1038
 
1038
 
1039
    public function test_execute() {
1039
    public function test_execute(): void {
Línea 1040... Línea 1040...
1040
        $DB = $this->tdb;
1040
        $DB = $this->tdb;
1041
        $dbman = $this->tdb->get_manager();
1041
        $dbman = $this->tdb->get_manager();
Línea 1124... Línea 1124...
1124
        $this->assertCount(1, $records);
1124
        $this->assertCount(1, $records);
1125
        $record = reset($records);
1125
        $record = reset($records);
1126
        $this->assertSame($newonetext, $record->onetext);
1126
        $this->assertSame($newonetext, $record->onetext);
1127
    }
1127
    }
Línea 1128... Línea 1128...
1128
 
1128
 
1129
    public function test_get_recordset() {
1129
    public function test_get_recordset(): void {
1130
        $DB = $this->tdb;
1130
        $DB = $this->tdb;
Línea 1131... Línea 1131...
1131
        $dbman = $DB->get_manager();
1131
        $dbman = $DB->get_manager();
1132
 
1132
 
Línea 1226... Línea 1226...
1226
        // Notes:
1226
        // Notes:
1227
        //  * limits are tested in test_get_recordset_sql()
1227
        //  * limits are tested in test_get_recordset_sql()
1228
        //  * where_clause() is used internally and is tested in test_get_records()
1228
        //  * where_clause() is used internally and is tested in test_get_records()
1229
    }
1229
    }
Línea 1230... Línea 1230...
1230
 
1230
 
1231
    public function test_get_recordset_static() {
1231
    public function test_get_recordset_static(): void {
1232
        $DB = $this->tdb;
1232
        $DB = $this->tdb;
Línea 1233... Línea 1233...
1233
        $dbman = $DB->get_manager();
1233
        $dbman = $DB->get_manager();
1234
 
1234
 
Línea 1278... Línea 1278...
1278
        }
1278
        }
1279
        $rs->close();
1279
        $rs->close();
1280
        $this->assertEquals(3, $i);
1280
        $this->assertEquals(3, $i);
1281
    }
1281
    }
Línea 1282... Línea 1282...
1282
 
1282
 
1283
    public function test_get_recordset_iterator_keys() {
1283
    public function test_get_recordset_iterator_keys(): void {
1284
        $DB = $this->tdb;
1284
        $DB = $this->tdb;
Línea 1285... Línea 1285...
1285
        $dbman = $DB->get_manager();
1285
        $dbman = $DB->get_manager();
1286
 
1286
 
Línea 1343... Línea 1343...
1343
        }
1343
        }
1344
        $rs->close();
1344
        $rs->close();
1345
        $this->assertEquals(3, $count);
1345
        $this->assertEquals(3, $count);
1346
    }
1346
    }
Línea 1347... Línea 1347...
1347
 
1347
 
1348
    public function test_get_recordset_list() {
1348
    public function test_get_recordset_list(): void {
1349
        $DB = $this->tdb;
1349
        $DB = $this->tdb;
Línea 1350... Línea 1350...
1350
        $dbman = $DB->get_manager();
1350
        $dbman = $DB->get_manager();
1351
 
1351
 
Línea 1434... Línea 1434...
1434
        // Notes:
1434
        // Notes:
1435
        //  * limits are tested in test_get_recordset_sql()
1435
        //  * limits are tested in test_get_recordset_sql()
1436
        //  * where_clause() is used internally and is tested in test_get_records()
1436
        //  * where_clause() is used internally and is tested in test_get_records()
1437
    }
1437
    }
Línea 1438... Línea 1438...
1438
 
1438
 
1439
    public function test_get_recordset_select() {
1439
    public function test_get_recordset_select(): void {
1440
        $DB = $this->tdb;
1440
        $DB = $this->tdb;
Línea 1441... Línea 1441...
1441
        $dbman = $DB->get_manager();
1441
        $dbman = $DB->get_manager();
1442
 
1442
 
Línea 1471... Línea 1471...
1471
 
1471
 
1472
        // Notes:
1472
        // Notes:
1473
        //  * limits are tested in test_get_recordset_sql()
1473
        //  * limits are tested in test_get_recordset_sql()
Línea 1474... Línea 1474...
1474
    }
1474
    }
1475
 
1475
 
1476
    public function test_get_recordset_sql() {
1476
    public function test_get_recordset_sql(): void {
Línea 1477... Línea 1477...
1477
        $DB = $this->tdb;
1477
        $DB = $this->tdb;
1478
        $dbman = $DB->get_manager();
1478
        $dbman = $DB->get_manager();
Línea 1514... Línea 1514...
1514
        $this->assertEquals($inskey7, end($records)->id);
1514
        $this->assertEquals($inskey7, end($records)->id);
Línea 1515... Línea 1515...
1515
 
1515
 
1516
        // Note: fetching nulls, empties, LOBs already tested by test_insert_record() no needed here.
1516
        // Note: fetching nulls, empties, LOBs already tested by test_insert_record() no needed here.
Línea 1517... Línea 1517...
1517
    }
1517
    }
1518
 
1518
 
1519
    public function test_export_table_recordset() {
1519
    public function test_export_table_recordset(): void {
Línea 1520... Línea 1520...
1520
        $DB = $this->tdb;
1520
        $DB = $this->tdb;
1521
        $dbman = $DB->get_manager();
1521
        $dbman = $DB->get_manager();
Línea 1544... Línea 1544...
1544
        }
1544
        }
1545
        $rs->close();
1545
        $rs->close();
1546
        $this->assertEqualsCanonicalizing($ids, $rids);
1546
        $this->assertEqualsCanonicalizing($ids, $rids);
1547
    }
1547
    }
Línea 1548... Línea 1548...
1548
 
1548
 
1549
    public function test_get_records() {
1549
    public function test_get_records(): void {
1550
        $DB = $this->tdb;
1550
        $DB = $this->tdb;
Línea 1551... Línea 1551...
1551
        $dbman = $DB->get_manager();
1551
        $dbman = $DB->get_manager();
1552
 
1552
 
Línea 1652... Línea 1652...
1652
        }
1652
        }
Línea 1653... Línea 1653...
1653
 
1653
 
1654
        // Note: delegate limits testing to test_get_records_sql().
1654
        // Note: delegate limits testing to test_get_records_sql().
Línea 1655... Línea 1655...
1655
    }
1655
    }
1656
 
1656
 
1657
    public function test_get_records_list() {
1657
    public function test_get_records_list(): void {
Línea 1658... Línea 1658...
1658
        $DB = $this->tdb;
1658
        $DB = $this->tdb;
1659
        $dbman = $DB->get_manager();
1659
        $dbman = $DB->get_manager();
Línea 1682... Línea 1682...
1682
        $this->assertCount(0, $records);
1682
        $this->assertCount(0, $records);
Línea 1683... Línea 1683...
1683
 
1683
 
1684
        // Note: delegate limits testing to test_get_records_sql().
1684
        // Note: delegate limits testing to test_get_records_sql().
Línea 1685... Línea 1685...
1685
    }
1685
    }
1686
 
1686
 
1687
    public function test_get_records_sql() {
1687
    public function test_get_records_sql(): void {
Línea 1688... Línea 1688...
1688
        $DB = $this->tdb;
1688
        $DB = $this->tdb;
1689
        $dbman = $DB->get_manager();
1689
        $dbman = $DB->get_manager();
Línea 1801... Línea 1801...
1801
        // TODO: Test limits in queries having DISTINCT clauses.
1801
        // TODO: Test limits in queries having DISTINCT clauses.
Línea 1802... Línea 1802...
1802
 
1802
 
1803
        // Note: fetching nulls, empties, LOBs already tested by test_update_record() no needed here.
1803
        // Note: fetching nulls, empties, LOBs already tested by test_update_record() no needed here.
Línea 1804... Línea 1804...
1804
    }
1804
    }
1805
 
1805
 
1806
    public function test_get_records_menu() {
1806
    public function test_get_records_menu(): void {
Línea 1807... Línea 1807...
1807
        $DB = $this->tdb;
1807
        $DB = $this->tdb;
1808
        $dbman = $DB->get_manager();
1808
        $dbman = $DB->get_manager();
Línea 1829... Línea 1829...
1829
        $this->assertEquals(3, $records[2]);
1829
        $this->assertEquals(3, $records[2]);
Línea 1830... Línea 1830...
1830
 
1830
 
1831
        // Note: delegate limits testing to test_get_records_sql().
1831
        // Note: delegate limits testing to test_get_records_sql().
Línea 1832... Línea 1832...
1832
    }
1832
    }
1833
 
1833
 
1834
    public function test_get_records_select_menu() {
1834
    public function test_get_records_select_menu(): void {
Línea 1835... Línea 1835...
1835
        $DB = $this->tdb;
1835
        $DB = $this->tdb;
1836
        $dbman = $DB->get_manager();
1836
        $dbman = $DB->get_manager();
Línea 1861... Línea 1861...
1861
        $this->assertSame('5', $records[4]);
1861
        $this->assertSame('5', $records[4]);
Línea 1862... Línea 1862...
1862
 
1862
 
1863
        // Note: delegate limits testing to test_get_records_sql().
1863
        // Note: delegate limits testing to test_get_records_sql().
Línea 1864... Línea 1864...
1864
    }
1864
    }
1865
 
1865
 
1866
    public function test_get_records_sql_menu() {
1866
    public function test_get_records_sql_menu(): void {
Línea 1867... Línea 1867...
1867
        $DB = $this->tdb;
1867
        $DB = $this->tdb;
1868
        $dbman = $DB->get_manager();
1868
        $dbman = $DB->get_manager();
Línea 1893... Línea 1893...
1893
        $this->assertSame('5', $records[4]);
1893
        $this->assertSame('5', $records[4]);
Línea 1894... Línea 1894...
1894
 
1894
 
1895
        // Note: delegate limits testing to test_get_records_sql().
1895
        // Note: delegate limits testing to test_get_records_sql().
Línea 1896... Línea 1896...
1896
    }
1896
    }
1897
 
1897
 
1898
    public function test_get_record() {
1898
    public function test_get_record(): void {
Línea 1899... Línea 1899...
1899
        $DB = $this->tdb;
1899
        $DB = $this->tdb;
1900
        $dbman = $DB->get_manager();
1900
        $dbman = $DB->get_manager();
Línea 1916... Línea 1916...
1916
        $this->assertEquals(2, $record->course);
1916
        $this->assertEquals(2, $record->course);
1917
        $this->assertEquals(2, $record->id);
1917
        $this->assertEquals(2, $record->id);
1918
    }
1918
    }
Línea 1919... Línea 1919...
1919
 
1919
 
1920
 
1920
 
1921
    public function test_get_record_select() {
1921
    public function test_get_record_select(): void {
Línea 1922... Línea 1922...
1922
        $DB = $this->tdb;
1922
        $DB = $this->tdb;
1923
        $dbman = $DB->get_manager();
1923
        $dbman = $DB->get_manager();
Línea 1939... Línea 1939...
1939
        $this->assertEquals(2, $record->course);
1939
        $this->assertEquals(2, $record->course);
Línea 1940... Línea 1940...
1940
 
1940
 
1941
        // Note: delegates limit testing to test_get_records_sql().
1941
        // Note: delegates limit testing to test_get_records_sql().
Línea 1942... Línea 1942...
1942
    }
1942
    }
1943
 
1943
 
1944
    public function test_get_record_sql() {
1944
    public function test_get_record_sql(): void {
Línea 1945... Línea 1945...
1945
        $DB = $this->tdb;
1945
        $DB = $this->tdb;
1946
        $dbman = $DB->get_manager();
1946
        $dbman = $DB->get_manager();
Línea 1995... Línea 1995...
1995
        } catch (dml_multiple_records_exception $e) {
1995
        } catch (dml_multiple_records_exception $e) {
1996
            $this->assertTrue(true);
1996
            $this->assertTrue(true);
1997
        }
1997
        }
1998
    }
1998
    }
Línea 1999... Línea 1999...
1999
 
1999
 
2000
    public function test_get_field() {
2000
    public function test_get_field(): void {
2001
        $DB = $this->tdb;
2001
        $DB = $this->tdb;
Línea 2002... Línea 2002...
2002
        $dbman = $DB->get_manager();
2002
        $dbman = $DB->get_manager();
2003
 
2003
 
Línea 2043... Línea 2043...
2043
            $this->assertInstanceOf('dml_exception', $e);
2043
            $this->assertInstanceOf('dml_exception', $e);
2044
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
2044
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
2045
        }
2045
        }
2046
    }
2046
    }
Línea 2047... Línea 2047...
2047
 
2047
 
2048
    public function test_get_field_select() {
2048
    public function test_get_field_select(): void {
2049
        $DB = $this->tdb;
2049
        $DB = $this->tdb;
Línea 2050... Línea 2050...
2050
        $dbman = $DB->get_manager();
2050
        $dbman = $DB->get_manager();
2051
 
2051
 
Línea 2060... Línea 2060...
2060
        $DB->insert_record($tablename, array('course' => 3));
2060
        $DB->insert_record($tablename, array('course' => 3));
Línea 2061... Línea 2061...
2061
 
2061
 
2062
        $this->assertEquals(3, $DB->get_field_select($tablename, 'course', "id = ?", array(1)));
2062
        $this->assertEquals(3, $DB->get_field_select($tablename, 'course', "id = ?", array(1)));
Línea 2063... Línea 2063...
2063
    }
2063
    }
2064
 
2064
 
2065
    public function test_get_field_sql() {
2065
    public function test_get_field_sql(): void {
Línea 2066... Línea 2066...
2066
        $DB = $this->tdb;
2066
        $DB = $this->tdb;
2067
        $dbman = $DB->get_manager();
2067
        $dbman = $DB->get_manager();
Línea 2077... Línea 2077...
2077
        $DB->insert_record($tablename, array('course' => 3));
2077
        $DB->insert_record($tablename, array('course' => 3));
Línea 2078... Línea 2078...
2078
 
2078
 
2079
        $this->assertEquals(3, $DB->get_field_sql("SELECT course FROM {{$tablename}} WHERE id = ?", array(1)));
2079
        $this->assertEquals(3, $DB->get_field_sql("SELECT course FROM {{$tablename}} WHERE id = ?", array(1)));
Línea 2080... Línea 2080...
2080
    }
2080
    }
2081
 
2081
 
2082
    public function test_get_fieldset() {
2082
    public function test_get_fieldset(): void {
Línea 2083... Línea 2083...
2083
        $DB = $this->tdb;
2083
        $DB = $this->tdb;
2084
        $dbman = $DB->get_manager();
2084
        $dbman = $DB->get_manager();
Línea 2103... Línea 2103...
2103
        $this->assertEquals(1, $fieldset[0]);
2103
        $this->assertEquals(1, $fieldset[0]);
2104
        $this->assertEquals(2, $fieldset[1]);
2104
        $this->assertEquals(2, $fieldset[1]);
2105
        $this->assertEquals(4, $fieldset[2]);
2105
        $this->assertEquals(4, $fieldset[2]);
2106
    }
2106
    }
Línea 2107... Línea 2107...
2107
 
2107
 
2108
    public function test_get_fieldset_select() {
2108
    public function test_get_fieldset_select(): void {
2109
        $DB = $this->tdb;
2109
        $DB = $this->tdb;
Línea 2110... Línea 2110...
2110
        $dbman = $DB->get_manager();
2110
        $dbman = $DB->get_manager();
2111
 
2111
 
Línea 2129... Línea 2129...
2129
        $this->assertEquals(3, $fieldset[0]);
2129
        $this->assertEquals(3, $fieldset[0]);
2130
        $this->assertEquals(2, $fieldset[1]);
2130
        $this->assertEquals(2, $fieldset[1]);
2131
        $this->assertEquals(6, $fieldset[2]);
2131
        $this->assertEquals(6, $fieldset[2]);
2132
    }
2132
    }
Línea 2133... Línea 2133...
2133
 
2133
 
2134
    public function test_get_fieldset_sql() {
2134
    public function test_get_fieldset_sql(): void {
2135
        $DB = $this->tdb;
2135
        $DB = $this->tdb;
Línea 2136... Línea 2136...
2136
        $dbman = $DB->get_manager();
2136
        $dbman = $DB->get_manager();
2137
 
2137
 
Línea 2166... Línea 2166...
2166
        $this->assertEquals($binarydata, $fieldset[0]);
2166
        $this->assertEquals($binarydata, $fieldset[0]);
2167
        $this->assertEquals($binarydata, $fieldset[1]);
2167
        $this->assertEquals($binarydata, $fieldset[1]);
2168
        $this->assertEquals($binarydata, $fieldset[2]);
2168
        $this->assertEquals($binarydata, $fieldset[2]);
2169
    }
2169
    }
Línea 2170... Línea 2170...
2170
 
2170
 
2171
    public function test_insert_record_raw() {
2171
    public function test_insert_record_raw(): void {
2172
        $DB = $this->tdb;
2172
        $DB = $this->tdb;
Línea 2173... Línea 2173...
2173
        $dbman = $DB->get_manager();
2173
        $dbman = $DB->get_manager();
2174
 
2174
 
Línea 2236... Línea 2236...
2236
        $DB->insert_record_raw($tablename, $record, false, false, true);
2236
        $DB->insert_record_raw($tablename, $record, false, false, true);
2237
        $record = $DB->get_record($tablename, array());
2237
        $record = $DB->get_record($tablename, array());
2238
        $this->assertEquals(5, $record->id);
2238
        $this->assertEquals(5, $record->id);
2239
    }
2239
    }
Línea 2240... Línea 2240...
2240
 
2240
 
2241
    public function test_insert_record() {
2241
    public function test_insert_record(): void {
2242
        // All the information in this test is fetched from DB by get_recordset() so we
2242
        // All the information in this test is fetched from DB by get_recordset() so we
Línea 2243... Línea 2243...
2243
        // have such method properly tested against nulls, empties and friends...
2243
        // have such method properly tested against nulls, empties and friends...
2244
 
2244
 
Línea 2518... Línea 2518...
2518
        } catch (\Exception $e) {
2518
        } catch (\Exception $e) {
2519
            $this->assertTrue($e instanceof dml_exception);
2519
            $this->assertTrue($e instanceof dml_exception);
2520
        }
2520
        }
2521
    }
2521
    }
Línea 2522... Línea 2522...
2522
 
2522
 
2523
    public function test_insert_records() {
2523
    public function test_insert_records(): void {
2524
        $DB = $this->tdb;
2524
        $DB = $this->tdb;
Línea 2525... Línea 2525...
2525
        $dbman = $DB->get_manager();
2525
        $dbman = $DB->get_manager();
2526
 
2526
 
Línea 2626... Línea 2626...
2626
        } catch (\moodle_exception $e) {
2626
        } catch (\moodle_exception $e) {
2627
            $this->assertInstanceOf('coding_exception', $e);
2627
            $this->assertInstanceOf('coding_exception', $e);
2628
        }
2628
        }
2629
    }
2629
    }
Línea 2630... Línea 2630...
2630
 
2630
 
2631
    public function test_insert_record_with_nullable_unique_index() {
2631
    public function test_insert_record_with_nullable_unique_index(): void {
2632
        $DB = $this->tdb;
2632
        $DB = $this->tdb;
Línea 2633... Línea 2633...
2633
        $dbman = $DB->get_manager();
2633
        $dbman = $DB->get_manager();
2634
 
2634
 
Línea 2688... Línea 2688...
2688
        $this->assertEquals(3, $DB->count_records($table->getName(), ['nullable1' => 1]));
2688
        $this->assertEquals(3, $DB->count_records($table->getName(), ['nullable1' => 1]));
2689
        $this->assertEquals(2, $DB->count_records($table->getName(), ['nullable1' => null]));
2689
        $this->assertEquals(2, $DB->count_records($table->getName(), ['nullable1' => null]));
Línea 2690... Línea 2690...
2690
 
2690
 
Línea 2691... Línea 2691...
2691
    }
2691
    }
2692
 
2692
 
2693
    public function test_import_record() {
2693
    public function test_import_record(): void {
Línea 2694... Línea 2694...
2694
        // All the information in this test is fetched from DB by get_recordset() so we
2694
        // All the information in this test is fetched from DB by get_recordset() so we
2695
        // have such method properly tested against nulls, empties and friends...
2695
        // have such method properly tested against nulls, empties and friends...
Línea 2854... Línea 2854...
2854
        $this->assertEquals($newclob, $record->onetext, 'Test "small" CLOB insert (full contents output disabled)');
2854
        $this->assertEquals($newclob, $record->onetext, 'Test "small" CLOB insert (full contents output disabled)');
2855
        $this->assertEquals($newblob, $record->onebinary, 'Test "small" BLOB insert (full contents output disabled)');
2855
        $this->assertEquals($newblob, $record->onebinary, 'Test "small" BLOB insert (full contents output disabled)');
2856
        $this->assertEquals(false, $rs->key()); // Ensure recordset key() method to be working ok after closing.
2856
        $this->assertEquals(false, $rs->key()); // Ensure recordset key() method to be working ok after closing.
2857
    }
2857
    }
Línea 2858... Línea 2858...
2858
 
2858
 
2859
    public function test_update_record_raw() {
2859
    public function test_update_record_raw(): void {
2860
        $DB = $this->tdb;
2860
        $DB = $this->tdb;
Línea 2861... Línea 2861...
2861
        $dbman = $DB->get_manager();
2861
        $dbman = $DB->get_manager();
2862
 
2862
 
Línea 2895... Línea 2895...
2895
        } catch (\moodle_exception $e) {
2895
        } catch (\moodle_exception $e) {
2896
            $this->assertInstanceOf('coding_exception', $e);
2896
            $this->assertInstanceOf('coding_exception', $e);
2897
        }
2897
        }
2898
    }
2898
    }
Línea 2899... Línea 2899...
2899
 
2899
 
Línea 2900... Línea 2900...
2900
    public function test_update_record() {
2900
    public function test_update_record(): void {
2901
 
2901
 
Línea 2902... Línea 2902...
2902
        // All the information in this test is fetched from DB by get_record() so we
2902
        // All the information in this test is fetched from DB by get_record() so we
Línea 3089... Línea 3089...
3089
        $this->assertEquals(1e-300, $DB->get_field($tablename, 'onetext', array('id' => $id)));
3089
        $this->assertEquals(1e-300, $DB->get_field($tablename, 'onetext', array('id' => $id)));
3090
        $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e300));
3090
        $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e300));
3091
        $this->assertEquals(1e300, $DB->get_field($tablename, 'onetext', array('id' => $id)));
3091
        $this->assertEquals(1e300, $DB->get_field($tablename, 'onetext', array('id' => $id)));
3092
    }
3092
    }
Línea 3093... Línea 3093...
3093
 
3093
 
3094
    public function test_set_field() {
3094
    public function test_set_field(): void {
3095
        $DB = $this->tdb;
3095
        $DB = $this->tdb;
Línea 3096... Línea 3096...
3096
        $dbman = $DB->get_manager();
3096
        $dbman = $DB->get_manager();
3097
 
3097
 
Línea 3189... Línea 3189...
3189
 
3189
 
3190
        // Note: All the nulls, booleans, empties, quoted and backslashes tests
3190
        // Note: All the nulls, booleans, empties, quoted and backslashes tests
3191
        // go to set_field_select() because set_field() is just one wrapper over it.
3191
        // go to set_field_select() because set_field() is just one wrapper over it.
Línea 3192... Línea 3192...
3192
    }
3192
    }
Línea 3193... Línea 3193...
3193
 
3193
 
3194
    public function test_set_field_select() {
3194
    public function test_set_field_select(): void {
Línea 3195... Línea 3195...
3195
 
3195
 
Línea 3335... Línea 3335...
3335
            $this->assertFalse(true, 'We have an unexpected exception.');
3335
            $this->assertFalse(true, 'We have an unexpected exception.');
3336
            throw $e;
3336
            throw $e;
3337
        }
3337
        }
3338
    }
3338
    }
Línea 3339... Línea 3339...
3339
 
3339
 
3340
    public function test_count_records() {
3340
    public function test_count_records(): void {
Línea 3341... Línea 3341...
3341
        $DB = $this->tdb;
3341
        $DB = $this->tdb;
Línea 3342... Línea 3342...
3342
 
3342
 
Línea 3371... Línea 3371...
3371
            $this->assertInstanceOf('dml_exception', $e);
3371
            $this->assertInstanceOf('dml_exception', $e);
3372
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
3372
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
3373
        }
3373
        }
3374
    }
3374
    }
Línea 3375... Línea 3375...
3375
 
3375
 
3376
    public function test_count_records_select() {
3376
    public function test_count_records_select(): void {
Línea 3377... Línea 3377...
3377
        $DB = $this->tdb;
3377
        $DB = $this->tdb;
Línea 3378... Línea 3378...
3378
 
3378
 
Línea 3393... Línea 3393...
3393
        $DB->insert_record($tablename, array('course' => 5));
3393
        $DB->insert_record($tablename, array('course' => 5));
Línea 3394... Línea 3394...
3394
 
3394
 
3395
        $this->assertSame(2, $DB->count_records_select($tablename, 'course > ?', array(3)));
3395
        $this->assertSame(2, $DB->count_records_select($tablename, 'course > ?', array(3)));
Línea 3396... Línea 3396...
3396
    }
3396
    }
3397
 
3397
 
3398
    public function test_count_records_sql() {
3398
    public function test_count_records_sql(): void {
Línea 3399... Línea 3399...
3399
        $DB = $this->tdb;
3399
        $DB = $this->tdb;
3400
        $dbman = $DB->get_manager();
3400
        $dbman = $DB->get_manager();
Línea 3430... Línea 3430...
3430
        } catch (\moodle_exception $e) {
3430
        } catch (\moodle_exception $e) {
3431
            $this->assertInstanceOf('coding_exception', $e);
3431
            $this->assertInstanceOf('coding_exception', $e);
3432
        }
3432
        }
3433
    }
3433
    }
Línea 3434... Línea 3434...
3434
 
3434
 
3435
    public function test_record_exists() {
3435
    public function test_record_exists(): void {
3436
        $DB = $this->tdb;
3436
        $DB = $this->tdb;
Línea 3437... Línea 3437...
3437
        $dbman = $DB->get_manager();
3437
        $dbman = $DB->get_manager();
3438
 
3438
 
Línea 3464... Línea 3464...
3464
            $this->assertInstanceOf('dml_exception', $e);
3464
            $this->assertInstanceOf('dml_exception', $e);
3465
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
3465
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
3466
        }
3466
        }
3467
    }
3467
    }
Línea 3468... Línea 3468...
3468
 
3468
 
3469
    public function test_record_exists_select() {
3469
    public function test_record_exists_select(): void {
3470
        $DB = $this->tdb;
3470
        $DB = $this->tdb;
Línea 3471... Línea 3471...
3471
        $dbman = $DB->get_manager();
3471
        $dbman = $DB->get_manager();
3472
 
3472
 
Línea 3484... Línea 3484...
3484
        $DB->insert_record($tablename, array('course' => 3));
3484
        $DB->insert_record($tablename, array('course' => 3));
Línea 3485... Línea 3485...
3485
 
3485
 
3486
        $this->assertTrue($DB->record_exists_select($tablename, "course = ?", array(3)));
3486
        $this->assertTrue($DB->record_exists_select($tablename, "course = ?", array(3)));
Línea 3487... Línea 3487...
3487
    }
3487
    }
3488
 
3488
 
3489
    public function test_record_exists_sql() {
3489
    public function test_record_exists_sql(): void {
Línea 3490... Línea 3490...
3490
        $DB = $this->tdb;
3490
        $DB = $this->tdb;
3491
        $dbman = $DB->get_manager();
3491
        $dbman = $DB->get_manager();
Línea 3504... Línea 3504...
3504
        $DB->insert_record($tablename, array('course' => 3));
3504
        $DB->insert_record($tablename, array('course' => 3));
Línea 3505... Línea 3505...
3505
 
3505
 
3506
        $this->assertTrue($DB->record_exists_sql("SELECT * FROM {{$tablename}} WHERE course = ?", array(3)));
3506
        $this->assertTrue($DB->record_exists_sql("SELECT * FROM {{$tablename}} WHERE course = ?", array(3)));
Línea 3507... Línea 3507...
3507
    }
3507
    }
3508
 
3508
 
3509
    public function test_recordset_locks_delete() {
3509
    public function test_recordset_locks_delete(): void {
Línea 3510... Línea 3510...
3510
        $DB = $this->tdb;
3510
        $DB = $this->tdb;
3511
        $dbman = $DB->get_manager();
3511
        $dbman = $DB->get_manager();
Línea 3536... Línea 3536...
3536
        $rs->close();
3536
        $rs->close();
Línea 3537... Línea 3537...
3537
 
3537
 
3538
        $this->assertEquals(4, $DB->count_records($tablename, array()));
3538
        $this->assertEquals(4, $DB->count_records($tablename, array()));
Línea 3539... Línea 3539...
3539
    }
3539
    }
3540
 
3540
 
3541
    public function test_recordset_locks_update() {
3541
    public function test_recordset_locks_update(): void {
Línea 3542... Línea 3542...
3542
        $DB = $this->tdb;
3542
        $DB = $this->tdb;
3543
        $dbman = $DB->get_manager();
3543
        $dbman = $DB->get_manager();
Línea 3568... Línea 3568...
3568
        $rs->close();
3568
        $rs->close();
Línea 3569... Línea 3569...
3569
 
3569
 
3570
        $this->assertEquals(2, $DB->count_records($tablename, array('course' => 10)));
3570
        $this->assertEquals(2, $DB->count_records($tablename, array('course' => 10)));
Línea 3571... Línea 3571...
3571
    }
3571
    }
3572
 
3572
 
3573
    public function test_delete_records() {
3573
    public function test_delete_records(): void {
Línea 3574... Línea 3574...
3574
        $DB = $this->tdb;
3574
        $DB = $this->tdb;
3575
        $dbman = $DB->get_manager();
3575
        $dbman = $DB->get_manager();
Línea 3628... Línea 3628...
3628
            $this->assertInstanceOf('dml_exception', $e);
3628
            $this->assertInstanceOf('dml_exception', $e);
3629
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
3629
            $this->assertSame('textconditionsnotallowed', $e->errorcode);
3630
        }
3630
        }
3631
    }
3631
    }
Línea 3632... Línea 3632...
3632
 
3632
 
3633
    public function test_delete_records_select() {
3633
    public function test_delete_records_select(): void {
3634
        $DB = $this->tdb;
3634
        $DB = $this->tdb;
Línea 3635... Línea 3635...
3635
        $dbman = $DB->get_manager();
3635
        $dbman = $DB->get_manager();
3636
 
3636
 
Línea 3648... Línea 3648...
3648
 
3648
 
3649
        $this->assertTrue($DB->delete_records_select($tablename, 'course = ?', array(2)));
3649
        $this->assertTrue($DB->delete_records_select($tablename, 'course = ?', array(2)));
3650
        $this->assertEquals(1, $DB->count_records($tablename));
3650
        $this->assertEquals(1, $DB->count_records($tablename));
Línea 3651... Línea 3651...
3651
    }
3651
    }
3652
 
3652
 
3653
    public function test_delete_records_subquery() {
3653
    public function test_delete_records_subquery(): void {
Línea 3654... Línea 3654...
3654
        $DB = $this->tdb;
3654
        $DB = $this->tdb;
3655
        $dbman = $DB->get_manager();
3655
        $dbman = $DB->get_manager();
Línea 3671... Línea 3671...
3671
        $DB->delete_records_subquery($tablename, 'id', 'frog',
3671
        $DB->delete_records_subquery($tablename, 'id', 'frog',
3672
                'SELECT id AS frog FROM {' . $tablename . '} WHERE course = ?', [2]);
3672
                'SELECT id AS frog FROM {' . $tablename . '} WHERE course = ?', [2]);
3673
        $this->assertEquals(1, $DB->count_records($tablename));
3673
        $this->assertEquals(1, $DB->count_records($tablename));
3674
    }
3674
    }
Línea 3675... Línea 3675...
3675
 
3675
 
3676
    public function test_delete_records_list() {
3676
    public function test_delete_records_list(): void {
3677
        $DB = $this->tdb;
3677
        $DB = $this->tdb;
Línea 3678... Línea 3678...
3678
        $dbman = $DB->get_manager();
3678
        $dbman = $DB->get_manager();
3679
 
3679
 
Línea 3694... Línea 3694...
3694
 
3694
 
3695
        $this->assertTrue($DB->delete_records_list($tablename, 'course', array())); // Must delete 0 rows without conditions. MDL-17645.
3695
        $this->assertTrue($DB->delete_records_list($tablename, 'course', array())); // Must delete 0 rows without conditions. MDL-17645.
3696
        $this->assertEquals(1, $DB->count_records($tablename));
3696
        $this->assertEquals(1, $DB->count_records($tablename));
Línea 3697... Línea 3697...
3697
    }
3697
    }
3698
 
3698
 
3699
    public function test_object_params() {
3699
    public function test_object_params(): void {
Línea 3700... Línea 3700...
3700
        $DB = $this->tdb;
3700
        $DB = $this->tdb;
3701
        $dbman = $DB->get_manager();
3701
        $dbman = $DB->get_manager();
Línea 3805... Línea 3805...
3805
        } catch (\moodle_exception $e) {
3805
        } catch (\moodle_exception $e) {
3806
            $this->assertInstanceOf('coding_exception', $e);
3806
            $this->assertInstanceOf('coding_exception', $e);
3807
        }
3807
        }
3808
    }
3808
    }
Línea 3809... Línea 3809...
3809
 
3809
 
3810
    public function test_sql_null_from_clause() {
3810
    public function test_sql_null_from_clause(): void {
3811
        $DB = $this->tdb;
3811
        $DB = $this->tdb;
3812
        $sql = "SELECT 1 AS id ".$DB->sql_null_from_clause();
3812
        $sql = "SELECT 1 AS id ".$DB->sql_null_from_clause();
3813
        $this->assertEquals(1, $DB->get_field_sql($sql));
3813
        $this->assertEquals(1, $DB->get_field_sql($sql));
Línea 3814... Línea 3814...
3814
    }
3814
    }
3815
 
3815
 
3816
    public function test_sql_bitand() {
3816
    public function test_sql_bitand(): void {
Línea 3817... Línea 3817...
3817
        $DB = $this->tdb;
3817
        $DB = $this->tdb;
3818
        $dbman = $DB->get_manager();
3818
        $dbman = $DB->get_manager();
Línea 3840... Línea 3840...
3840
        $result = $DB->get_records_sql($sql, array(10));
3840
        $result = $DB->get_records_sql($sql, array(10));
3841
        $this->assertCount(1, $result);
3841
        $this->assertCount(1, $result);
3842
        $this->assertEquals(2, reset($result)->res);
3842
        $this->assertEquals(2, reset($result)->res);
3843
    }
3843
    }
Línea 3844... Línea 3844...
3844
 
3844
 
3845
    public function test_sql_bitnot() {
3845
    public function test_sql_bitnot(): void {
Línea 3846... Línea 3846...
3846
        $DB = $this->tdb;
3846
        $DB = $this->tdb;
3847
 
3847
 
Línea 3848... Línea 3848...
3848
        $not = $DB->sql_bitnot(2);
3848
        $not = $DB->sql_bitnot(2);
3849
        $notlimited = $DB->sql_bitand($not, 7); // Might be positive or negative number which can not fit into PHP INT!
3849
        $notlimited = $DB->sql_bitand($not, 7); // Might be positive or negative number which can not fit into PHP INT!
3850
 
3850
 
Línea 3851... Línea 3851...
3851
        $sql = "SELECT $notlimited AS res ".$DB->sql_null_from_clause();
3851
        $sql = "SELECT $notlimited AS res ".$DB->sql_null_from_clause();
3852
        $this->assertEquals(5, $DB->get_field_sql($sql));
3852
        $this->assertEquals(5, $DB->get_field_sql($sql));
3853
    }
3853
    }
Línea 3854... Línea 3854...
3854
 
3854
 
3855
    public function test_sql_bitor() {
3855
    public function test_sql_bitor(): void {
Línea 3879... Línea 3879...
3879
        $result = $DB->get_records_sql($sql, array(10));
3879
        $result = $DB->get_records_sql($sql, array(10));
3880
        $this->assertCount(1, $result);
3880
        $this->assertCount(1, $result);
3881
        $this->assertEquals(11, reset($result)->res);
3881
        $this->assertEquals(11, reset($result)->res);
3882
    }
3882
    }
Línea 3883... Línea 3883...
3883
 
3883
 
3884
    public function test_sql_bitxor() {
3884
    public function test_sql_bitxor(): void {
3885
        $DB = $this->tdb;
3885
        $DB = $this->tdb;
Línea 3886... Línea 3886...
3886
        $dbman = $DB->get_manager();
3886
        $dbman = $DB->get_manager();
3887
 
3887
 
Línea 3908... Línea 3908...
3908
        $result = $DB->get_records_sql($sql, array(10));
3908
        $result = $DB->get_records_sql($sql, array(10));
3909
        $this->assertCount(1, $result);
3909
        $this->assertCount(1, $result);
3910
        $this->assertEquals(9, reset($result)->res);
3910
        $this->assertEquals(9, reset($result)->res);
3911
    }
3911
    }
Línea 3912... Línea 3912...
3912
 
3912
 
3913
    public function test_sql_modulo() {
3913
    public function test_sql_modulo(): void {
3914
        $DB = $this->tdb;
3914
        $DB = $this->tdb;
3915
        $sql = "SELECT ".$DB->sql_modulo(10, 7)." AS res ".$DB->sql_null_from_clause();
3915
        $sql = "SELECT ".$DB->sql_modulo(10, 7)." AS res ".$DB->sql_null_from_clause();
3916
        $this->assertEquals(3, $DB->get_field_sql($sql));
3916
        $this->assertEquals(3, $DB->get_field_sql($sql));
Línea 3917... Línea 3917...
3917
    }
3917
    }
3918
 
3918
 
3919
    public function test_sql_ceil() {
3919
    public function test_sql_ceil(): void {
3920
        $DB = $this->tdb;
3920
        $DB = $this->tdb;
3921
        $sql = "SELECT ".$DB->sql_ceil(665.666)." AS res ".$DB->sql_null_from_clause();
3921
        $sql = "SELECT ".$DB->sql_ceil(665.666)." AS res ".$DB->sql_null_from_clause();
Línea 3958... Línea 3958...
3958
 
3958
 
3959
        $fieldset = $DB->get_fieldset_sql($sql);
3959
        $fieldset = $DB->get_fieldset_sql($sql);
3960
        $this->assertEquals(['uno'], $fieldset);
3960
        $this->assertEquals(['uno'], $fieldset);
Línea 3961... Línea 3961...
3961
    }
3961
    }
3962
 
3962
 
3963
    public function test_cast_char2int() {
3963
    public function test_cast_char2int(): void {
Línea 3964... Línea 3964...
3964
        $DB = $this->tdb;
3964
        $DB = $this->tdb;
3965
        $dbman = $DB->get_manager();
3965
        $dbman = $DB->get_manager();
Línea 4011... Línea 4011...
4011
        $this->assertCount(2, $records);
4011
        $this->assertCount(2, $records);
4012
        $this->assertSame('20', reset($records)->nametext);
4012
        $this->assertSame('20', reset($records)->nametext);
4013
        $this->assertSame('0200', next($records)->nametext);
4013
        $this->assertSame('0200', next($records)->nametext);
4014
    }
4014
    }
Línea 4015... Línea 4015...
4015
 
4015
 
4016
    public function test_cast_char2real() {
4016
    public function test_cast_char2real(): void {
4017
        $DB = $this->tdb;
4017
        $DB = $this->tdb;
Línea 4018... Línea 4018...
4018
        $dbman = $DB->get_manager();
4018
        $dbman = $DB->get_manager();
4019
 
4019
 
Línea 4068... Línea 4068...
4068
        // And also, although not recommended, with directly passed values.
4068
        // And also, although not recommended, with directly passed values.
4069
        $sql = "SELECT name FROM {{$tablename}} WHERE FLOOR(res - " . $DB->sql_cast_char2real('10.09999') . ") = 0";
4069
        $sql = "SELECT name FROM {{$tablename}} WHERE FLOOR(res - " . $DB->sql_cast_char2real('10.09999') . ") = 0";
4070
        $this->assertEquals('011.13333333', $DB->get_field_sql($sql));
4070
        $this->assertEquals('011.13333333', $DB->get_field_sql($sql));
4071
    }
4071
    }
Línea 4072... Línea 4072...
4072
 
4072
 
4073
    public function test_sql_compare_text() {
4073
    public function test_sql_compare_text(): void {
4074
        $DB = $this->tdb;
4074
        $DB = $this->tdb;
Línea 4075... Línea 4075...
4075
        $dbman = $DB->get_manager();
4075
        $dbman = $DB->get_manager();
4076
 
4076
 
Línea 4131... Línea 4131...
4131
        $this->assertCount(1, $records);
4131
        $this->assertCount(1, $records);
4132
        $record = reset($records);
4132
        $record = reset($records);
4133
        $this->assertSame($clob, $record->description);
4133
        $this->assertSame($clob, $record->description);
4134
    }
4134
    }
Línea 4135... Línea 4135...
4135
 
4135
 
4136
    public function test_unique_index_collation_trouble() {
4136
    public function test_unique_index_collation_trouble(): void {
Línea 4137... Línea 4137...
4137
        // Note: this is a work in progress, we should probably move this to ddl test.
4137
        // Note: this is a work in progress, we should probably move this to ddl test.
4138
 
4138
 
Línea 4171... Línea 4171...
4171
            }
4171
            }
4172
            throw($e);
4172
            throw($e);
4173
        }
4173
        }
4174
    }
4174
    }
Línea 4175... Línea 4175...
4175
 
4175
 
4176
    public function test_sql_equal() {
4176
    public function test_sql_equal(): void {
4177
        $DB = $this->tdb;
4177
        $DB = $this->tdb;
Línea 4178... Línea 4178...
4178
        $dbman = $DB->get_manager();
4178
        $dbman = $DB->get_manager();
4179
 
4179
 
Línea 4227... Línea 4227...
4227
        $sql = "SELECT * FROM {{$tablename}} WHERE " . $DB->sql_equal('name', 'name2', false, false);
4227
        $sql = "SELECT * FROM {{$tablename}} WHERE " . $DB->sql_equal('name', 'name2', false, false);
4228
        $records = $DB->get_records_sql($sql);
4228
        $records = $DB->get_records_sql($sql);
4229
        $this->assertGreaterThanOrEqual(4, count($records)); // At very least, there are 4 records with CI/AI names matching.
4229
        $this->assertGreaterThanOrEqual(4, count($records)); // At very least, there are 4 records with CI/AI names matching.
4230
    }
4230
    }
Línea 4231... Línea 4231...
4231
 
4231
 
4232
    public function test_sql_like() {
4232
    public function test_sql_like(): void {
4233
        $DB = $this->tdb;
4233
        $DB = $this->tdb;
Línea 4234... Línea 4234...
4234
        $dbman = $DB->get_manager();
4234
        $dbman = $DB->get_manager();
4235
 
4235
 
Línea 4343... Línea 4343...
4343
            'lionel%_^-[0]',
4343
            'lionel%_^-[0]',
4344
            'rick%_^-[0]',
4344
            'rick%_^-[0]',
4345
        ], $DB->get_fieldset_select($tablename, 'name', $select, $params));
4345
        ], $DB->get_fieldset_select($tablename, 'name', $select, $params));
4346
    }
4346
    }
Línea 4347... Línea 4347...
4347
 
4347
 
4348
    public function test_coalesce() {
4348
    public function test_coalesce(): void {
Línea 4349... Línea 4349...
4349
        $DB = $this->tdb;
4349
        $DB = $this->tdb;
4350
 
4350
 
4351
        // Testing not-null occurrences, return 1st.
4351
        // Testing not-null occurrences, return 1st.
Línea 4383... Línea 4383...
4383
        // Check there are not problems with whitespace strings.
4383
        // Check there are not problems with whitespace strings.
4384
        $sql = "SELECT COALESCE(null, :paramvalue, null) AS test" . $DB->sql_null_from_clause();
4384
        $sql = "SELECT COALESCE(null, :paramvalue, null) AS test" . $DB->sql_null_from_clause();
4385
        $this->assertSame('', $DB->get_field_sql($sql, array('paramvalue' => '')));
4385
        $this->assertSame('', $DB->get_field_sql($sql, array('paramvalue' => '')));
4386
    }
4386
    }
Línea 4387... Línea 4387...
4387
 
4387
 
4388
    public function test_sql_concat() {
4388
    public function test_sql_concat(): void {
4389
        $DB = $this->tdb;
4389
        $DB = $this->tdb;
Línea 4390... Línea 4390...
4390
        $dbman = $DB->get_manager();
4390
        $dbman = $DB->get_manager();
4391
 
4391
 
Línea 4529... Línea 4529...
4529
     * @param string $concat The string to use when concatanating.
4529
     * @param string $concat The string to use when concatanating.
4530
     * @param array $fields The fields to concatanate
4530
     * @param array $fields The fields to concatanate
4531
     * @param array $params Any parameters to provide to the query
4531
     * @param array $params Any parameters to provide to the query
4532
     * @param @string $expected The expected result
4532
     * @param @string $expected The expected result
4533
     */
4533
     */
4534
    public function test_concat_join($concat, $fields, $params, $expected) {
4534
    public function test_concat_join($concat, $fields, $params, $expected): void {
4535
        $DB = $this->tdb;
4535
        $DB = $this->tdb;
4536
        $sql = "SELECT " . $DB->sql_concat_join($concat, $fields) . " AS result" . $DB->sql_null_from_clause();
4536
        $sql = "SELECT " . $DB->sql_concat_join($concat, $fields) . " AS result" . $DB->sql_null_from_clause();
4537
        $result = $DB->get_field_sql($sql, $params);
4537
        $result = $DB->get_field_sql($sql, $params);
4538
        $this->assertEquals($expected, $result);
4538
        $this->assertEquals($expected, $result);
4539
    }
4539
    }
Línea 4671... Línea 4671...
4671
                'falias' => 'Dan, Grace',
4671
                'falias' => 'Dan, Grace',
4672
            ],
4672
            ],
4673
        ], $DB->get_records_sql($sql));
4673
        ], $DB->get_records_sql($sql));
4674
    }
4674
    }
Línea 4675... Línea 4675...
4675
 
4675
 
4676
    public function test_sql_fullname() {
4676
    public function test_sql_fullname(): void {
4677
        $DB = $this->tdb;
4677
        $DB = $this->tdb;
4678
        $sql = "SELECT ".$DB->sql_fullname(':first', ':last')." AS fullname ".$DB->sql_null_from_clause();
4678
        $sql = "SELECT ".$DB->sql_fullname(':first', ':last')." AS fullname ".$DB->sql_null_from_clause();
4679
        $params = array('first'=>'Firstname', 'last'=>'Surname');
4679
        $params = array('first'=>'Firstname', 'last'=>'Surname');
4680
        $this->assertEquals("Firstname Surname", $DB->get_field_sql($sql, $params));
4680
        $this->assertEquals("Firstname Surname", $DB->get_field_sql($sql, $params));
Línea 4681... Línea 4681...
4681
    }
4681
    }
4682
 
4682
 
4683
    public function test_sql_order_by_text() {
4683
    public function test_sql_order_by_text(): void {
Línea 4684... Línea 4684...
4684
        $DB = $this->tdb;
4684
        $DB = $this->tdb;
4685
        $dbman = $DB->get_manager();
4685
        $dbman = $DB->get_manager();
Línea 4739... Línea 4739...
4739
        $this->assertEquals('aaaa', array_shift($records)->name);
4739
        $this->assertEquals('aaaa', array_shift($records)->name);
4740
        $this->assertEquals('', array_shift($records)->name);
4740
        $this->assertEquals('', array_shift($records)->name);
4741
        $this->assertEquals(null, array_shift($records)->name);
4741
        $this->assertEquals(null, array_shift($records)->name);
4742
    }
4742
    }
Línea 4743... Línea 4743...
4743
 
4743
 
4744
    public function test_sql_substring() {
4744
    public function test_sql_substring(): void {
4745
        $DB = $this->tdb;
4745
        $DB = $this->tdb;
Línea 4746... Línea 4746...
4746
        $dbman = $DB->get_manager();
4746
        $dbman = $DB->get_manager();
4747
 
4747
 
Línea 4800... Línea 4800...
4800
        $sql = "SELECT id, ".$DB->sql_substr("name", "(:param1 + 1) - 1")." AS name FROM {{$tablename}}";
4800
        $sql = "SELECT id, ".$DB->sql_substr("name", "(:param1 + 1) - 1")." AS name FROM {{$tablename}}";
4801
        $record = $DB->get_record_sql($sql, array('param1' => $start));
4801
        $record = $DB->get_record_sql($sql, array('param1' => $start));
4802
        $this->assertEquals(substr($string, $start - 1), $record->name); // PHP's substr is 0-based.
4802
        $this->assertEquals(substr($string, $start - 1), $record->name); // PHP's substr is 0-based.
4803
    }
4803
    }
Línea 4804... Línea 4804...
4804
 
4804
 
4805
    public function test_sql_length() {
4805
    public function test_sql_length(): void {
4806
        $DB = $this->tdb;
4806
        $DB = $this->tdb;
4807
        $this->assertEquals($DB->get_field_sql(
4807
        $this->assertEquals($DB->get_field_sql(
4808
            "SELECT ".$DB->sql_length("'aeiou'").$DB->sql_null_from_clause()), 5);
4808
            "SELECT ".$DB->sql_length("'aeiou'").$DB->sql_null_from_clause()), 5);
4809
        $this->assertEquals($DB->get_field_sql(
4809
        $this->assertEquals($DB->get_field_sql(
4810
            "SELECT ".$DB->sql_length("'áéíóú'").$DB->sql_null_from_clause()), 5);
4810
            "SELECT ".$DB->sql_length("'áéíóú'").$DB->sql_null_from_clause()), 5);
Línea 4811... Línea 4811...
4811
    }
4811
    }
4812
 
4812
 
4813
    public function test_sql_position() {
4813
    public function test_sql_position(): void {
4814
        $DB = $this->tdb;
4814
        $DB = $this->tdb;
4815
        $this->assertEquals($DB->get_field_sql(
4815
        $this->assertEquals($DB->get_field_sql(
4816
            "SELECT ".$DB->sql_position("'ood'", "'Moodle'").$DB->sql_null_from_clause()), 2);
4816
            "SELECT ".$DB->sql_position("'ood'", "'Moodle'").$DB->sql_null_from_clause()), 2);
4817
        $this->assertEquals($DB->get_field_sql(
4817
        $this->assertEquals($DB->get_field_sql(
Línea 4818... Línea 4818...
4818
            "SELECT ".$DB->sql_position("'Oracle'", "'Moodle'").$DB->sql_null_from_clause()), 0);
4818
            "SELECT ".$DB->sql_position("'Oracle'", "'Moodle'").$DB->sql_null_from_clause()), 0);
4819
    }
4819
    }
4820
 
4820
 
Línea 4821... Línea 4821...
4821
    public function test_sql_empty() {
4821
    public function test_sql_empty(): void {
4822
        $DB = $this->tdb;
4822
        $DB = $this->tdb;
Línea 4854... Línea 4854...
4854
        $this->assertCount(4, $records);
4854
        $this->assertCount(4, $records);
4855
        $record = reset($records);
4855
        $record = reset($records);
4856
        $this->assertSame('', $record->namenotnullnodeflt);
4856
        $this->assertSame('', $record->namenotnullnodeflt);
4857
    }
4857
    }
Línea 4858... Línea 4858...
4858
 
4858
 
4859
    public function test_sql_isempty() {
4859
    public function test_sql_isempty(): void {
4860
        $DB = $this->tdb;
4860
        $DB = $this->tdb;
Línea 4861... Línea 4861...
4861
        $dbman = $DB->get_manager();
4861
        $dbman = $DB->get_manager();
4862
 
4862
 
Línea 4895... Línea 4895...
4895
        $this->assertCount(1, $records);
4895
        $this->assertCount(1, $records);
4896
        $record = reset($records);
4896
        $record = reset($records);
4897
        $this->assertSame('', $record->descriptionnull);
4897
        $this->assertSame('', $record->descriptionnull);
4898
    }
4898
    }
Línea 4899... Línea 4899...
4899
 
4899
 
4900
    public function test_sql_isnotempty() {
4900
    public function test_sql_isnotempty(): void {
4901
        $DB = $this->tdb;
4901
        $DB = $this->tdb;
Línea 4902... Línea 4902...
4902
        $dbman = $DB->get_manager();
4902
        $dbman = $DB->get_manager();
4903
 
4903
 
Línea 4936... Línea 4936...
4936
        $this->assertCount(2, $records); // Nulls aren't comparable (so they aren't "not empty"). SQL expected behaviour.
4936
        $this->assertCount(2, $records); // Nulls aren't comparable (so they aren't "not empty"). SQL expected behaviour.
4937
        $record = reset($records);
4937
        $record = reset($records);
4938
        $this->assertSame('lalala', $record->descriptionnull); // So 'lalala' is the first non-empty 'descriptionnull' record.
4938
        $this->assertSame('lalala', $record->descriptionnull); // So 'lalala' is the first non-empty 'descriptionnull' record.
4939
    }
4939
    }
Línea 4940... Línea 4940...
4940
 
4940
 
4941
    public function test_sql_regex() {
4941
    public function test_sql_regex(): void {
4942
        $DB = $this->tdb;
4942
        $DB = $this->tdb;
4943
        $dbman = $DB->get_manager();
4943
        $dbman = $DB->get_manager();
4944
        if (!$DB->sql_regex_supported()) {
4944
        if (!$DB->sql_regex_supported()) {
4945
            $this->markTestSkipped($DB->get_name().' does not support regular expressions');
4945
            $this->markTestSkipped($DB->get_name().' does not support regular expressions');
Línea 4984... Línea 4984...
4984
    }
4984
    }
Línea 4985... Línea 4985...
4985
 
4985
 
4986
    /**
4986
    /**
4987
     * Test some complicated variations of set_field_select.
4987
     * Test some complicated variations of set_field_select.
4988
     */
4988
     */
4989
    public function test_set_field_select_complicated() {
4989
    public function test_set_field_select_complicated(): void {
4990
        $DB = $this->tdb;
4990
        $DB = $this->tdb;
Línea 4991... Línea 4991...
4991
        $dbman = $DB->get_manager();
4991
        $dbman = $DB->get_manager();
4992
 
4992
 
Línea 5014... Línea 5014...
5014
 
5014
 
5015
    /**
5015
    /**
5016
     * Test some more complex SQL syntax which moodle uses and depends on to work
5016
     * Test some more complex SQL syntax which moodle uses and depends on to work
5017
     * useful to determine if new database libraries can be supported.
5017
     * useful to determine if new database libraries can be supported.
5018
     */
5018
     */
5019
    public function test_get_records_sql_complicated() {
5019
    public function test_get_records_sql_complicated(): void {
5020
        $DB = $this->tdb;
5020
        $DB = $this->tdb;
Línea 5021... Línea 5021...
5021
        $dbman = $DB->get_manager();
5021
        $dbman = $DB->get_manager();
5022
 
5022
 
Línea 5160... Línea 5160...
5160
                 WHERE id $insql";
5160
                 WHERE id $insql";
5161
        $results = $DB->get_records_sql($sql, $inparams);
5161
        $results = $DB->get_records_sql($sql, $inparams);
5162
        $this->assertCount($currentcount, $results);
5162
        $this->assertCount($currentcount, $results);
5163
    }
5163
    }
Línea 5164... Línea 5164...
5164
 
5164
 
5165
    public function test_replace_all_text() {
5165
    public function test_replace_all_text(): void {
5166
        $DB = $this->tdb;
5166
        $DB = $this->tdb;
Línea 5167... Línea 5167...
5167
        $dbman = $DB->get_manager();
5167
        $dbman = $DB->get_manager();
5168
 
5168
 
Línea 5254... Línea 5254...
5254
        $result = $DB->get_records($tablename, array(), 'id ASC');
5254
        $result = $DB->get_records($tablename, array(), 'id ASC');
5255
        $expected[$id5]->intro = $long.'llll';
5255
        $expected[$id5]->intro = $long.'llll';
5256
        $this->assertEquals($expected, $result);
5256
        $this->assertEquals($expected, $result);
5257
    }
5257
    }
Línea 5258... Línea 5258...
5258
 
5258
 
5259
    public function test_onelevel_commit() {
5259
    public function test_onelevel_commit(): void {
5260
        $DB = $this->tdb;
5260
        $DB = $this->tdb;
Línea 5261... Línea 5261...
5261
        $dbman = $DB->get_manager();
5261
        $dbman = $DB->get_manager();
5262
 
5262
 
Línea 5275... Línea 5275...
5275
        $this->assertEquals(1, $DB->count_records($tablename));
5275
        $this->assertEquals(1, $DB->count_records($tablename));
5276
        $transaction->allow_commit();
5276
        $transaction->allow_commit();
5277
        $this->assertEquals(1, $DB->count_records($tablename));
5277
        $this->assertEquals(1, $DB->count_records($tablename));
5278
    }
5278
    }
Línea 5279... Línea 5279...
5279
 
5279
 
5280
    public function test_transaction_ignore_error_trouble() {
5280
    public function test_transaction_ignore_error_trouble(): void {
5281
        $DB = $this->tdb;
5281
        $DB = $this->tdb;
Línea 5282... Línea 5282...
5282
        $dbman = $DB->get_manager();
5282
        $dbman = $DB->get_manager();
5283
 
5283
 
Línea 5358... Línea 5358...
5358
        $this->assertFalse($DB->is_transaction_started());
5358
        $this->assertFalse($DB->is_transaction_started());
Línea 5359... Línea 5359...
5359
 
5359
 
5360
        // NOTE: SQL_QUERY_STRUCTURE is intentionally not tested here because it should never fail.
5360
        // NOTE: SQL_QUERY_STRUCTURE is intentionally not tested here because it should never fail.
Línea 5361... Línea 5361...
5361
    }
5361
    }
5362
 
5362
 
5363
    public function test_onelevel_rollback() {
5363
    public function test_onelevel_rollback(): void {
Línea 5364... Línea 5364...
5364
        $DB = $this->tdb;
5364
        $DB = $this->tdb;
5365
        $dbman = $DB->get_manager();
5365
        $dbman = $DB->get_manager();
Línea 5386... Línea 5386...
5386
            // Ignored.
5386
            // Ignored.
5387
        }
5387
        }
5388
        $this->assertEquals(0, $DB->count_records($tablename));
5388
        $this->assertEquals(0, $DB->count_records($tablename));
5389
    }
5389
    }
Línea 5390... Línea 5390...
5390
 
5390
 
5391
    public function test_nested_transactions() {
5391
    public function test_nested_transactions(): void {
5392
        $DB = $this->tdb;
5392
        $DB = $this->tdb;
Línea 5393... Línea 5393...
5393
        $dbman = $DB->get_manager();
5393
        $dbman = $DB->get_manager();
5394
 
5394
 
Línea 5529... Línea 5529...
5529
        }
5529
        }
5530
        $rs1->close();
5530
        $rs1->close();
5531
        $this->assertEquals(3, $i);
5531
        $this->assertEquals(3, $i);
5532
    }
5532
    }
Línea 5533... Línea 5533...
5533
 
5533
 
5534
    public function test_transactions_forbidden() {
5534
    public function test_transactions_forbidden(): void {
5535
        $DB = $this->tdb;
5535
        $DB = $this->tdb;
Línea 5536... Línea 5536...
5536
        $dbman = $DB->get_manager();
5536
        $dbman = $DB->get_manager();
5537
 
5537
 
Línea 5556... Línea 5556...
5556
        $transaction->allow_commit();
5556
        $transaction->allow_commit();
5557
        $this->assertFalse($DB->is_transaction_started());
5557
        $this->assertFalse($DB->is_transaction_started());
5558
        $this->assertEquals(1, $DB->count_records($tablename));
5558
        $this->assertEquals(1, $DB->count_records($tablename));
5559
    }
5559
    }
Línea 5560... Línea 5560...
5560
 
5560
 
5561
    public function test_wrong_transactions() {
5561
    public function test_wrong_transactions(): void {
5562
        $DB = $this->tdb;
5562
        $DB = $this->tdb;
Línea 5563... Línea 5563...
5563
        $dbman = $DB->get_manager();
5563
        $dbman = $DB->get_manager();
5564
 
5564
 
Línea 5643... Línea 5643...
5643
        }
5643
        }
5644
        $DB->force_transaction_rollback();
5644
        $DB->force_transaction_rollback();
5645
        $DB->delete_records($tablename);
5645
        $DB->delete_records($tablename);
5646
    }
5646
    }
Línea 5647... Línea 5647...
5647
 
5647
 
5648
    public function test_concurent_transactions() {
5648
    public function test_concurent_transactions(): void {
5649
        // Notes about this test:
5649
        // Notes about this test:
5650
        // 1- MySQL needs to use one engine with transactions support (InnoDB).
5650
        // 1- MySQL needs to use one engine with transactions support (InnoDB).
5651
        // 2- MSSQL needs to have enabled versioning for read committed
5651
        // 2- MSSQL needs to have enabled versioning for read committed
5652
        //    transactions (ALTER DATABASE xxx SET READ_COMMITTED_SNAPSHOT ON)
5652
        //    transactions (ALTER DATABASE xxx SET READ_COMMITTED_SNAPSHOT ON)
Línea 5718... Línea 5718...
5718
        $this->assertEquals(0, $DB2->count_records($tablename));
5718
        $this->assertEquals(0, $DB2->count_records($tablename));
Línea 5719... Línea 5719...
5719
 
5719
 
5720
        $DB2->dispose();
5720
        $DB2->dispose();
Línea 5721... Línea 5721...
5721
    }
5721
    }
5722
 
5722
 
5723
    public function test_session_locks() {
5723
    public function test_session_locks(): void {
Línea 5724... Línea 5724...
5724
        $DB = $this->tdb;
5724
        $DB = $this->tdb;
5725
        $dbman = $DB->get_manager();
5725
        $dbman = $DB->get_manager();
Línea 5762... Línea 5762...
5762
        $DB2->release_session_lock($rowid);
5762
        $DB2->release_session_lock($rowid);
Línea 5763... Línea 5763...
5763
 
5763
 
5764
        $DB2->dispose();
5764
        $DB2->dispose();
Línea 5765... Línea 5765...
5765
    }
5765
    }
5766
 
5766
 
5767
    public function test_bound_param_types() {
5767
    public function test_bound_param_types(): void {
Línea 5768... Línea 5768...
5768
        $DB = $this->tdb;
5768
        $DB = $this->tdb;
5769
        $dbman = $DB->get_manager();
5769
        $dbman = $DB->get_manager();
Línea 5824... Línea 5824...
5824
        $this->assertCount(1, $records);
5824
        $this->assertCount(1, $records);
5825
        $this->assertNotEmpty($records = $DB->get_records_sql($sqlnamed, array('content' => '2')));
5825
        $this->assertNotEmpty($records = $DB->get_records_sql($sqlnamed, array('content' => '2')));
5826
        $this->assertCount(1, $records);
5826
        $this->assertCount(1, $records);
5827
    }
5827
    }
Línea 5828... Línea 5828...
5828
 
5828
 
5829
    public function test_bound_param_reserved() {
5829
    public function test_bound_param_reserved(): void {
5830
        $DB = $this->tdb;
5830
        $DB = $this->tdb;
Línea 5831... Línea 5831...
5831
        $dbman = $DB->get_manager();
5831
        $dbman = $DB->get_manager();
5832
 
5832
 
Línea 5852... Línea 5852...
5852
 
5852
 
5853
        // If we get here test passed ok.
5853
        // If we get here test passed ok.
5854
        $this->assertTrue(true);
5854
        $this->assertTrue(true);
Línea 5855... Línea 5855...
5855
    }
5855
    }
5856
 
5856
 
5857
    public function test_limits_and_offsets() {
5857
    public function test_limits_and_offsets(): void {
Línea 5858... Línea 5858...
5858
        $DB = $this->tdb;
5858
        $DB = $this->tdb;
5859
        $dbman = $DB->get_manager();
5859
        $dbman = $DB->get_manager();
Línea 5965... Línea 5965...
5965
    }
5965
    }
Línea 5966... Línea 5966...
5966
 
5966
 
5967
    /**
5967
    /**
5968
     * Test debugging messages about invalid limit number values.
5968
     * Test debugging messages about invalid limit number values.
5969
     */
5969
     */
5970
    public function test_invalid_limits_debugging() {
5970
    public function test_invalid_limits_debugging(): void {
5971
        $DB = $this->tdb;
5971
        $DB = $this->tdb;
Línea 5972... Línea 5972...
5972
        $dbman = $DB->get_manager();
5972
        $dbman = $DB->get_manager();
5973
 
5973
 
Línea 6030... Línea 6030...
6030
        $this->assertDebuggingCalled("Negative limitfrom parameter detected: -2, did you pass the correct arguments?");
6030
        $this->assertDebuggingCalled("Negative limitfrom parameter detected: -2, did you pass the correct arguments?");
6031
        $DB->get_records_sql("SELECT * FROM {{$tablename}}", null, 1, -2);
6031
        $DB->get_records_sql("SELECT * FROM {{$tablename}}", null, 1, -2);
6032
        $this->assertDebuggingCalled("Negative limitnum parameter detected: -2, did you pass the correct arguments?");
6032
        $this->assertDebuggingCalled("Negative limitnum parameter detected: -2, did you pass the correct arguments?");
6033
    }
6033
    }
Línea 6034... Línea 6034...
6034
 
6034
 
Línea 6035... Línea 6035...
6035
    public function test_queries_counter() {
6035
    public function test_queries_counter(): void {
6036
 
6036
 
Línea 6037... Línea 6037...
6037
        $DB = $this->tdb;
6037
        $DB = $this->tdb;
Línea 6109... Línea 6109...
6109
        // Sum of them.
6109
        // Sum of them.
6110
        $totaldbqueries = $DB->perf_get_reads() + $DB->perf_get_writes();
6110
        $totaldbqueries = $DB->perf_get_reads() + $DB->perf_get_writes();
6111
        $this->assertEquals($totaldbqueries, $DB->perf_get_queries());
6111
        $this->assertEquals($totaldbqueries, $DB->perf_get_queries());
6112
    }
6112
    }
Línea 6113... Línea 6113...
6113
 
6113
 
6114
    public function test_sql_intersect() {
6114
    public function test_sql_intersect(): void {
6115
        $DB = $this->tdb;
6115
        $DB = $this->tdb;
Línea 6116... Línea 6116...
6116
        $dbman = $this->tdb->get_manager();
6116
        $dbman = $this->tdb->get_manager();
6117
 
6117
 
Línea 6194... Línea 6194...
6194
    }
6194
    }
Línea 6195... Línea 6195...
6195
 
6195
 
6196
    /**
6196
    /**
6197
     * Test that the database has full utf8 support (4 bytes).
6197
     * Test that the database has full utf8 support (4 bytes).
6198
     */
6198
     */
6199
    public function test_four_byte_character_insertion() {
6199
    public function test_four_byte_character_insertion(): void {
Línea 6200... Línea 6200...
6200
        $DB = $this->tdb;
6200
        $DB = $this->tdb;
6201
 
6201
 
6202
        if ($DB->get_dbfamily() === 'mysql' && strpos($DB->get_dbcollation(), 'utf8_') === 0) {
6202
        if ($DB->get_dbfamily() === 'mysql' && strpos($DB->get_dbcollation(), 'utf8_') === 0) {
Línea 6241... Línea 6241...
6241
     * @see \mysqli_native_moodle_database::get_server_info()
6241
     * @see \mysqli_native_moodle_database::get_server_info()
6242
     * @covers \mysqli_native_moodle_database::get_server_info
6242
     * @covers \mysqli_native_moodle_database::get_server_info
6243
     * @dataProvider get_server_info_mysql_provider
6243
     * @dataProvider get_server_info_mysql_provider
6244
     */
6244
     */
6245
    public function test_get_server_info_mysql(
6245
    public function test_get_server_info_mysql(
6246
        string $mysqliserverinfo, string $versionfromdb, bool $cfgversionfromdb, string $expecteddbversion) {
6246
        string $mysqliserverinfo, string $versionfromdb, bool $cfgversionfromdb, string $expecteddbversion): void {
6247
        // Avoid to run MySQL-ish related tests when running tests on other DB families.
6247
        // Avoid to run MySQL-ish related tests when running tests on other DB families.
6248
        $DB = $this->tdb;
6248
        $DB = $this->tdb;
6249
        if ($DB->get_dbfamily() != 'mysql') {
6249
        if ($DB->get_dbfamily() != 'mysql') {
6250
            $this->markTestSkipped("Not MySQL family");
6250
            $this->markTestSkipped("Not MySQL family");
6251
        }
6251
        }
Línea 6355... Línea 6355...
6355
    /**
6355
    /**
6356
     * Test {@see \mysqli_native_moodle_database::get_server_info()} with the actual DB Server.
6356
     * Test {@see \mysqli_native_moodle_database::get_server_info()} with the actual DB Server.
6357
     * @see \mysqli_native_moodle_database::get_server_info
6357
     * @see \mysqli_native_moodle_database::get_server_info
6358
     * @covers \mysqli_native_moodle_database::get_server_info
6358
     * @covers \mysqli_native_moodle_database::get_server_info
6359
     */
6359
     */
6360
    public function test_get_server_info_dbfamily_mysql() {
6360
    public function test_get_server_info_dbfamily_mysql(): void {
6361
        $DB = $this->tdb;
6361
        $DB = $this->tdb;
6362
        if ($DB->get_dbfamily() != 'mysql') {
6362
        if ($DB->get_dbfamily() != 'mysql') {
6363
            $this->markTestSkipped("Not MySQL family");
6363
            $this->markTestSkipped("Not MySQL family");
6364
        }
6364
        }