[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Unit tests for lib/outputrequirementslibphp. 19 * 20 * @package core 21 * @category phpunit 22 * @copyright 2012 Petr Škoda 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->libdir . '/outputrequirementslib.php'); 30 31 32 class core_outputrequirementslib_testcase extends advanced_testcase { 33 public function test_string_for_js() { 34 $this->resetAfterTest(); 35 36 $page = new moodle_page(); 37 $page->requires->string_for_js('course', 'moodle', 1); 38 $page->requires->string_for_js('course', 'moodle', 1); 39 $this->expectException('coding_exception'); 40 $page->requires->string_for_js('course', 'moodle', 2); 41 42 // Note: we can not switch languages in phpunit yet, 43 // it would be nice to test that the strings are actually fetched in the footer. 44 } 45 46 public function test_one_time_output_normal_case() { 47 $page = new moodle_page(); 48 $this->assertTrue($page->requires->should_create_one_time_item_now('test_item')); 49 $this->assertFalse($page->requires->should_create_one_time_item_now('test_item')); 50 } 51 52 public function test_one_time_output_repeat_output_throws() { 53 $page = new moodle_page(); 54 $page->requires->set_one_time_item_created('test_item'); 55 $this->expectException('coding_exception'); 56 $page->requires->set_one_time_item_created('test_item'); 57 } 58 59 public function test_one_time_output_different_pages_independent() { 60 $firstpage = new moodle_page(); 61 $secondpage = new moodle_page(); 62 $this->assertTrue($firstpage->requires->should_create_one_time_item_now('test_item')); 63 $this->assertTrue($secondpage->requires->should_create_one_time_item_now('test_item')); 64 } 65 66 /** 67 * Test for the jquery_plugin method. 68 * 69 * Test to make sure that backslashes are not generated with either slasharguments set to on or off. 70 */ 71 public function test_jquery_plugin() { 72 global $CFG; 73 74 $this->resetAfterTest(); 75 76 // With slasharguments on. 77 $CFG->slasharguments = 1; 78 79 $page = new moodle_page(); 80 $requirements = $page->requires; 81 // Assert successful method call. 82 $this->assertTrue($requirements->jquery_plugin('jquery')); 83 $this->assertTrue($requirements->jquery_plugin('ui')); 84 85 // Get the code containing the required jquery plugins. 86 $requirecode = $requirements->get_top_of_body_code(); 87 // Make sure that the generated code does not contain backslashes. 88 $this->assertFalse(strpos($requirecode, '\\'), "Output contains backslashes: " . $requirecode); 89 90 // With slasharguments off. 91 $CFG->slasharguments = 0; 92 93 $page = new moodle_page(); 94 $requirements = $page->requires; 95 // Assert successful method call. 96 $this->assertTrue($requirements->jquery_plugin('jquery')); 97 $this->assertTrue($requirements->jquery_plugin('ui')); 98 99 // Get the code containing the required jquery plugins. 100 $requirecode = $requirements->get_top_of_body_code(); 101 // Make sure that the generated code does not contain backslashes. 102 $this->assertFalse(strpos($requirecode, '\\'), "Output contains backslashes: " . $requirecode); 103 } 104 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |