2008-09-16 20:12:07 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\View\Tests\Parsers;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\View\Parsers\SQLFormatter;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class SQLFormatterTest extends SapphireTest
|
|
|
|
{
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
public function testNewlineHanding()
|
|
|
|
{
|
|
|
|
$formatter = new SQLFormatter();
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$sqlBefore = <<<SQL
|
2008-09-16 20:12:07 +02:00
|
|
|
SELECT Test.Foo, Test.Bar FROM Test WHERE 'From' = "Where"
|
|
|
|
SQL;
|
2016-12-16 05:34:21 +01:00
|
|
|
$sqlAfter = <<<SQL
|
2008-09-16 20:12:07 +02:00
|
|
|
SELECT Test.Foo, Test.Bar
|
|
|
|
FROM Test
|
|
|
|
WHERE 'From' = "Where"
|
|
|
|
SQL;
|
2009-11-21 02:43:54 +01:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$formatter->formatPlain($sqlBefore),
|
|
|
|
$sqlAfter,
|
|
|
|
'correct replacement of newlines and don\'t replace non-uppercase tokens'
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
$sqlBefore = <<<SQL
|
2008-09-16 20:12:07 +02:00
|
|
|
SELECT Test.Foo, Test.Bar
|
|
|
|
FROM Test
|
|
|
|
WHERE
|
|
|
|
'From' = "Where"
|
|
|
|
SQL;
|
2016-12-16 05:34:21 +01:00
|
|
|
$sqlAfter = <<<SQL
|
2008-09-16 20:12:07 +02:00
|
|
|
SELECT Test.Foo, Test.Bar
|
|
|
|
FROM Test
|
|
|
|
WHERE
|
|
|
|
'From' = "Where"
|
|
|
|
SQL;
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->assertEquals(
|
|
|
|
$formatter->formatPlain($sqlBefore),
|
|
|
|
$sqlAfter,
|
|
|
|
'Leave existing newlines and indentation in place'
|
|
|
|
);
|
|
|
|
}
|
2008-09-16 20:12:07 +02:00
|
|
|
}
|