2013-03-11 11:40:42 +01:00
|
|
|
<?php
|
|
|
|
|
2016-10-14 03:30:05 +02:00
|
|
|
namespace SilverStripe\View\Tests;
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
use SilverStripe\Control\ContentNegotiator;
|
2016-09-09 08:43:05 +02:00
|
|
|
use SilverStripe\Control\HTTPResponse;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\View\SSViewer;
|
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
class ContentNegotiatorTest extends SapphireTest
|
|
|
|
{
|
|
|
|
public function testXhtmltagReplacement()
|
|
|
|
{
|
2024-09-26 06:16:04 +02:00
|
|
|
$baseTag = SSViewer::getBaseTag(true);
|
|
|
|
$renderedOutput = '<?xml version="1.0" encoding="UTF-8"?>
|
2013-03-11 11:40:42 +01:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
|
2016-12-16 05:34:21 +01:00
|
|
|
. ' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2013-03-11 11:40:42 +01:00
|
|
|
<html>
|
2024-09-26 06:16:04 +02:00
|
|
|
<head>' . $baseTag . '</head>
|
2013-03-11 11:40:42 +01:00
|
|
|
<body>
|
|
|
|
<form action="#">
|
|
|
|
<select>
|
|
|
|
<option>aa</option>
|
|
|
|
<option selected = "selected">bb</option>
|
|
|
|
<option selected="selected">cc</option>
|
|
|
|
<option class="foo" selected>dd</option>
|
|
|
|
<option>ee</option>
|
|
|
|
<option selected value="">ll</option>
|
|
|
|
</select>
|
|
|
|
<input type="checkbox">ff
|
|
|
|
<input type="checkbox" checked = "checked">gg
|
|
|
|
<input type="checkbox" checked="checked">hh
|
|
|
|
<input class="bar" type="checkbox" checked>ii
|
|
|
|
<input type="checkbox" checked class="foo">jj
|
|
|
|
<input type="submit">
|
|
|
|
</form>
|
|
|
|
<body>
|
|
|
|
</html>';
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
// Check that the content negotiator converts to the equally legal formats
|
|
|
|
$negotiator = new ContentNegotiator();
|
2024-09-26 06:16:04 +02:00
|
|
|
$response = new HTTPResponse($renderedOutput);
|
2016-12-16 05:34:21 +01:00
|
|
|
$negotiator->xhtml($response);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
////////////////////////
|
|
|
|
// XHTML select options
|
|
|
|
////////////////////////
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertMatchesRegularExpression('/<option>aa<\/option>/', $response->getBody());
|
|
|
|
$this->assertMatchesRegularExpression('/<option selected = "selected">bb<\/option>/', $response->getBody());
|
|
|
|
$this->assertMatchesRegularExpression('/<option selected="selected">cc<\/option>/', $response->getBody());
|
2016-12-16 05:34:21 +01:00
|
|
|
// Just transform this
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertMatchesRegularExpression('/<option class="foo" selected="selected">dd<\/option>/', $response->getBody());
|
|
|
|
$this->assertMatchesRegularExpression('/<option selected="selected" value="">ll<\/option>/', $response->getBody());
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
////////////////////////////////////////////////
|
|
|
|
// XHTML checkbox options + XHTML input closure
|
|
|
|
////////////////////////////////////////////////
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertMatchesRegularExpression('/<input type="checkbox"\/>ff/', $response->getBody());
|
|
|
|
$this->assertMatchesRegularExpression('/<input type="checkbox" checked = "checked"\/>g/', $response->getBody());
|
|
|
|
$this->assertMatchesRegularExpression('/<input type="checkbox" checked="checked"\/>hh/', $response->getBody());
|
2016-12-16 05:34:21 +01:00
|
|
|
// Just transform this
|
2021-10-27 04:39:47 +02:00
|
|
|
$this->assertMatchesRegularExpression('/<input class="bar" type="checkbox" checked="checked"\/>ii/', $response->getBody());
|
|
|
|
$this->assertMatchesRegularExpression('/<input type="checkbox" checked="checked" class="foo"\/>jj/', $response->getBody());
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2013-03-11 11:40:42 +01:00
|
|
|
}
|