File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,6 +80,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
8080. HTMLPURIFIER_STRICT removed; no validation is performed on runtime, only
8181 during cache generation
8282. Reordered script calls in maintenance/flush.php
83+ . Command line scripts now honor exit codes
84+ . When --flush fails in unit testers, abort tests and print message
8385
84863.0.0, released 2008-01-06
8587# HTML Purifier is PHP 5 only! The 2.1.x branch will be maintained
Original file line number Diff line number Diff line change @@ -27,9 +27,6 @@ DOCUMENTATION
2727IMPORTANT FEATURES
2828 - Get everything into configuration objects (filters, I'm looking at you)
2929 - Factor out command line parser into its own class, and unit test it
30- - Verbose mode for webtester that includes transcript from command line
31- - Command line maintenance scripts must complain with exit(1) if there are
32- fatal errors
3330 - Emit notices when aliases are used (allow muting these errors)
3431
3532CONFIGDOC
Original file line number Diff line number Diff line change @@ -178,3 +178,33 @@ function printTokens($tokens, $index = null) {
178178 $ string .= '</pre> ' ;
179179 echo $ string ;
180180}
181+
182+ /**
183+ * Convenient "insta-fail" test-case to add if any outside things fail
184+ */
185+ class FailedTest extends UnitTestCase {
186+ protected $ msg , $ details ;
187+ public function __construct ($ msg , $ details = null ) {
188+ $ this ->msg = $ msg ;
189+ $ this ->details = $ details ;
190+ }
191+ public function test () {
192+ $ this ->fail ($ this ->msg );
193+ if ($ this ->details ) $ this ->_reporter ->paintFormattedMessage ($ this ->details );
194+ }
195+ }
196+
197+ /**
198+ * Flushes all caches, and fatally errors out if there's a problem.
199+ */
200+ function htmlpurifier_flush ($ php , $ reporter ) {
201+ exec ($ php . ' ../maintenance/flush.php ' , $ out , $ status );
202+ if ($ status ) {
203+ $ test = new FailedTest (
204+ 'maintenance/flush.php returned non-zero exit status ' ,
205+ wordwrap (implode ("\n" , $ out ), 80 )
206+ );
207+ $ test ->run ($ reporter );
208+ exit (1 );
209+ }
210+ }
Original file line number Diff line number Diff line change 5959
6060// Shell-script code is executed
6161
62+ if ($ AC ['xml ' ]) {
63+ if (!SimpleReporter::inCli ()) header ('Content-Type: text/xml;charset=UTF-8 ' );
64+ $ reporter = new XmlReporter ();
65+ } elseif (SimpleReporter::inCli ()) {
66+ $ reporter = new TextReporter ();
67+ } else {
68+ $ reporter = new HTMLPurifier_SimpleTest_Reporter ('UTF-8 ' , $ AC );
69+ }
70+
6271if ($ AC ['flush ' ]) {
63- if (SimpleReporter::inCli () && !$ AC ['xml ' ]) {
64- passthru ($ AC ['php ' ] . ' ../maintenance/flush.php ' );
65- } else {
66- shell_exec ($ AC ['php ' ] . ' ../maintenance/flush.php ' );
67- }
72+ htmlpurifier_flush ($ AC ['php ' ], $ reporter );
6873}
6974
7075// initialize and load HTML Purifier
157162
158163}
159164
160- if ($ AC ['xml ' ]) {
161- if (!SimpleReporter::inCli ()) header ('Content-Type: text/xml;charset=UTF-8 ' );
162- $ reporter = new XmlReporter ();
163- } elseif (SimpleReporter::inCli ()) {
164- $ reporter = new TextReporter ();
165- } else {
166- $ reporter = new HTMLPurifier_SimpleTest_Reporter ('UTF-8 ' , $ AC );
167- }
168-
169165if ($ AC ['dry ' ]) $ reporter ->makeDry ();
170166
171167$ test ->run ($ reporter );
Original file line number Diff line number Diff line change 4646);
4747htmlpurifier_parse_args ($ AC , $ aliases );
4848
49+ if ($ AC ['xml ' ]) {
50+ $ reporter = new XmlReporter ();
51+ } else {
52+ $ reporter = new TextReporter ();
53+ }
54+
4955// Regenerate any necessary files
50- shell_exec ($ AC ['php ' ] . ' ../maintenance/flush.php ' );
56+ htmlpurifier_flush ($ AC ['php ' ], $ reporter );
5157
52- $ test = new TestSuite ('HTML Purifier Multiple Versions Test ' );
5358$ file = '' ;
5459
5560$ test_files = array ();
5964 if (isset ($ test_files_lookup [$ AC ['file ' ]])) {
6065 $ file = '--file= ' . $ AC ['file ' ];
6166 } else {
62- echo "Invalid file passed \n" ;
63- exit ;
67+ throw new Exception ("Invalid file passed " );
6468 }
6569}
6670// This allows us to get out of having to do dry runs.
6771$ size = count ($ test_files );
6872
73+ // Setup the test
74+ $ test = new TestSuite ('HTML Purifier Multiple Versions Test ' );
6975foreach ($ versions_to_test as $ version ) {
7076 $ flush = '' ;
7177 if (is_array ($ version )) {
104110// add more websites, i.e. more configurations to test.
105111$ test ->addTestCase (new RemoteTestCase ('http://htmlpurifier.org/dev/tests/?xml=1 ' , 'http://htmlpurifier.org/dev/tests/?xml=1&dry=1&flush=1 ' ));
106112
107- if ($ AC ['xml ' ]) {
108- $ reporter = new XmlReporter ();
109- } else {
110- $ reporter = new TextReporter ();
111- }
112113$ test ->run ($ reporter );
113114
114115shell_exec ($ AC ['php ' ] . ' ../maintenance/flush-definition-cache.php ' );
You can’t perform that action at this time.
0 commit comments