Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 30... Línea 30...
30
 * @package     core_reportbuilder
30
 * @package     core_reportbuilder
31
 * @covers      \core_reportbuilder\local\report\column
31
 * @covers      \core_reportbuilder\local\report\column
32
 * @copyright   2020 Paul Holden <paulh@moodle.com>
32
 * @copyright   2020 Paul Holden <paulh@moodle.com>
33
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
34
 */
35
class column_test extends advanced_testcase {
35
final class column_test extends advanced_testcase {
Línea 36... Línea 36...
36
 
36
 
37
    /**
37
    /**
38
     * Test column name getter/setter
38
     * Test column name getter/setter
39
     */
39
     */
Línea 111... Línea 111...
111
        $this->expectExceptionMessage('Invalid column type');
111
        $this->expectExceptionMessage('Invalid column type');
112
        $column->set_type(-1);
112
        $column->set_type(-1);
113
    }
113
    }
Línea 114... Línea 114...
114
 
114
 
115
    /**
-
 
116
     * Test adding single join
-
 
117
     */
-
 
118
    public function test_add_join(): void {
-
 
119
        $column = $this->create_column('test');
-
 
120
        $this->assertEquals([], $column->get_joins());
-
 
121
 
-
 
122
        $column->add_join('JOIN {user} u ON u.id = table.userid');
-
 
123
        $this->assertEquals(['JOIN {user} u ON u.id = table.userid'], $column->get_joins());
-
 
124
    }
-
 
125
 
-
 
126
    /**
-
 
127
     * Test adding multiple joins
-
 
128
     */
-
 
129
    public function test_add_joins(): void {
-
 
130
        $tablejoins = [
-
 
131
            "JOIN {course} c2 ON c2.id = c1.id",
-
 
132
            "JOIN {course} c3 ON c3.id = c1.id",
-
 
133
        ];
-
 
134
 
-
 
135
        $column = $this->create_column('test')
-
 
136
            ->add_joins($tablejoins);
-
 
137
 
-
 
138
        $this->assertEquals($tablejoins, $column->get_joins());
-
 
139
    }
-
 
140
 
-
 
141
    /**
115
    /**
142
     * Data provider for {@see test_add_field}
116
     * Data provider for {@see test_add_field}
143
     *
117
     *
144
     * @return array
118
     * @return array
145
     */
119
     */
