silverstripe-framework/tests/php/View/Parsers/DiffTest.php

60 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2016-10-14 03:30:05 +02:00
namespace SilverStripe\View\Tests\Parsers;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\Parsers\Diff;
class DiffTest extends SapphireTest
{
/**
* @see https://groups.google.com/forum/#!topic/silverstripe-dev/yHcluCvuszo
*/
public function testTableDiff()
{
if (!class_exists('DOMDocument')) {
$this->markTestSkipped('"DOMDocument" required');
return;
}
$from = "<table>
2014-08-15 08:53:05 +02:00
<tbody>
<tr class=\"blah\">
<td colspan=\"2\">Row 1</td>
</tr>
<tr class=\"foo\">
<td>Row 2</td>
<td>Row 2</td>
</tr>
<tr>
<td>Row 3</td>
<td>Row 3</td>
</tr>
</tbody>
</table>";
$to = "<table class=\"new-class\">
2014-08-15 08:53:05 +02:00
<tbody>
<tr class=\"blah\">
<td colspan=\"2\">Row 1</td>
</tr>
<tr class=\"foo\">
<td>Row 2</td>
<td>Row 2</td>
</tr>
</tbody>
</table>";
2014-08-15 08:53:05 +02:00
$expected = "<ins>" . $to . "</ins>" . "<del>" . $from . "</del>";
$compare = Diff::compareHTML($from, $to);
2014-08-15 08:53:05 +02:00
// Very hard to debug this way, wouldn't need to do this if PHP had an *actual* DOM parsing lib,
// and not just the poor excuse that is DOMDocument
$compare = preg_replace('/[\s\t\n\r]*/', '', $compare);
$expected = preg_replace('/[\s\t\n\r]*/', '', $expected);
2014-08-15 08:53:05 +02:00
$this->assertEquals($compare, $expected);
}
}