Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 23... Línea 23...
23
use renderer_base;
23
use renderer_base;
24
use single_button;
24
use single_button;
25
use single_select;
25
use single_select;
26
use theme_config;
26
use theme_config;
27
use url_select;
27
use url_select;
28
use user_picture;
28
use core\output\user_picture;
29
 
-
 
30
defined('MOODLE_INTERNAL') || die();
-
 
31
 
-
 
32
global $CFG;
-
 
33
require_once($CFG->libdir . '/outputcomponents.php');
-
 
Línea 34... Línea 29...
34
 
29
 
35
/**
30
/**
36
 * Unit tests for lib/outputcomponents.php.
31
 * Unit tests for lib/outputcomponents.php.
37
 *
32
 *
38
 * @package   core
33
 * @package   core
39
 * @category  test
34
 * @category  test
40
 * @copyright 2011 David Mudrak <david@moodle.com>
35
 * @copyright 2011 David Mudrak <david@moodle.com>
41
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
37
 */
43
class outputcomponents_test extends \advanced_testcase {
-
 
44
 
38
final class outputcomponents_test extends \advanced_testcase {
45
    /**
39
    /**
46
     * Tests user_picture::fields.
40
     * Tests user_picture::fields.
47
     *
41
     *
48
     * @deprecated since Moodle 3.11 MDL-45242
42
     * @deprecated since Moodle 3.11 MDL-45242
Línea 617... Línea 611...
617
        $this->assertEquals('primary', $data->type);
611
        $this->assertEquals('primary', $data->type);
618
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);
612
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);
619
    }
613
    }
Línea 620... Línea 614...
620
 
614
 
621
    /**
-
 
622
     * Test for checking the template context data for the single_select element legacy API.
-
 
623
     * @covers \single_button
-
 
624
     */
-
 
625
    public function test_single_button_deprecated(): void {
-
 
626
        global $PAGE;
-
 
627
        $url = new \moodle_url('/');
-
 
628
        $realname = 'realname';
-
 
629
        $attributes = [
-
 
630
            'data-dummy' => 'dummy',
-
 
631
        ];
-
 
632
 
-
 
633
        // Test that when we use a true boolean value for the 4th parameter this is set as primary type.
-
 
634
        $singlebutton = new single_button($url, $realname, 'post', single_button::BUTTON_PRIMARY, $attributes);
-
 
635
        $renderer = $PAGE->get_renderer('core');
-
 
636
        $data = $singlebutton->export_for_template($renderer);
-
 
637
        $this->assertEquals($realname, $data->label);
-
 
638
        $this->assertEquals('post', $data->method);
-
 
639
        $this->assertEquals('singlebutton', $data->classes);
-
 
640
        $this->assertEquals('primary', $data->type);
-
 
641
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);
-
 
642
 
-
 
643
        // Test that when we use a false boolean value for the 4th parameter this is set as secondary type.
-
 
644
        $singlebutton = new single_button($url, $realname, 'post', false, $attributes);
-
 
645
        $this->assertDebuggingCalled();
-
 
646
        $renderer = $PAGE->get_renderer('core');
-
 
647
        $data = $singlebutton->export_for_template($renderer);
-
 
648
        $this->assertEquals($realname, $data->label);
-
 
649
        $this->assertEquals('post', $data->method);
-
 
650
        $this->assertEquals('singlebutton', $data->classes);
-
 
651
        $this->assertEquals('secondary', $data->type);
-
 
652
        $this->assertEquals($attributes['data-dummy'], $data->attributes[0]['value']);
-
 
653
 
-
 
654
        // Test that when we set the primary value, then this is reflected in the type.
-
 
655
        $singlebutton->primary = false;
-
 
656
        $this->assertDebuggingCalled();
-
 
657
        $this->assertEquals(single_button::BUTTON_SECONDARY, $singlebutton->type);
-
 
658
        $singlebutton->primary = true;
-
 
659
        $this->assertDebuggingCalled();
-
 
660
        $this->assertEquals(single_button::BUTTON_PRIMARY, $singlebutton->type);
-
 
661
        // Then set the type directly.
-
 
662
 
-
 
663
        $singlebutton->type = single_button::BUTTON_DANGER;
-
 
664
        $data = $singlebutton->export_for_template($renderer);
-
 
665
        $this->assertEquals('danger', $data->type);
-
 
666
 
-
 
667
    }
-
 
668
 
-
 
669
    /**
615
    /**
670
     * Test for checking the template context data for the url_select element.
616
     * Test for checking the template context data for the url_select element.
671
     */
617
     */
672
    public function test_url_select(): void {
618
    public function test_url_select(): void {
Línea 749... Línea 695...
749
        $this->assertTrue(in_array(['name' => 'class', 'value' => $labelclass], $data->labelattributes));
695
        $this->assertTrue(in_array(['name' => 'class', 'value' => $labelclass], $data->labelattributes));
750
        $this->assertTrue(in_array(['name' => 'style', 'value' => $labelstyle], $data->labelattributes));
696
        $this->assertTrue(in_array(['name' => 'style', 'value' => $labelstyle], $data->labelattributes));
751
    }
697
    }
Línea 752... Línea 698...
752
 
698
 
-
 
699
    /**
-
 
700
     * Test for checking the template context data for the url_select element.
-
 
701
     * @covers \url_select::disable_option
-
 
702
     * @covers \url_select::enable_option
-
 
703
     */
-
 
704
    public function test_url_select_disabled_options(): void {
-
 
705
        global $PAGE;
-
 
706
        $url1 = new \moodle_url("/#a");
-
 
707
        $url2 = new \moodle_url("/#b");
-
 
708
        $url3 = new \moodle_url("/#c");
-
 
709
 
-
 
710
        $urls = [
-
 
711
            $url1->out() => 'A',
-
 
712
            $url2->out() => 'B',
-
 
713
            $url3->out() => 'C',
-
 
714
        ];
-
 
715
        $urlselect = new url_select($urls,
-
 
716
            null,
-
 
717
            null,
-
 
718
            'someformid',
-
 
719
            null);
-
 
720
        $renderer = $PAGE->get_renderer('core');
-
 
721
        $urlselect->set_option_disabled($url2->out(), true);
-
 
722
        $data = $urlselect->export_for_template($renderer);
-
 
723
        $this->assertFalse($data->options[0]['disabled']);
-
 
724
        $this->assertTrue($data->options[1]['disabled']);
-
 
725
        $urlselect->set_option_disabled($url2->out(), false);
-
 
726
        $data = $urlselect->export_for_template($renderer);
-
 
727
        $this->assertFalse($data->options[0]['disabled']);
-
 
728
        $this->assertFalse($data->options[1]['disabled']);
-
 
729
    }
-
 
730
 
753
    /**
731
    /**
754
     * Data provider for test_block_contents_is_fake().
732
     * Data provider for test_block_contents_is_fake().
755
     *
733
     *
756
     * @return array
734
     * @return array
757
     */
735
     */
758
    public function block_contents_is_fake_provider() {
736
    public static function block_contents_is_fake_provider(): array {
759
        return [
737
        return [
760
            'Null' => [null, false],
738
            'Null' => [null, false],
761
            'Not set' => [false, false],
739
            'Not set' => [false, false],
762
            'Fake' => ['_fake', true],
740
            'Fake' => ['_fake', true],