Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 41... Línea 41...
41
 * @package     core_reportbuilder
41
 * @package     core_reportbuilder
42
 * @covers      \core_reportbuilder\local\entities\base
42
 * @covers      \core_reportbuilder\local\entities\base
43
 * @copyright   2021 David Matamoros <davidmc@moodle.com>
43
 * @copyright   2021 David Matamoros <davidmc@moodle.com>
44
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
44
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
45
 */
45
 */
46
class base_test extends advanced_testcase {
46
final class base_test extends advanced_testcase {
Línea 47... Línea 47...
47
 
47
 
48
    /**
48
    /**
49
     * Test entity table alias
49
     * Test entity table alias
50
     */
50
     */
Línea 64... Línea 64...
64
        $this->assertEquals($mytablealias, $entity->get_table_alias('mytable'));
64
        $this->assertEquals($mytablealias, $entity->get_table_alias('mytable'));
65
        $this->assertEquals($myothertablealias, $entity->get_table_alias('myothertable'));
65
        $this->assertEquals($myothertablealias, $entity->get_table_alias('myothertable'));
66
    }
66
    }
Línea 67... Línea 67...
67
 
67
 
-
 
68
    /**
-
 
69
     * Test for deprecated get table alias
-
 
70
     */
-
 
71
    public function test_get_table_alias_deprecated(): void {
-
 
72
        $entity = new base_test_entity();
-
 
73
 
-
 
74
        $entity->get_table_alias('mydeprecatedtable');
-
 
75
 
-
 
76
        // Debugging called twice, as get_table_alias internally calls set_table_alias for undefined alias.
-
 
77
        $this->assertDebuggingCalledCount(2, [
-
 
78
            'The table \'mydeprecatedtable\' is deprecated, please do not use it any more.',
-
 
79
            'The table \'mydeprecatedtable\' is deprecated, please do not use it any more.',
-
 
80
        ]);
-
 
81
    }
-
 
82
 
-
 
83
    /**
-
 
84
     * Test for deprecated get table alias replacement
-
 
85
     */
-
 
86
    public function test_get_table_alias_deprecated_replacement(): void {
-
 
87
        $entity = new base_test_entity_second();
-
 
88
 
-
 
89
        $mydeprecatedtable = $entity->get_table_alias('mydeprecatedtable');
-
 
90
        $this->assertDebuggingCalled();
-
 
91
 
-
 
92
        // We should get back the same alias for the replacement table.
-
 
93
        $this->assertEquals($mydeprecatedtable, $entity->get_table_alias('mytable'));
-
 
94
    }
-
 
95
 
68
    /**
96
    /**
69
     * Test for invalid get table alias
97
     * Test for invalid get table alias
70
     */
98
     */
71
    public function test_get_table_alias_invalid(): void {
99
    public function test_get_table_alias_invalid(): void {
Línea 104... Línea 132...
104
        $entity->set_table_alias('mytable', 'newalias');
132
        $entity->set_table_alias('mytable', 'newalias');
105
        $this->assertEquals('newalias', $entity->get_table_alias('mytable'));
133
        $this->assertEquals('newalias', $entity->get_table_alias('mytable'));
106
    }
134
    }
Línea 107... Línea 135...
107
 
135
 
-
 
136
    /**
-
 
137
     * Test for deprecated set table alias
-
 
138
     */
-
 
139
    public function test_set_table_alias_deprecated(): void {
-
 
140
        $entity = new base_test_entity();
-
 
141
 
-
 
142
        $entity->set_table_alias('mydeprecatedtable', 'newalias');
-
 
143
        $this->assertEquals('newalias', $entity->get_table_alias('mydeprecatedtable'));
-
 
144
 
-
 
145
        // Debugging called twice, once for set_table_alias and once for subsequent get_table_alias.
-
 
146
        $this->assertDebuggingCalledCount(2, [
-
 
147
            'The table \'mydeprecatedtable\' is deprecated, please do not use it any more.',
-
 
148
            'The table \'mydeprecatedtable\' is deprecated, please do not use it any more.',
-
 
149
        ]);
-
 
150
    }
-
 
151
 
-
 
152
    /**
-
 
153
     * Test for deprecated get table alias replacement
-
 
154
     */
-
 
155
    public function test_set_table_alias_deprecated_replacement(): void {
-
 
156
        $entity = new base_test_entity_second();
-
 
157
 
-
 
158
        $entity->set_table_alias('mydeprecatedtable', 'newalias');
-
 
159
        $this->assertDebuggingCalled();
-
 
160
 
-
 
161
        // We should get back the same alias for the replacement table.
-
 
162
        $this->assertEquals('newalias', $entity->get_table_alias('mytable'));
-
 
163
    }
-
 
164
 
