Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 16... Línea 16...
16
 
16
 
Línea 17... Línea 17...
17
namespace customfield_select;
17
namespace customfield_select;
18
 
18
 
-
 
19
use core_customfield_generator;
Línea 19... Línea 20...
19
use core_customfield_generator;
20
use core_customfield_test_instance_form;
20
use core_customfield_test_instance_form;
21
use stdClass;
21
 
22
 
22
/**
23
/**
-
 
24
 * Functional test for customfield_select
-
 
25
 *
23
 * Functional test for customfield_select
26
 * @package    customfield_select
24
 *
27
 * @covers     \customfield_select\data_controller
25
 * @package    customfield_select
28
 * @covers     \customfield_select\field_controller
26
 * @copyright  2019 Marina Glancy
29
 * @copyright  2019 Marina Glancy
Línea 27... Línea 30...
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 */
31
 */
29
class plugin_test extends \advanced_testcase {
32
final class plugin_test extends \advanced_testcase {
30
 
33
 
Línea 74... Línea 77...
74
    }
77
    }
Línea 75... Línea 78...
75
 
78
 
76
    /**
79
    /**
77
     * Test for initialising field and data controllers
80
     * Test for initialising field and data controllers
78
     */
81
     */
79
    public function test_initialise() {
82
    public function test_initialise(): void {
80
        $f = \core_customfield\field_controller::create($this->cfields[1]->get('id'));
83
        $f = \core_customfield\field_controller::create($this->cfields[1]->get('id'));
Línea 81... Línea 84...
81
        $this->assertTrue($f instanceof field_controller);
84
        $this->assertTrue($f instanceof field_controller);
82
 
85
 
Línea 93... Línea 96...
93
    /**
96
    /**
94
     * Test for configuration form functions
97
     * Test for configuration form functions
95
     *
98
     *
96
     * Create a configuration form and submit it with the same values as in the field
99
     * Create a configuration form and submit it with the same values as in the field
97
     */
100
     */
98
    public function test_config_form() {
101
    public function test_config_form(): void {
99
        $this->setAdminUser();
102
        $this->setAdminUser();
100
        $submitdata = (array)$this->cfields[1]->to_record();
103
        $submitdata = (array)$this->cfields[1]->to_record();
101
        $submitdata['configdata'] = $this->cfields[1]->get('configdata');
104
        $submitdata['configdata'] = $this->cfields[1]->get('configdata');
Línea 102... Línea 105...
102
 
105
 
Línea 109... Línea 112...
109
    }
112
    }
Línea 110... Línea 113...
110
 
113
 
111
    /**
114
    /**
112
     * Test for instance form functions
115
     * Test for instance form functions
113
     */
116
     */
114
    public function test_instance_form() {
117
    public function test_instance_form(): void {
115
        global $CFG;
118
        global $CFG;
116
        require_once($CFG->dirroot . '/customfield/tests/fixtures/test_instance_form.php');
119
        require_once($CFG->dirroot . '/customfield/tests/fixtures/test_instance_form.php');
117
        $this->setAdminUser();
120
        $this->setAdminUser();
Línea 138... Línea 141...
138
    }
141
    }
Línea 139... Línea 142...
139
 
142
 
140
    /**
143
    /**
141
     * Test for data_controller::get_value and export_value
144
     * Test for data_controller::get_value and export_value
142
     */
145
     */
143
    public function test_get_export_value() {
146
    public function test_get_export_value(): void {
144
        $this->assertEquals(1, $this->cfdata[1]->get_value());
147
        $this->assertEquals(1, $this->cfdata[1]->get_value());
Línea 145... Línea 148...
145
        $this->assertEquals('a', $this->cfdata[1]->export_value());
148
        $this->assertEquals('a', $this->cfdata[1]->export_value());
146
 
149
 
147
        // Field without data but with a default value.
150
        // Field without data but with a default value.
148
        $d = \core_customfield\data_controller::create(0, null, $this->cfields[3]);
151
        $d = \core_customfield\data_controller::create(0, null, $this->cfields[3]);
149
        $this->assertEquals(2, $d->get_value());
152
        $this->assertEquals(2, $d->get_value());
Línea 150... Línea 153...
150
        $this->assertEquals('b', $d->export_value());
153
        $this->assertEquals('b', $d->export_value());
-
 
154
    }
-
 
155
 
-
 
156
    /**
-
 
157
     * Test getting field options, formatted
-
 
158
     */
-
 
159
    public function test_get_options(): void {
-
 
160
        filter_set_global_state('multilang', TEXTFILTER_ON);
-
 
161
        filter_set_applies_to_strings('multilang', true);
-
 
162
 
-
 
163
        $field = $this->get_generator()->create_field([
-
 
164
            'categoryid' => $this->cfcat->get('id'),
-
 
165
            'type' => 'select',
-
 
166
            'shortname' => 'myselect',
-
 
167
            'configdata' => [
-
 
168
                'options' => <<<EOF
-
 
169
                    <span lang="en" class="multilang">Beginner</span><span lang="es" class="multilang">Novato</span>
-
 
170
                    <span lang="en" class="multilang">Intermediate</span><span lang="es" class="multilang">Intermedio</span>
-
 
171
                    <span lang="en" class="multilang">Advanced</span><span lang="es" class="multilang">Avanzado</span>
-
 
172
                EOF,
-
 
173
            ],
-
 
174
        ]);
-
 
175
 
-
 
176
        $this->assertEquals([
-
 
177
            '',
-
 
178
            'Beginner',
-
 
179
            'Intermediate',
-
 
180
            'Advanced',
-
 
181
        ], $field->get_options());
151
    }
182
    }
152
 
183
 
153
    /**
184
    /**
154
     * Data provider for {@see test_parse_value}
185
     * Data provider for {@see test_parse_value}
155
     *
186
     *
156
     * @return array
187
     * @return array
157
     */
188
     */
158
    public function parse_value_provider(): array {
189
    public static function parse_value_provider(): array {
159
        return [
190
        return [
160
            ['Red', 1],
191
            ['Red', 1],
Línea 167... Línea 198...
167
    /**
198
    /**
168
     * Test field parse_value method
199
     * Test field parse_value method
169
     *
200
     *
170
     * @param string $value
201
     * @param string $value
171
     * @param int $expected
202
     * @param int $expected
172
     * @return void
-
 
173
     *
203
     *
174
     * @dataProvider parse_value_provider
204
     * @dataProvider parse_value_provider
175
     */
205
     */
176
    public function test_parse_value(string $value, int $expected) {
206
    public function test_parse_value(string $value, int $expected): void {
177
        $field = $this->get_generator()->create_field([
207
        $field = $this->get_generator()->create_field([
178
            'categoryid' => $this->cfcat->get('id'),
208
            'categoryid' => $this->cfcat->get('id'),
179
            'type' => 'select',
209
            'type' => 'select',
180
            'shortname' => 'myselect',
210
            'shortname' => 'myselect',
181
            'configdata' => [
211
            'configdata' => [
Línea 187... Línea 217...
187
    }
217
    }
Línea 188... Línea 218...
188
 
218
 
189
    /**
219
    /**
190
     * Deleting fields and data
220
     * Deleting fields and data
191
     */
221
     */
192
    public function test_delete() {
222
    public function test_delete(): void {
193
        $this->cfcat->get_handler()->delete_all();
223
        $this->cfcat->get_handler()->delete_all();
194
    }
224
    }