mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-05 07:38:26 +02:00
Merge remote-tracking branch 'origin/3.0'
Conflicts: .travis.yml
This commit is contained in:
commit
1181ba089a
@ -26,8 +26,12 @@ script:
|
|||||||
|
|
||||||
branches:
|
branches:
|
||||||
except:
|
except:
|
||||||
- translation-staging
|
- 2.1
|
||||||
|
- 2.2
|
||||||
|
- 2.3
|
||||||
- 2.4
|
- 2.4
|
||||||
|
- post-2.4
|
||||||
|
- translation-staging
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
irc:
|
irc:
|
||||||
|
@ -65,14 +65,14 @@ class DB {
|
|||||||
* Set it to null to revert to the main database.
|
* Set it to null to revert to the main database.
|
||||||
*/
|
*/
|
||||||
public static function set_alternative_database_name($dbname) {
|
public static function set_alternative_database_name($dbname) {
|
||||||
$_SESSION["alternativeDatabaseName"] = $dbname;
|
Session::set("alternativeDatabaseName", $dbname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the database in use
|
* Get the name of the database in use
|
||||||
*/
|
*/
|
||||||
public static function get_alternative_database_name() {
|
public static function get_alternative_database_name() {
|
||||||
return $_SESSION["alternativeDatabaseName"];
|
return Session::get("alternativeDatabaseName");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,8 +84,8 @@ class DB {
|
|||||||
*/
|
*/
|
||||||
public static function connect($databaseConfig) {
|
public static function connect($databaseConfig) {
|
||||||
// This is used by TestRunner::startsession() to test up a test session using an alt
|
// This is used by TestRunner::startsession() to test up a test session using an alt
|
||||||
if(isset($_SESSION) && !empty($_SESSION['alternativeDatabaseName'])) {
|
if($name = Session::get('alternativeDatabaseName')) {
|
||||||
$databaseConfig['database'] = $_SESSION['alternativeDatabaseName'];
|
$databaseConfig['database'] = $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($databaseConfig['type']) || empty($databaseConfig['type'])) {
|
if(!isset($databaseConfig['type']) || empty($databaseConfig['type'])) {
|
||||||
|
@ -17,14 +17,30 @@ class SS_HTMLValue extends ViewableData {
|
|||||||
* @param string $content
|
* @param string $content
|
||||||
*/
|
*/
|
||||||
public function __construct($content = null) {
|
public function __construct($content = null) {
|
||||||
$this->document = new DOMDocument('1.0', 'UTF-8');
|
$this->setDocument(new DOMDocument('1.0', 'UTF-8'));
|
||||||
$this->document->scrictErrorChecking = false;
|
$this->setScrictErrorChecking(false);
|
||||||
|
$this->setOutputFormatting(false);
|
||||||
$this->setContent($content);
|
$this->setContent($content);
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should strict error checking be used?
|
||||||
|
* @param boolean $bool
|
||||||
|
*/
|
||||||
|
public function setScrictErrorChecking($bool) {
|
||||||
|
$this->getDocument()->scrictErrorChecking = $bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the output be formatted?
|
||||||
|
* @param boolean $bool
|
||||||
|
*/
|
||||||
|
public function setOutputFormatting($bool) {
|
||||||
|
$this->getDocument()->formatOutput = $bool;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@ -35,9 +51,8 @@ class SS_HTMLValue extends ViewableData {
|
|||||||
return trim(
|
return trim(
|
||||||
preg_replace(
|
preg_replace(
|
||||||
array(
|
array(
|
||||||
'/^<!DOCTYPE.+?>/i',
|
'/(.*)<body>/is',
|
||||||
'/(.*)<body>/i',
|
'/<\/body>(.*)/is',
|
||||||
'/<\/body>(.*)/i',
|
|
||||||
),
|
),
|
||||||
'',
|
'',
|
||||||
urldecode($this->getDocument()->saveHTML())
|
urldecode($this->getDocument()->saveHTML())
|
||||||
@ -67,6 +82,13 @@ class SS_HTMLValue extends ViewableData {
|
|||||||
return $this->document;
|
return $this->document;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param DOMDocument $document
|
||||||
|
*/
|
||||||
|
public function setDocument($document) {
|
||||||
|
$this->document = $document;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple convenience wrapper around DOMDocument::getElementsByTagName().
|
* A simple convenience wrapper around DOMDocument::getElementsByTagName().
|
||||||
*
|
*
|
||||||
|
@ -6,9 +6,10 @@
|
|||||||
class SS_HTMLValueTest extends SapphireTest {
|
class SS_HTMLValueTest extends SapphireTest {
|
||||||
|
|
||||||
public function testInvalidHTMLSaving() {
|
public function testInvalidHTMLSaving() {
|
||||||
$value = new SS_HTMLValue();
|
$value = new SS_HTMLValue();
|
||||||
$invalid = array (
|
$invalid = array (
|
||||||
'<p>Enclosed Value</p></p>' => '<p>Enclosed Value</p>',
|
'<p>Enclosed Value</p></p>' => '<p>Enclosed Value</p>',
|
||||||
|
'<meta content="text/html"></meta>' => '<meta content="text/html">',
|
||||||
'<p><div class="example"></div></p>' => '<p></p><div class="example"></div>',
|
'<p><div class="example"></div></p>' => '<p></p><div class="example"></div>',
|
||||||
'<html><html><body><falsetag "attribute=""attribute""">' => '<falsetag></falsetag>',
|
'<html><html><body><falsetag "attribute=""attribute""">' => '<falsetag></falsetag>',
|
||||||
'<body<body<body>/bodu>/body>' => '/bodu>/body>'
|
'<body<body<body>/bodu>/body>' => '/bodu>/body>'
|
||||||
@ -20,8 +21,21 @@ class SS_HTMLValueTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUtf8Saving() {
|
||||||
|
$value = new SS_HTMLValue();
|
||||||
|
$value->setContent('<p>ö ß ā い 家</p>');
|
||||||
|
$this->assertEquals('<p>ö ß ā い 家</p>', $value->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOutputFormatting() {
|
||||||
|
$value = new SS_HTMLValue();
|
||||||
|
$value->setOutputFormatting(true);
|
||||||
|
$value->setContent('<meta content="text/html">');
|
||||||
|
$this->assertEquals('<meta content="text/html">', $value->getContent(), 'Formatted output works');
|
||||||
|
}
|
||||||
|
|
||||||
public function testInvalidHTMLTagNames() {
|
public function testInvalidHTMLTagNames() {
|
||||||
$value = new SS_HTMLValue();
|
$value = new SS_HTMLValue();
|
||||||
$invalid = array(
|
$invalid = array(
|
||||||
'<p><div><a href="test-link"></p></div>',
|
'<p><div><a href="test-link"></p></div>',
|
||||||
'<html><div><a href="test-link"></a></a></html_>',
|
'<html><div><a href="test-link"></a></a></html_>',
|
||||||
@ -30,7 +44,7 @@ class SS_HTMLValueTest extends SapphireTest {
|
|||||||
|
|
||||||
foreach($invalid as $input) {
|
foreach($invalid as $input) {
|
||||||
$value->setContent($input);
|
$value->setContent($input);
|
||||||
$this->assertEquals (
|
$this->assertEquals(
|
||||||
'test-link',
|
'test-link',
|
||||||
$value->getElementsByTagName('a')->item(0)->getAttribute('href'),
|
$value->getElementsByTagName('a')->item(0)->getAttribute('href'),
|
||||||
'Link data can be extraced from malformed HTML'
|
'Link data can be extraced from malformed HTML'
|
||||||
|
Loading…
Reference in New Issue
Block a user