Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 26... Línea 26...
26
 * @category   test
26
 * @category   test
27
 * @copyright  2019 Andrew Nicols <andrew@nicols.co.uk>
27
 * @copyright  2019 Andrew Nicols <andrew@nicols.co.uk>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @coversDefaultClass \core\dml\table
29
 * @coversDefaultClass \core\dml\table
30
 */
30
 */
31
class dml_table_test extends \database_driver_testcase {
31
final class dml_table_test extends \database_driver_testcase {
Línea 32... Línea 32...
32
 
32
 
33
    /**
33
    /**
34
     * Data provider for various \core\dml\table method tests.
34
     * Data provider for various \core\dml\table method tests.
35
     *
35
     *
36
     * @return  array
36
     * @return  array
37
     */
37
     */
38
    public function get_field_select_provider(): array {
38
    public static function get_field_select_provider(): array {
39
        return [
39
        return [
40
            'single field' => [
40
            'single field' => [
41
                'tablename' => 'test_table_single',
41
                'tablename' => 'test_table_single',
42
                'fieldlist' => [
42
                'fieldlist' => [
43
                    'id' => ['id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null],
43
                    'id' => ['id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null],
44
                ],
44
                ],
45
                'primarykey' => 'id',
45
                'primarykey' => 'id',
46
                'fieldprefix' => 'ban',
46
                'fieldprefix' => 'ban',
47
                'tablealias' => 'banana',
47
                'tablealias' => 'banana',
48
                'banana.id AS banid',
48
                'expected' => 'banana.id AS banid',
49
            ],
49
            ],
50
            'multiple fields' => [
50
            'multiple fields' => [
51
                'tablename' => 'test_table_multiple',
51
                'tablename' => 'test_table_multiple',
52
                'fieldlist' => [
52
                'fieldlist' => [
Línea 55... Línea 55...
55
                    'name' => ['name', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala'],
55
                    'name' => ['name', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala'],
56
                ],
56
                ],
57
                'primarykey' => 'id',
57
                'primarykey' => 'id',
58
                'fieldprefix' => 'ban',
58
                'fieldprefix' => 'ban',
59
                'tablealias' => 'banana',
59
                'tablealias' => 'banana',
60
                'banana.id AS banid, banana.course AS bancourse, banana.name AS banname',
60
                'expected' => 'banana.id AS banid, banana.course AS bancourse, banana.name AS banname',
61
            ],
61
            ],
62
        ];
62
        ];
63
    }
63
    }
Línea 64... Línea 64...
64
 
64
 
Línea 100... Línea 100...
100
    /**
100
    /**
101
     * Data provider for \core\dml\table::extract_from_result() tests.
101
     * Data provider for \core\dml\table::extract_from_result() tests.
102
     *
102
     *
103
     * @return  array
103
     * @return  array
104
     */
104
     */
105
    public function extract_from_result_provider(): array {
105
    public static function extract_from_result_provider(): array {
106
        return [
106
        return [
107
            'single table' => [
107
            'single table' => [
108
                'fieldlist' => [
108
                'fieldlist' => [
109
                    'id' => ['id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null],
109
                    'id' => ['id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null],
110
                    'course' => ['course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'],
110
                    'course' => ['course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'],
111
                    'flag' => ['flag', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala'],
111
                    'flag' => ['flag', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala'],
112
                ],
112
                ],
113
                'primarykey' => 'id',
113
                'primarykey' => 'id',
114
                'prefix' => 's',
114
                'fieldprefix' => 's',
115
                'result' => (object) [
115
                'result' => (object) [
116
                    'sid' => 1,
116
                    'sid' => 1,
117
                    'scourse' => 42,
117
                    'scourse' => 42,
118
                    'sflag' => 'foo',
118
                    'sflag' => 'foo',
119
                ],
119
                ],
120
                'expectedrecord' => (object) [
120
                'expected' => (object) [
121
                    'id' => 1,
121
                    'id' => 1,
122
                    'course' => 42,
122
                    'course' => 42,
123
                    'flag' => 'foo',
123
                    'flag' => 'foo',
124
                ],
124
                ],
125
            ],
125
            ],
Línea 128... Línea 128...
128
                    'id' => ['id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null],
128
                    'id' => ['id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null],
129
                    'course' => ['course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'],
129
                    'course' => ['course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'],
130
                    'flag' => ['flag', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala'],
130
                    'flag' => ['flag', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala'],
131
                ],
131
                ],
132
                'primarykey' => 'id',
132
                'primarykey' => 'id',
133
                'prefix' => 's',
133
                'fieldprefix' => 's',
134
                'result' => (object) [
134
                'result' => (object) [
135
                    'sid' => 1,
135
                    'sid' => 1,
136
                    'scourse' => 42,
136
                    'scourse' => 42,
137
                    'sflag' => 'foo',
137
                    'sflag' => 'foo',
138
                    'oid' => 'id',
138
                    'oid' => 'id',
139
                    'ocourse' => 'course',
139
                    'ocourse' => 'course',
140
                    'oflag' => 'flag',
140
                    'oflag' => 'flag',
141
                ],
141
                ],
142
                'expectedrecord' => (object) [
142
                'expected' => (object) [
143
                    'id' => 1,
143
                    'id' => 1,
144
                    'course' => 42,
144
                    'course' => 42,
145
                    'flag' => 'foo',
145
                    'flag' => 'foo',
146
                ],
146
                ],
147
            ],
147
            ],