Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/simpletest/testoutputlib.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00027 if (!defined('MOODLE_INTERNAL')) {
00028     die('Direct access to this script is forbidden.');    
00029 }
00030 require_once($CFG->libdir . '/outputlib.php');
00031 
00032 
00042 class xhtml_container_stack_test extends UnitTestCase {
00043 
00044     public static $includecoverage = array('lib/outputlib.php');
00045     protected function start_capture() {
00046         ob_start();
00047     }
00048 
00049     protected function end_capture() {
00050         $result = ob_get_contents();
00051         ob_end_clean();
00052         return $result;
00053     }
00054 
00055     public function test_push_then_pop() {
00056         // Set up.
00057         $stack = new xhtml_container_stack();
00058         // Exercise SUT.
00059         $this->start_capture();
00060         $stack->push('testtype', '</div>');
00061         $html = $stack->pop('testtype');
00062         $errors = $this->end_capture();
00063         // Verify outcome
00064         $this->assertEqual('</div>', $html);
00065         $this->assertEqual('', $errors);
00066     }
00067 
00068     public function test_mismatched_pop_prints_warning() {
00069         // Set up.
00070         $stack = new xhtml_container_stack();
00071         $stack->push('testtype', '</div>');
00072         // Exercise SUT.
00073         $this->start_capture();
00074         $html = $stack->pop('mismatch');
00075         $errors = $this->end_capture();
00076         // Verify outcome
00077         $this->assertEqual('</div>', $html);
00078         $this->assertNotEqual('', $errors);
00079     }
00080 
00081     public function test_pop_when_empty_prints_warning() {
00082         // Set up.
00083         $stack = new xhtml_container_stack();
00084         // Exercise SUT.
00085         $this->start_capture();
00086         $html = $stack->pop('testtype');
00087         $errors = $this->end_capture();
00088         // Verify outcome
00089         $this->assertEqual('', $html);
00090         $this->assertNotEqual('', $errors);
00091     }
00092 
00093     public function test_correct_nesting() {
00094         // Set up.
00095         $stack = new xhtml_container_stack();
00096         // Exercise SUT.
00097         $this->start_capture();
00098         $stack->push('testdiv', '</div>');
00099         $stack->push('testp', '</p>');
00100         $html2 = $stack->pop('testp');
00101         $html1 = $stack->pop('testdiv');
00102         $errors = $this->end_capture();
00103         // Verify outcome
00104         $this->assertEqual('</p>', $html2);
00105         $this->assertEqual('</div>', $html1);
00106         $this->assertEqual('', $errors);
00107     }
00108 
00109     public function test_pop_all_but_last() {
00110         // Set up.
00111         $stack = new xhtml_container_stack();
00112         $stack->push('test1', '</h1>');
00113         $stack->push('test2', '</h2>');
00114         $stack->push('test3', '</h3>');
00115         // Exercise SUT.
00116         $this->start_capture();
00117         $html = $stack->pop_all_but_last();
00118         $errors = $this->end_capture();
00119         // Verify outcome
00120         $this->assertEqual('</h3></h2>', $html);
00121         $this->assertEqual('', $errors);
00122         // Tear down.
00123         $stack->discard();
00124     }
00125 
00126     public function test_pop_all_but_last_only_one() {
00127         // Set up.
00128         $stack = new xhtml_container_stack();
00129         $stack->push('test1', '</h1>');
00130         // Exercise SUT.
00131         $this->start_capture();
00132         $html = $stack->pop_all_but_last();
00133         $errors = $this->end_capture();
00134         // Verify outcome
00135         $this->assertEqual('', $html);
00136         $this->assertEqual('', $errors);
00137         // Tear down.
00138         $stack->discard();
00139     }
00140 
00141     public function test_pop_all_but_last_empty() {
00142         // Set up.
00143         $stack = new xhtml_container_stack();
00144         // Exercise SUT.
00145         $this->start_capture();
00146         $html = $stack->pop_all_but_last();
00147         $errors = $this->end_capture();
00148         // Verify outcome
00149         $this->assertEqual('', $html);
00150         $this->assertEqual('', $errors);
00151     }
00152 
00153     public function test_discard() {
00154         // Set up.
00155         $stack = new xhtml_container_stack();
00156         $stack->push('test1', '</somethingdistinctive>');
00157         $stack->discard();
00158         // Exercise SUT.
00159         $this->start_capture();
00160         $stack = null;
00161         $errors = $this->end_capture();
00162         // Verify outcome
00163         $this->assertEqual('', $errors);
00164     }
00165 }
 All Data Structures Namespaces Files Functions Variables Enumerations