* @author Kornel Lesiński * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: $ * @link http://phptal.org/ */ class CompressTest extends PHPTAL_TestCase { private function assertStrips($expect,$source, $html5 = false) { $tpl = $this->newPHPTAL(); if ($html5) $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setPreFilter(new PHPTAL_PreFilter_Compress()); $tpl->setSource($source); $this->assertEquals($expect,$tpl->execute()); } function testConsecutiveSpace() { $this->assertStrips("

foo bar baz

", "

foo \t bar\n\n\n baz

"); } function testPreservesPre() { $this->assertStrips("

foo bar

  \tfoo\t   \nbar   
", "

foo \t\n bar

  \tfoo\t   \nbar   
"); } function testCase1() { $this->assertStrips('

foo bar baz

','

foo bar baz

'); } function testCase2() { $this->assertStrips('

foo bar baz

', '

foo bar baz

'); } function testCase3() { $this->assertStrips('

foo bar baz

', '

foo bar baz

'); } function testCase4() { $this->assertStrips('

foo bar baz

','

foo bar baz

'); } function testLastEmptyChild1() { $this->assertStrips('

foo

', '

foo

'); } function testLastEmptyChild2() { $this->assertStrips('

foo

', '

foo

'); } function testLastEmptyChild3() { $this->assertStrips('

foo

', '

foo

'); } function testLastEmptyChild4() { $this->assertStrips('

foo

', '

foo

'); } function testRespectsNamespace() { $this->assertStrips('
z

ke

ep

z
', '
z

ke

ep

z
'); } function testTalRepeatBlock() { $this->assertStrips("
a
x
x
x
b
", "
a
x
b
"); } function testTrimsSpaceBeforeBlockSibling() { $this->assertStrips("
a
b
c
d
e
", "
a
b
c
d
e
"); } function testPreservesSpaceAroundImages() { $this->assertStrips("
","
"); $this->assertStrips("
x
","
x
"); $this->assertStrips("
x y
","
x y
"); $this->assertStrips("
y
","
y
"); } function testPreservesSpaceAroundButtons() { $this->assertStrips("
","
"); $this->assertStrips("
x
","
x
"); $this->assertStrips("
x y
","
x y
"); $this->assertStrips("
y
","
y
"); $this->markTestIncomplete(); $this->assertStrips("
","
"); $this->assertStrips("
x
","
x
"); $this->assertStrips("
x y
","
x y
"); $this->assertStrips("
y
","
y
"); } function testKeepsNewlinesInScript() { $this->assertStrips("",""); } function testTalRepeatInline() { $this->assertStrips("
x x x
", "
x
"); } function testStripsAllInHead() { $this->assertStrips('', ' ", "",true); } function testShortensHTML5TypesSafely() { $this->assertStrips('', '',true); } function testTalBlockInInlineIsInline() { $this->assertStrips("

foo bar

","

foo bar

"); } function testTalBlockInListIsInline() { $this->assertStrips("",""); } function testPreservesSpaceBeforePI() { $this->assertStrips("

foo bar

","

foo

"); } function testTalContent() { $this->assertStrips('

a » b »

','

»

'); } function testAll() { $this->assertStrips("Foo

x xu


foo", ' Foo

x xu


foo '); } }