MDL-36721 make upgrade queries cross-db
[moodle.git] / lib / tests / ajaxlib_test.php
blob9baea2ce8fba6a6b60d342146f1c64fdd928f904
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.
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/>.
17 /**
18 * Code quality unit tests that are fast enough to run each time.
20 * @package core
21 * @category phpunit
22 * @copyright 2013 Andrew Nicols
23 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
26 defined('MOODLE_INTERNAL') || die();
28 class core_ajaxlib_testcase extends advanced_testcase {
30 protected function helper_test_clean_output() {
31 $this->resetAfterTest();
33 $result = ajax_capture_output();
35 // ob_start should normally return without issue.
36 $this->assertTrue($result);
38 $result = ajax_check_captured_output();
39 $this->assertEmpty($result);
42 protected function helper_test_dirty_output($expectexception = false) {
43 $this->resetAfterTest();
45 // Keep track of the content we will output.
46 $content = "Some example content";
48 $result = ajax_capture_output();
50 // ob_start should normally return without issue.
51 $this->assertTrue($result);
53 // Fill the output buffer.
54 echo $content;
56 if ($expectexception) {
57 $this->setExpectedException('coding_exception');
58 ajax_check_captured_output();
59 } else {
60 $result = ajax_check_captured_output();
61 $this->assertEquals($result, $content);
65 public function test_output_capture_normal_debug_none() {
66 global $CFG;
67 // In normal conditions, and with DEBUG_NONE set, we should not receive any output or throw any exceptions.
68 $CFG->debug = DEBUG_NONE;
69 $this->helper_test_clean_output();
72 public function test_output_capture_normal_debug_normal() {
73 global $CFG;
74 // In normal conditions, and with DEBUG_NORMAL set, we should not receive any output or throw any exceptions.
75 $CFG->debug = DEBUG_NORMAL;
76 $this->helper_test_clean_output();
79 public function test_output_capture_normal_debug_all() {
80 global $CFG;
81 // In normal conditions, and with DEBUG_ALL set, we should not receive any output or throw any exceptions.
82 $CFG->debug = DEBUG_ALL;
83 $this->helper_test_clean_output();
86 public function test_output_capture_normal_debugdeveloper() {
87 global $CFG;
88 // In normal conditions, and with DEBUG_DEVELOPER set, we should not receive any output or throw any exceptions.
89 $CFG->debug = DEBUG_DEVELOPER;
90 $this->helper_test_clean_output();
93 public function test_output_capture_error_debug_none() {
94 global $CFG;
95 // With DEBUG_NONE set, we should not throw any exception, but the output will be returned.
96 $CFG->debug = DEBUG_NONE;
97 $this->helper_test_dirty_output();
100 public function test_output_capture_error_debug_normal() {
101 global $CFG;
102 // With DEBUG_NORMAL set, we should not throw any exception, but the output will be returned.
103 $CFG->debug = DEBUG_NORMAL;
104 $this->helper_test_dirty_output();
107 public function test_output_capture_error_debug_all() {
108 global $CFG;
109 // In error conditions, and with DEBUG_ALL set, we should not receive any output or throw any exceptions.
110 $CFG->debug = DEBUG_ALL;
111 $this->helper_test_dirty_output();
114 public function test_output_capture_error_debugdeveloper() {
115 global $CFG;
116 // With DEBUG_DEVELOPER set, we should throw an exception.
117 $CFG->debug = DEBUG_DEVELOPER;
118 $this->helper_test_dirty_output(true);