108
    /**
165
    /**
109
     * Test invalid entity set table alias
166
     * Test invalid entity set table alias
110
     */
167
     */
111
    public function test_set_table_alias_invalid(): void {
168
    public function test_set_table_alias_invalid(): void {
Línea 191... Línea 248...
191
        $entity->set_entity_title($newtitle);
248
        $entity->set_entity_title($newtitle);
192
        $this->assertEquals($newtitle, $entity->get_entity_title());
249
        $this->assertEquals($newtitle, $entity->get_entity_title());
193
    }
250
    }
Línea 194... Línea 251...
194
 
251
 
195
    /**
-
 
196
     * Test adding single join
-
 
197
     */
-
 
198
    public function test_add_join(): void {
-
 
199
        $entity = new base_test_entity();
-
 
200
 
-
 
201
        $tablejoin = "JOIN {course} c2 ON c2.id = c1.id";
-
 
202
        $entity->add_join($tablejoin);
-
 
203
 
-
 
204
        $this->assertEquals([$tablejoin], $entity->get_joins());
-
 
205
    }
-
 
206
 
-
 
207
    /**
-
 
208
     * Test adding multiple joins
-
 
209
     */
-
 
210
    public function test_add_joins(): void {
-
 
211
        $entity = new base_test_entity();
-
 
212
 
-
 
213
        $tablejoins = [
-
 
214
            "JOIN {course} c2 ON c2.id = c1.id",
-
 
215
            "JOIN {course} c3 ON c3.id = c1.id",
-
 
216
        ];
-
 
217
        $entity->add_joins($tablejoins);
-
 
218
 
-
 
219
        $this->assertEquals($tablejoins, $entity->get_joins());
-
 
220
    }
-
 
221
 
-
 
222
    /**
-
 
223
     * Test adding duplicate joins
-
 
224
     */
-
 
225
    public function test_add_duplicate_joins(): void {
-
 
226
        $entity = new base_test_entity();
-
 
227
 
-
 
228
        $tablejoins = [
-
 
229
            "JOIN {course} c2 ON c2.id = c1.id",
-
 
230
            "JOIN {course} c3 ON c3.id = c1.id",
-
 
231
        ];
-
 
232
        $entity
-
 
233
            ->add_joins($tablejoins)
-
 
234
            ->add_joins($tablejoins);
-
 
235
 
-
 
236
        $this->assertEquals($tablejoins, $entity->get_joins());
-
 
237
    }
-
 
238
 
-
 
239
    /**
252
    /**
240
     * Test getting column
253
     * Test getting column
241
     */
254
     */
242
    public function test_get_column(): void {
255
    public function test_get_column(): void {
Línea 340... Línea 353...
340
 * Simple implementation of the base entity
353
 * Simple implementation of the base entity
341
 */
354
 */
342
class base_test_entity extends base {
355
class base_test_entity extends base {
Línea 343... Línea 356...
343
 
356
 
344
    /**
357
    /**
345
     * Table aliases
358
     * Database tables that this entity uses
346
     *
359
     *
347
     * @return array
360
     * @return string[]
348
     */
361
     */
349
    protected function get_default_tables(): array {
362
    protected function get_default_tables(): array {
350
        return [
363
        return [
351
            'mytable',
364
            'mytable',
352
            'myothertable',
365
            'myothertable',
353
        ];
366
        ];
Línea 354... Línea 367...
354
    }
367
    }
-
 
368
 
-
 
369
    /**
-
 
370
     * Database tables that this entity no longer uses
-
 
371
     *
-
 
372
     * @return string[]
-
 
373
     */
-
 
374
    protected function get_deprecated_tables(): array {
-
 
375
        return [
-
 
376
            'mydeprecatedtable',
-
 
377
        ];
-
 
378
    }
355
 
379
 
356
    /**
380
    /**
357
     * Entity title
381
     * Entity title
358
     *
382
     *
359
     * @return lang_string
383
     * @return lang_string
Línea 387... Línea 411...
387
            ->add_column($column)
411
            ->add_column($column)
388
            ->add_filter($filter)
412
            ->add_filter($filter)
389
            ->add_condition($filter);
413
            ->add_condition($filter);
390
    }
414
    }
391
}
415
}
-
 
416
 
-
 
417
/**
-
 
418
 * Another simple implementation of the base entity
-
 
419
 */
-
 
420
class base_test_entity_second extends base_test_entity {
-
 
421
 
-
 
422
    /**
-
 
423
     * Database tables that this entity no longer uses
-
 
424
     *
-
 
425
     * @return string[]
-
 
426
     */
-
 
427
    protected function get_deprecated_tables(): array {
-
 
428
        return [
-
 
429
            'mytable' => 'mydeprecatedtable',
-
 
430
        ];
-
 
431
    }
-
 
432
}