146
    public function add_field_provider(): array {
120
    public static function add_field_provider(): array {
147
        return [
121
        return [
148
            ['foo', '', ['foo AS c1_foo']],
122
            ['foo', '', ['foo AS c1_foo']],
149
            ['foo', 'bar', ['foo AS c1_bar']],
123
            ['foo', 'bar', ['foo AS c1_bar']],
150
            ['t.foo', '', ['t.foo AS c1_foo']],
124
            ['t.foo', '', ['t.foo AS c1_foo']],
Línea 229... Línea 203...
229
    /**
203
    /**
230
     * Data provider for {@see test_add_fields}
204
     * Data provider for {@see test_add_fields}
231
     *
205
     *
232
     * @return array
206
     * @return array
233
     */
207
     */
234
    public function add_fields_provider(): array {
208
    public static function add_fields_provider(): array {
235
        return [
209
        return [
236
            ['t.foo', ['t.foo AS c1_foo']],
210
            ['t.foo', ['t.foo AS c1_foo']],
237
            ['t.foo bar', ['t.foo AS c1_bar']],
211
            ['t.foo bar', ['t.foo AS c1_bar']],
238
            ['t.foo AS bar', ['t.foo AS c1_bar']],
212
            ['t.foo AS bar', ['t.foo AS c1_bar']],
239
            ['t.foo1, t.foo2 bar, t.foo3 AS baz', ['t.foo1 AS c1_foo1', 't.foo2 AS c1_bar', 't.foo3 AS c1_baz']],
213
            ['t.foo1, t.foo2 bar, t.foo3 AS baz', ['t.foo1 AS c1_foo1', 't.foo2 AS c1_bar', 't.foo3 AS c1_baz']],
Línea 325... Línea 299...
325
    /**
299
    /**
326
     * Data provider for {@see test_get_default_value} and {@see test_format_value}
300
     * Data provider for {@see test_get_default_value} and {@see test_format_value}
327
     *
301
     *
328
     * @return array[]
302
     * @return array[]
329
     */
303
     */
330
    public function column_type_provider(): array {
304
    public static function column_type_provider(): array {
331
        return [
305
        return [
332
            [column::TYPE_INTEGER, 42],
306
            [column::TYPE_INTEGER, 42],
333
            [column::TYPE_TEXT, 'Hello'],
307
            [column::TYPE_TEXT, 'Hello'],
334
            [column::TYPE_TIMESTAMP, HOURSECS],
308
            [column::TYPE_TIMESTAMP, HOURSECS],
335
            [column::TYPE_BOOLEAN, 1, true],
309
            [column::TYPE_BOOLEAN, 1, true],
Línea 499... Línea 473...
499
    }
473
    }
Línea 500... Línea 474...
500
 
474
 
501
    /**
475
    /**
502
     * Test retrieving sort fields
476
     * Test retrieving sort fields
503
     */
477
     */
504
    public function test_get_sortfields(): void {
478
    public function test_get_sort_fields(): void {
505
        $column = $this->create_column('test')
479
        $column = $this->create_column('test')
506
            ->set_index(1)
480
            ->set_index(1)
507
            ->add_fields('t.foo, t.bar, t.baz')
481
            ->add_fields('t.foo, t.bar, t.baz')
Línea 511... Línea 485...
511
    }
485
    }
Línea 512... Línea 486...
512
 
486
 
513
    /**
487
    /**
514
     * Test retrieving sort fields when an aliased field is set as sortable
488
     * Test retrieving sort fields when an aliased field is set as sortable
515
     */
489
     */
516
    public function test_get_sortfields_with_field_alias(): void {
490
    public function test_get_sort_fields_with_field_alias(): void {
517
        $column = $this->create_column('test')
491
        $column = $this->create_column('test')
518
            ->set_index(1)
492
            ->set_index(1)
519
            ->add_field('t.foo')
493
            ->add_field('t.foo')
520
            ->add_field('COALESCE(t.foo, t.bar)', 'lionel')
494
            ->add_field('COALESCE(t.foo, t.bar)', 'lionel')
Línea 521... Línea 495...
521
            ->set_is_sortable(true, ['lionel']);
495
            ->set_is_sortable(true, ['lionel']);
522
 
496
 
Línea 523... Línea 497...
523
        $this->assertEquals(['c1_lionel'], $column->get_sort_fields());
497
        $this->assertEquals(['c1_lionel'], $column->get_sort_fields());
-
 
498
    }
-
 
499
 
-
 
500
    /**
-
 
501
     * Test retrieving sort fields that contain references to fields within complex snippet
-
 
502
     */
-
 
503
    public function test_get_sort_fields_complex(): void {
-
 
504
        $column = $this->create_column('test')
-
 
505
            ->set_index(1)
-
 
506
            ->add_fields('t.foo, t.bar')
-
 
507
            ->set_is_sortable(true, ['CASE WHEN 1=1 THEN t.foo ELSE t.bar END']);
-
 
508
 
-
 
509
        $this->assertEquals(['CASE WHEN 1=1 THEN c1_foo ELSE c1_bar END'], $column->get_sort_fields());
524
    }
510
    }
525
 
511
 
526
    /**
512
    /**
527
     * Test retrieving sort fields when an unknown field is set as sortable
513
     * Test retrieving sort fields when an unknown field is set as sortable
528
     */
514
     */
529
    public function test_get_sortfields_unknown_field(): void {
515
    public function test_get_sort_fields_unknown_field(): void {
530
        $column = $this->create_column('test')
516
        $column = $this->create_column('test')