1<?php
2/* vim: set expandtab tabstop=4 shiftwidth=4: */
3// +----------------------------------------------------------------------+
4// | PHP version 5                                                        |
5// +----------------------------------------------------------------------+
6// | Copyright (c) 1997-2004 The PHP Group                                |
7// +----------------------------------------------------------------------+
8// | This source file is subject to version 3.0 of the PHP license,       |
9// | that is bundled with this package in the file LICENSE, and is        |
10// | available through the world-wide-web at the following url:           |
11// | http://www.php.net/license/3_0.txt.                                  |
12// | If you did not receive a copy of the PHP license and are unable to   |
13// | obtain it through the world-wide-web, please send a note to          |
14// | license@php.net so we can mail you a copy immediately.               |
15// +----------------------------------------------------------------------+
16// | Authors: Claudio Bustos <cdx@users.sourceforge.net>                  |
17// |          Jens Bierkandt <schtorch@users.sourceforge.net>             |
18// +----------------------------------------------------------------------+
19//
20// $Id:
21require_once('Helpers.php');
22
23
24class BeautifierBugsTest extends PHPUnit_Framework_TestCase
25{
26
27    function setUp()
28    {
29        $this->oBeaut = new PHP_Beautifier();
30    }
31    function setText($sText)
32    {
33        $this->oBeaut->setInputString($sText);
34        $this->oBeaut->process();
35    }
36    /**
37     * HeredocBeforeCloseTag
38     * Close tag after heredoc remove whitespace,
39     * breaking the script.
40     *
41     */
42    function testBugInternal1()
43    {
44        $sText = <<<SCRIPT
45<?php
46\$a = <<<HEREDOC
47sdsdsds
48HEREDOC;
49?>
50SCRIPT;
51        $this->setText($sText);
52        $sExpected = <<<SCRIPT
53<?php
54\$a = <<<HEREDOC
55sdsdsds
56HEREDOC;
57
58?>
59SCRIPT;
60        $this->assertEquals($sExpected, $this->oBeaut->get());
61    }
62    /**
63     * Bug 1597
64     * Brace after short comment in new line was appended to
65     * the comment, breaking the code
66     */
67    function testBug1597()
68    {
69        $sText = <<<SCRIPT
70<?php
71if (\$_POST["url"] != "") //inserting data
72{
73}
74?>
75SCRIPT;
76        $this->setText($sText);
77        $sExpected = <<<SCRIPT
78<?php
79if (\$_POST["url"] != "") //inserting data
80{
81}
82?>
83SCRIPT;
84        $this->assertEquals($sExpected, $this->oBeaut->get());
85    }
86    /**
87     * Bug 2301
88     * When I try to beautify PHP5 code with the 'throw new Exception'
89     * statement, the code is not formatted correctly. The
90     * whitespace between throw AND new is deleted.
91     */
92    function testBug2301()
93    {
94        $sText = <<<SCRIPT
95<?php
96throw new AccountFindException();
97?>
98SCRIPT;
99        $this->setText($sText);
100        $sExpected = <<<SCRIPT
101<?php
102throw new AccountFindException();
103?>
104SCRIPT;
105        $this->assertEquals($sExpected, $this->oBeaut->get());
106    }
107    /**
108     * Bug from Pavel Chtchevaev, 2004-11-17
109     * There's one more issue about the default filter, try beautifying with
110     * it the following string:
111     * "<?php\n\$o->_test1(\$c->test2()->test3())\n?>"
112     * It will return:
113     * "<?php\n    \$o->_test1(\$c->test2() ->test3())\n?>"
114     */
115    function testBugChtchevaev_2004_11_17()
116    {
117        $sText = <<<SCRIPT
118<?php
119\$o->_test1(\$c-> test2()-> test3());
120?>
121SCRIPT;
122        $this->setText($sText);
123        $sExpected = <<<SCRIPT
124<?php
125\$o->_test1(\$c->test2()->test3());
126?>
127SCRIPT;
128        $this->assertEquals($sExpected, $this->oBeaut->get());
129    }
130    /**
131     * Bug 3257
132     * Comments between if and elseif screws up formatting.
133     * The beautifier will cascade and start moving the indentations over
134     * if there is a comment between if {} and elseif {}
135     */
136    function testBug3257()
137    {
138        $sText = <<<SCRIPT
139<?php
140    class Foo {
141        var \$foobar = 0;
142        function Foo(\$a, \$b) {
143            if (\$a) {
144                dostuff();
145            }
146            // \$a no good
147            elseif {
148                dootherstuff();
149            }
150            // \$c maybe
151            elseif {
152                yea();
153            }
154        }
155
156        function bar() {
157            echo "Hello";
158        }
159    }
160
161?>
162SCRIPT;
163        $this->setText($sText);
164        $sExpected = <<<SCRIPT
165<?php
166class Foo {
167    var \$foobar = 0;
168    function Foo(\$a, \$b) {
169        if (\$a) {
170            dostuff();
171        }
172        // \$a no good
173        elseif {
174            dootherstuff();
175        }
176        // \$c maybe
177        elseif {
178            yea();
179        }
180    }
181    function bar() {
182        echo "Hello";
183    }
184}
185?>
186SCRIPT;
187        $this->assertEquals($sExpected, $this->oBeaut->get());
188    }
189    /**
190     * Bug from Daniel Convissor, 2005-06-20
191     * Switch statements aren't coming out right.  I, and most PEAR developers
192     * I've asked, partial to them looking like this:
193     * @deprecated as bug!
194     * <code>
195     * switch ($subId) {
196     *   case "myevents";
197     *       $myeventsOn = "on";
198     *       break;
199     *   case "publicevents";
200     *       $publiceventsOn = "on";
201     *       break;
202     * }
203     * </code>
204     */
205    function deprecatedtestBugConvissor_2005_06_20()
206    {
207        $this->oBeaut->addFilter("Pear");
208        $sText = <<<SCRIPT
209<?php
210switch (\$subId) {
211case "myevents":
212\$myeventsOn = "on";
213break;
214case "publicevents":
215\$publiceventsOn = "on";
216break;
217}
218?>
219SCRIPT;
220        $this->setText($sText);
221        $sExpected = <<<SCRIPT
222<?php
223switch (\$subId) {
224    case "myevents":
225        \$myeventsOn = "on";
226        break;
227
228    case "publicevents":
229        \$publiceventsOn = "on";
230        break;
231}
232?>
233SCRIPT;
234        $this->assertEquals($sExpected, $this->oBeaut->get());
235    }
236    function testBugJustinh_2005_07_26()
237    {
238        $sText = <<<SCRIPT
239<?php
240switch (\$var) {
241case 1:
242print "hi";
243break;
244case 2:
245default:
246break;
247}
248?>
249SCRIPT;
250        $this->setText($sText);
251        $sExpected = <<<SCRIPT
252<?php
253switch (\$var) {
254    case 1:
255        print "hi";
256    break;
257    case 2:
258    default:
259    break;
260}
261?>
262SCRIPT;
263        $this->assertEquals($sExpected, $this->oBeaut->get());
264    }
265    function testBugjuancarlos2005_09_13()
266    {
267        $this->oBeaut->addFilter("ArrayNested");
268        $this->oBeaut->addFilter('IndentStyles', array(
269            'style' => 'allman'
270        ));
271        $sText = <<<SCRIPT
272<?php include_once ("turnos.conf.php")
273?>
274SCRIPT;
275        $this->setText($sText);
276        $sExpected = <<<SCRIPT
277<?php include_once ("turnos.conf.php")
278?>
279SCRIPT;
280        $this->assertEquals($sExpected, $this->oBeaut->get());
281    }
282    function testBug5711()
283    {
284        $this->oBeaut->addFilter("Pear");
285        $sText = <<<SCRIPT
286<?php
287
288class CampaignManagerConfig {
289
290    const BLOCKSIZE_ALL = 9999999;
291
292    public static function getStagingUrl(\$liveUrl) {
293        return true;
294    }
295
296}
297
298?>
299SCRIPT;
300        $this->setText($sText);
301        $sExpected = <<<SCRIPT
302<?php
303class CampaignManagerConfig
304{
305    const BLOCKSIZE_ALL = 9999999;
306    public static function getStagingUrl(\$liveUrl)
307    {
308        return true;
309    }
310}
311?>
312SCRIPT;
313        $this->assertEquals($sExpected, $this->oBeaut->get());
314    }
315    function testBug6237()
316    {
317        $this->oBeaut->addFilter("Pear");
318        $sText = <<<SCRIPT
319<?php
320\$_SESSION["test\$i"];
321\$_SESSION["test_\$i"];
322\$_SESSION['test_\$i'];
323?>
324SCRIPT;
325        $this->setText($sText);
326        $sExpected = <<<SCRIPT
327<?php
328\$_SESSION["test\$i"];
329\$_SESSION["test_\$i"];
330\$_SESSION['test_\$i'];
331?>
332SCRIPT;
333        $this->assertEquals($sExpected, $this->oBeaut->get());
334    }
335    /**
336     * according to: http://pear.php.net/manual/en/standards.control.php
337     * control strutures should be indented in K&R style
338     *
339     * if (<cond>) {
340     * <body>
341     *   }
342     *   however, are getting indented in Allman style
343     * all control structures are affected.
344     */
345    function testBug7347()
346    {
347        $this->oBeaut->addFilter("Pear");
348        $sText = <<<SCRIPT
349<?php
350class Foo {
351    public function __construct() {
352        if(\$foo && \$bar) { echo "FUBAR"; }
353    }
354}
355?>
356SCRIPT;
357        $this->setText($sText);
358        $sExpected = <<<SCRIPT
359<?php
360class Foo
361{
362    public function __construct()
363    {
364        if (\$foo && \$bar) {
365            echo "FUBAR";
366        }
367    }
368}
369?>
370SCRIPT;
371        $this->assertEquals($sExpected, $this->oBeaut->get());
372    }
373    /**
374     * Bad code to detect tokens
375     */
376    function testInternal2()
377    {
378        $this->assertTrue(array_key_exists(T_COMMENT, $this->oBeaut->aTokenFunctions));
379    }
380    /**
381     * Adding a comment after a case statement in a switch causes
382     * the indenting to be wrong.
383     */
384    function testBug7759()
385    {
386        $sText = <<<SCRIPT
387<?php
388echo 0;
389switch(1) {
390case 1:
391case 5: // 5
392echo 1;
393break;
394case 2: //2
395echo "something";
396echo "something";
397case 3: /*3 */ /* 3? */
398case 4:
399default:
400echo '2';
401break;
402}
403echo 1;
404?>
405SCRIPT;
406        $this->setText($sText);
407        $sExpected = <<<SCRIPT
408<?php
409echo 0;
410switch (1) {
411    case 1:
412    case 5: // 5
413        echo 1;
414    break;
415    case 2: //2
416        echo "something";
417        echo "something";
418    case 3: /*3 */ /* 3? */
419    case 4:
420    default:
421        echo '2';
422    break;
423}
424echo 1;
425?>
426SCRIPT;
427        $this->assertEquals($sExpected, $this->oBeaut->get());
428    }
429    function testBug7818()
430    {
431        //$this->oBeaut->startLog();
432        $sText = <<<SCRIPT
433<?php
434\$field->createElement(\$form, \$this->_table->{\$field->id}, \$defaults);
435?>
436SCRIPT;
437        $this->setText($sText);
438        $sExpected = <<<SCRIPT
439<?php
440\$field->createElement(\$form, \$this->_table->{\$field->id}, \$defaults);
441?>
442SCRIPT;
443        $this->assertEquals($sExpected, $this->oBeaut->get());
444    }
445    /**
446     * Will be great if you can rewrite T_OPEN_TAG_WITH_ECHO
447     * in the default filter, specially <?= because it will be
448     * removed in PHP6.
449     */
450    function testBug7854()
451    {
452        if(ini_get("short_open_tag")) {
453        $this->oBeaut->addFilter("Pear");
454        $sText = <<<SCRIPT
455<?= \$var ?>
456SCRIPT;
457        $this->setText($sText);
458        $sExpected = <<<SCRIPT
459<?php echo \$var ?>
460SCRIPT;
461        $this->assertEquals($sExpected, $this->oBeaut->get());
462        } else {
463            $this->markTestSkipped(
464          'Needs short_open_tag php.ini set.'
465        );
466        }
467    }
468    /**
469     * the first lines are intended if -l "ListClassFunction()"
470     * is enabled
471     */
472    function testBug7307()
473    {
474        // $this->oBeaut->startLog();
475        $this->oBeaut->addFilter("ListClassFunction");
476        $sText = <<<SCRIPT
477<?php
478/**
479 * Class and Function List:
480 * Function list:
481 * Classes list:
482 */
483require_once 'dbobject.class.php';
484require_once 'kfp-globals.inc.php';
485class test {
486    function m1() {}
487    function m2() {}
488}
489function f1() {
490}
491?>
492SCRIPT;
493        $this->setText($sText);
494        $sExpected = <<<SCRIPT
495<?php
496/**
497 * Class and Function List:
498 * Function list:
499 * - m1()
500 * - m2()
501 * - f1()
502 * Classes list:
503 * - test
504 */
505require_once 'dbobject.class.php';
506require_once 'kfp-globals.inc.php';
507class test {
508    function m1() {
509    }
510    function m2() {
511    }
512}
513function f1() {
514}
515?>
516SCRIPT;
517        $this->assertEquals($sExpected, $this->oBeaut->get());
518    }
519    /**
520     * When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;" (notice the missing space, which makes the PHP interpreter quite sour :-(
521     */
522    function testBug_rolfhub_2007_02_07_1()
523    {
524        $sText = <<<SCRIPT
525<?php
526\$i = 0;
527while (++\$i) {
528    switch (\$i) {
529        case 5:
530            echo "At 5<br />";
531        break 1; /* Exit only the switch. */
532        case 10:
533            echo "At 10; quitting<br />";
534        break 2; /* Exit the switch and the while. */
535        default:
536        break;
537    }
538}
539?>
540SCRIPT;
541        $this->setText($sText);
542        $sExpected = <<<SCRIPT
543<?php
544\$i = 0;
545while (++\$i) {
546    switch (\$i) {
547        case 5:
548            echo "At 5<br />";
549        break 1; /* Exit only the switch. */
550        case 10:
551            echo "At 10; quitting<br />";
552        break 2; /* Exit the switch and the while. */
553        default:
554        break;
555    }
556}
557?>
558SCRIPT;
559        $this->assertEquals($sExpected, $this->oBeaut->get());
560    }
561    /**
562     * When using the "break" command, the command takes an optional parameter, see http://de.php.net/break for details. But this doesn't work when using the beautifier, because, for example "break 2;" morphs to "break2;" (notice the missing space, which makes the PHP interpreter quite sour :-(
563     */
564    function testBug_rolfhub_2007_02_07_1_pear()
565    {
566        $this->oBeaut->addFilter("Pear");
567        $sText = <<<SCRIPT
568<?php
569\$i = 0;
570while (++\$i) {
571    switch (\$i) {
572        case 5:
573            echo "At 5<br />";
574        break 1; /* Exit only the switch. */
575        case 10:
576            echo "At 10; quitting<br />";
577        break 2; /* Exit the switch and the while. */
578        default:
579        break;
580    }
581}
582?>
583SCRIPT;
584        $this->setText($sText);
585        $sExpected = <<<SCRIPT
586<?php
587\$i = 0;
588while (++\$i) {
589    switch (\$i) {
590    case 5:
591        echo "At 5<br />";
592        break 1; /* Exit only the switch. */
593    case 10:
594        echo "At 10; quitting<br />";
595        break 2; /* Exit the switch and the while. */
596    default:
597        break;
598    }
599}
600?>
601SCRIPT;
602        $this->assertEquals($sExpected, $this->oBeaut->get());
603    }
604    /**
605     * The beautifer removes the whitespaces left and right of the operator, so for example "echo 2 . 1 . 0 . "\n";" becomes "echo 2.1.0."\n";"
606     */
607    function testBug_rolfhub_2007_02_07_2()
608    {
609        $sText = <<<SCRIPT
610<?php
611echo (1.0 . " " . 2 . 3);
612?>
613SCRIPT;
614        $this->setText($sText);
615        $sExpected = <<<SCRIPT
616<?php
617echo (1.0 . " " . 2 . 3);
618?>
619SCRIPT;
620        $this->assertEquals($sExpected, $this->oBeaut->get());
621    }
622    /**
623     * Description:
624     * ------------
625     * When using the default filter, a T_ARRAY token used as a Type hint
626     * (http://php.net/language.oop5.typehinting) does not get a space
627     * after it.
628     * Similarly the T_CLONE token also misses whitespace after it.
629     */
630    function testBug10839()
631    {
632        $sText = <<<SCRIPT
633<?php
634class test
635{
636 function test(array \$moo)
637 {
638  return clone \$this;
639 }
640 public function test(OtherClass \$otherclass) {
641        echo \$otherclass->var;
642    }
643
644}
645?>
646SCRIPT;
647        $this->setText($sText);
648        $sExpected = <<<SCRIPT
649<?php
650class test {
651    function test(array \$moo) {
652        return clone \$this;
653    }
654    public function test(OtherClass \$otherclass) {
655        echo \$otherclass->var;
656    }
657}
658?>
659SCRIPT;
660        $this->assertEquals($sExpected, $this->oBeaut->get());
661    }
662    /**
663     * When processing the T_DOT in the partial tokenized script, and you use
664     * getPreviousWhitespace(), it will go all the back pass the T_ECHO and
665     * pick up the T_WHITESPACE prior to the T_ECHO.  It should actually stop
666     * at the T_CONSTANT_ENCAPSED_STRING.
667     */
668    function testBug11661()
669    {
670        $sText = <<<SCRIPT
671<?php
672if (empty(\$user_password) AND empty(\$user_password2)) {
673            \$user_password = makepass();
674
675        } elseif (\$user_password != \$user_password2) {
676
677            title(_NEWUSERERROR);
678
679            OpenTable();
680
681            echo '<center><b>'._PASSDIFFERENT.'</b><br /><br />'._GOBACK.'</center>';
682
683            CloseTable();
684
685            include_once('footer.php');
686
687            die();
688
689        } elseif (\$user_password == \$user_password2 AND
690strlen(\$user_password) < \$minpass) {
691
692            title(_NEWUSERERROR);
693
694            OpenTable();
695
696            echo '<center>'._YOUPASSMUSTBE.' <b>'.\$minpass.'</b>' . _CHARLONG . '<br /><br />' . _GOBACK . '</center>';
697
698            CloseTable();
699
700            include_once ('footer.php');
701
702            die();
703
704        }
705?>
706SCRIPT;
707
708$this->setText($sText);
709        $sExpected = <<<SCRIPT
710<?php
711if (empty(\$user_password) AND empty(\$user_password2)) {
712    \$user_password = makepass();
713} elseif (\$user_password != \$user_password2) {
714    title(_NEWUSERERROR);
715    OpenTable();
716    echo '<center><b>' . _PASSDIFFERENT . '</b><br /><br />' . _GOBACK . '</center>';
717    CloseTable();
718    include_once ('footer.php');
719    die();
720} elseif (\$user_password == \$user_password2 AND strlen(\$user_password) < \$minpass) {
721    title(_NEWUSERERROR);
722    OpenTable();
723    echo '<center>' . _YOUPASSMUSTBE . ' <b>' . \$minpass . '</b>' . _CHARLONG . '<br /><br />' . _GOBACK . '</center>';
724    CloseTable();
725    include_once ('footer.php');
726    die();
727}
728?>
729SCRIPT;
730        $this->assertEquals($sExpected, $this->oBeaut->get());
731    }
732    /**
733     * Doesn't works!
734     */
735    function atestComplexCurlySyntax()
736    {
737        try {
738            //$this->oBeaut->startLog();
739            $sText = '<?php
740$great = "fantastic";
741echo "This is { $great}";
742echo "This is {$great}";
743echo "This is ${great}";
744echo "This square is {$square->width}00 centimeters broad.";
745echo "This works: {$arr[4][3]}";
746echo "This is wrong: {$arr[foo][3]}";
747echo "This works: {$arr[foo][3]}";
748echo "This works: " . $arr["foo"][3];
749echo "You can even write {$obj->values[3]->name}";
750// echo "This is the value of the var named $name: {${$name}}";
751?>';
752            $this->setText($sText);
753            $sExpected = '<?php
754$great = "fantastic";
755echo "This is { $great}";
756echo "This is {$great}";
757echo "This is ${great}";
758echo "This square is {$square->width}00 centimeters broad.";
759echo "This works: {$arr[4][3]}";
760echo "This is wrong: {$arr[foo][3]}";
761echo "This works: {$arr[foo][3]}";
762echo "This works: " . $arr["foo"][3];
763echo "You can even write {$obj->values[3]->name}";
764// echo "This is the value of the var named $name: {${$name}}";
765?>';
766            $this->assertEquals($sExpected, $this->oBeaut->get());
767        }
768        catch(Exception $oExp) {
769            $this->assertTrue(false);
770        }
771    }
772
773    /**
774    *  	Double Ternary Issue
775    */
776    function testBug11941()
777    {
778        //$this->oBeaut->startLog();
779        $this->oBeaut->addFilter('Pear');
780        $sText = <<<SCRIPT
781<?php
782\$html_on = ( \$submit || \$refresh ) ? ((!empty(\$HTTP_POST_VARS['disable_html'])) ? 0 : TRUE ):\$userdata['user_allowhtml'];
783?>
784SCRIPT;
785        $this->setText($sText);
786        $sExpected = <<<SCRIPT
787<?php
788\$html_on = (\$submit || \$refresh) ? ((!empty(\$HTTP_POST_VARS['disable_html'])) ? 0 : TRUE) : \$userdata['user_allowhtml'];
789?>
790SCRIPT;
791        $this->assertEquals($sExpected, $this->oBeaut->get());
792    }
793
794
795
796
797    /**
798    * Pear filter appends space to function definition line
799    */
800    function testBug13600()
801    {
802        //$this->oBeaut->startLog();
803        $this->oBeaut->addFilter('Pear');
804        $sText = <<<SCRIPT
805<?php
806function example(){
807}
808?>
809SCRIPT;
810        $this->setText($sText);
811        $sExpected = <<<SCRIPT
812<?php
813function example()
814{
815}
816?>
817SCRIPT;
818        $this->assertEquals($sExpected, $this->oBeaut->get());
819    }
820
821
822    /**
823    * Pear filter breaks output - for valid, curly syntax "$this->{$method}();"
824    */
825    function testBug13602()
826    {
827        //$this->oBeaut->startLog();
828        $this->oBeaut->addFilter('Pear');
829        $sText = <<<SCRIPT
830<?php
831function example()
832{
833    \$this->{\$method}();
834}
835?>
836SCRIPT;
837        $this->setText($sText);
838        $sExpected = <<<SCRIPT
839<?php
840function example()
841{
842    \$this->{\$method}();
843}
844?>
845SCRIPT;
846        $this->assertEquals($sExpected, $this->oBeaut->get());
847    }
848
849
850
851    function testBug13795()
852    {
853        $this->oBeaut->addFilter("IndentStyles");
854        $sText = <<<SCRIPT
855<?php if (true){echo 'a';}else echo 'b'; ?>
856SCRIPT;
857        $this->setText($sText);
858        $sExpected = <<<SCRIPT
859<?php if (true) {
860    echo 'a';
861}
862else echo 'b'; ?>
863SCRIPT;
864        $this->assertEquals($sExpected, $this->oBeaut->get());
865    }
866
867    function testBug13805()
868    {
869        $this->oBeaut->addFilter("Pear");
870        $sText = <<<SCRIPT
871<?php
872switch (\$condition) {
873case 1:
874action1();
875break;
876case 2:
877action2();
878break;
879default:
880defaultaction();
881break;
882}
883?>
884SCRIPT;
885        $this->setText($sText);
886        $sExpected = <<<SCRIPT
887<?php
888switch (\$condition) {
889case 1:
890    action1();
891    break;
892
893case 2:
894    action2();
895    break;
896
897default:
898    defaultaction();
899    break;
900}
901?>
902SCRIPT;
903        $this->assertEquals($sExpected, $this->oBeaut->get());
904    }
905
906
907    function atestBug13861()
908    {
909        $sText = <<<SCRIPT
910<?php
911/*
912<?php
913class test
914{
915    function test()
916    {
917        switch (true) {
918            default:
919        }
920}
921}
922*/
923?>
924SCRIPT;
925        $this->setText($sText);
926        $sExpected = <<<SCRIPT
927<?php
928/*
929<?php
930class test
931{
932    function test()
933    {
934        switch (true) {
935            default:
936        }
937}
938}
939*/
940?>
941SCRIPT;
942        $this->assertEquals($sExpected, $this->oBeaut->get());
943    }
944
945    function testBug14175()
946    {
947        $sText = <<<SCRIPT
948<?php
949func( <<<END
950<form id="editform" name="editform" method="post" action=""
951enctype="multipart/form-data">
952END
953);
954?>
955SCRIPT;
956        $this->setText($sText);
957        $sExpected = <<<SCRIPT
958<?php
959func(<<<END
960<form id="editform" name="editform" method="post" action=""
961enctype="multipart/form-data">
962END
963);
964?>
965SCRIPT;
966        $this->assertEquals($sExpected, $this->oBeaut->get());
967    }
968     function testBug14429()
969    {
970        $this->oBeaut->addFilter('Pear');
971
972        $sText = <<<SCRIPT
973<?php
974\$var = new StdClass();
975\$var->text = 'hello';
976\$ok['what'] = 'ok';
977switch (\$something){
978case 'one':
979echo "{\$var->text} world {\$ok['what']}";
980break;
981default:
982break;
983}
984?>
985SCRIPT;
986        $this->setText($sText);
987        $sExpected = <<<SCRIPT
988<?php
989\$var = new StdClass();
990\$var->text = 'hello';
991\$ok['what'] = 'ok';
992switch (\$something) {
993case 'one':
994    echo "{\$var->text} world {\$ok['what']}";
995    break;
996
997default:
998    break;
999}
1000?>
1001SCRIPT;
1002        $this->assertEquals($sExpected, $this->oBeaut->get());
1003    }
1004function testBug14459()
1005    {
1006        $sText = <<<SCRIPT
1007<?php
1008\$bye = "Goodbye";
1009echo "Curly {Hello}.";
1010echo "Curly {{\$bye}}.";
1011echo "Curly {". \$bye ."}.";
1012?>
1013SCRIPT;
1014        $this->setText($sText);
1015        $sExpected = <<<SCRIPT
1016<?php
1017\$bye = "Goodbye";
1018echo "Curly {Hello}.";
1019echo "Curly {{\$bye}}.";
1020echo "Curly {" . \$bye . "}.";
1021?>
1022SCRIPT;
1023        $this->assertEquals($sExpected, $this->oBeaut->get());
1024    }
1025    /**
1026    * Lowercase filter prepends the control structure with ugly space
1027    */
1028
1029    function testBug11245() {
1030        $this->oBeaut->addFilter('Lowercase');
1031        $sText = <<<SCRIPT
1032<?php
1033IF (\$a OR \$b) { echo 'foo'; } ELSE IF (\$b AND \$c AND \$d) { echo 'bar'; }
1034?>
1035SCRIPT;
1036$this->setText($sText);
1037        $sExpected = <<<SCRIPT
1038<?php
1039if (\$a or \$b) {
1040    echo 'foo';
1041} else if (\$b and \$c and \$d) {
1042    echo 'bar';
1043}
1044?>
1045SCRIPT;
1046        $this->assertEquals($sExpected, $this->oBeaut->get());
1047    }
1048    /**
1049    * Lowercase filter prepends the control structure with ugly space
1050    */
1051
1052    function testBug14396() {
1053        //$this->oBeaut->startLog();
1054        $this->oBeaut->addFilter('Lowercase');
1055        $sText = <<<SCRIPT
1056<?php
1057\$a==FALSE;
1058\$b==TRUE;
1059?>
1060SCRIPT;
1061$this->setText($sText);
1062        $sExpected = <<<SCRIPT
1063<?php
1064\$a == false;
1065\$b == true;
1066?>
1067SCRIPT;
1068        $this->assertEquals($sExpected, $this->oBeaut->get());
1069    }
1070
1071    /**
1072    * Bug 14537
1073    * PHP_Beautifier breaks code with namespace and/or use statements
1074    */
1075    function testBug14537() {
1076
1077        if (version_compare(PHP_VERSION, '5.2.0') >= 0) {
1078
1079            $sText = <<<SCRIPT
1080<?php
1081namespace MyTestnamespace\someSubNS; use OtherNamespace\ClassA; use AnotherNamespace\Class1 as Class2;
1082?>
1083SCRIPT;
1084            $this->setText($sText);
1085        $sExpected = <<<SCRIPT
1086<?php
1087namespace MyTestnamespace\someSubNS;
1088use OtherNamespace\ClassA;
1089use AnotherNamespace\Class1 as Class2;
1090?>
1091SCRIPT;
1092            $this->assertEquals($sExpected, $this->oBeaut->get());
1093        } else {
1094             $this->markTestSkipped(
1095              'Needs PHP5.3+');
1096        }
1097    }
1098
1099    function testBug14754() {
1100        $this->oBeaut->startLog();
1101$sText = <<<SCRIPT
1102<?php
1103class Z {
1104    public function a() {
1105        echo "hi";
1106    }
1107    private function b() {
1108        echo "hi"; // Comment
1109    }
1110    private function c() {
1111        echo "hi";
1112    }
1113}
1114?>
1115SCRIPT;
1116$this->oBeaut->addFilter('BBY');
1117$this->setText($sText);
1118$sExpected = <<<SCRIPT
1119<?php
1120class Z {
1121    T_CLASSpublic function a() {
1122        echo "hi";
1123    }
1124    T_CLASSprivate function b() {
1125        echo "hi"; // Comment
1126
1127    }
1128    T_CLASSprivate function c() {
1129        echo "hi";
1130    }
1131}
1132?>
1133SCRIPT;
1134        $this->assertEquals($sExpected, $this->oBeaut->get());
1135    }
1136
1137}
1138?>