silverstripe-framework/tests/php/View/Parsers/SQLFormatterTest.php
2016-12-19 16:08:19 +13:00

49 lines
1020 B
PHP

<?php
namespace SilverStripe\View\Tests\Parsers;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\Parsers\SQLFormatter;
class SQLFormatterTest extends SapphireTest
{
public function testNewlineHanding()
{
$formatter = new SQLFormatter();
$sqlBefore = <<<SQL
SELECT Test.Foo, Test.Bar FROM Test WHERE 'From' = "Where"
SQL;
$sqlAfter = <<<SQL
SELECT Test.Foo, Test.Bar
FROM Test
WHERE 'From' = "Where"
SQL;
$this->assertEquals(
$formatter->formatPlain($sqlBefore),
$sqlAfter,
'correct replacement of newlines and don\'t replace non-uppercase tokens'
);
$sqlBefore = <<<SQL
SELECT Test.Foo, Test.Bar
FROM Test
WHERE
'From' = "Where"
SQL;
$sqlAfter = <<<SQL
SELECT Test.Foo, Test.Bar
FROM Test
WHERE
'From' = "Where"
SQL;
$this->assertEquals(
$formatter->formatPlain($sqlBefore),
$sqlAfter,
'Leave existing newlines and indentation in place'
);
}
}