diff --git a/.travis.yml b/.travis.yml index 156e33972..d2d94d077 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,8 +26,12 @@ script: branches: except: - - translation-staging + - 2.1 + - 2.2 + - 2.3 - 2.4 + - post-2.4 + - translation-staging notifications: irc: diff --git a/model/DB.php b/model/DB.php index e544d1372..70ef907ac 100644 --- a/model/DB.php +++ b/model/DB.php @@ -65,14 +65,14 @@ class DB { * Set it to null to revert to the main database. */ public static function set_alternative_database_name($dbname) { - $_SESSION["alternativeDatabaseName"] = $dbname; + Session::set("alternativeDatabaseName", $dbname); } /** * Get the name of the database in use */ 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) { // This is used by TestRunner::startsession() to test up a test session using an alt - if(isset($_SESSION) && !empty($_SESSION['alternativeDatabaseName'])) { - $databaseConfig['database'] = $_SESSION['alternativeDatabaseName']; + if($name = Session::get('alternativeDatabaseName')) { + $databaseConfig['database'] = $name; } if(!isset($databaseConfig['type']) || empty($databaseConfig['type'])) { diff --git a/model/HTMLValue.php b/model/HTMLValue.php index 4d1884d2b..86d754895 100644 --- a/model/HTMLValue.php +++ b/model/HTMLValue.php @@ -17,14 +17,30 @@ class SS_HTMLValue extends ViewableData { * @param string $content */ public function __construct($content = null) { - $this->document = new DOMDocument('1.0', 'UTF-8'); - $this->document->scrictErrorChecking = false; - + $this->setDocument(new DOMDocument('1.0', 'UTF-8')); + $this->setScrictErrorChecking(false); + $this->setOutputFormatting(false); $this->setContent($content); - + 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 */ @@ -35,16 +51,15 @@ class SS_HTMLValue extends ViewableData { return trim( preg_replace( array( - '/^/i', - '/(.*)/i', - '/<\/body>(.*)/i', + '/(.*)/is', + '/<\/body>(.*)/is', ), '', urldecode($this->getDocument()->saveHTML()) ) ); } - + /** * @param string $content * @return bool @@ -59,14 +74,21 @@ class SS_HTMLValue extends ViewableData { "$content" ); } - + /** * @return DOMDocument */ public function getDocument() { return $this->document; } - + + /** + * @param DOMDocument $document + */ + public function setDocument($document) { + $this->document = $document; + } + /** * A simple convenience wrapper around DOMDocument::getElementsByTagName(). * diff --git a/tests/integration/HTMLValueTest.php b/tests/integration/HTMLValueTest.php index 600325adf..aa2beadbb 100644 --- a/tests/integration/HTMLValueTest.php +++ b/tests/integration/HTMLValueTest.php @@ -6,9 +6,10 @@ class SS_HTMLValueTest extends SapphireTest { public function testInvalidHTMLSaving() { - $value = new SS_HTMLValue(); + $value = new SS_HTMLValue(); $invalid = array ( '

Enclosed Value

' => '

Enclosed Value

', + '' => '', '

' => '

', '' => '', '/bodu>/body>' => '/bodu>/body>' @@ -19,9 +20,22 @@ class SS_HTMLValueTest extends SapphireTest { $this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be saved'); } } - + + public function testUtf8Saving() { + $value = new SS_HTMLValue(); + $value->setContent('

ö ß ā い 家

'); + $this->assertEquals('

ö ß ā い 家

', $value->getContent()); + } + + public function testOutputFormatting() { + $value = new SS_HTMLValue(); + $value->setOutputFormatting(true); + $value->setContent(''); + $this->assertEquals('', $value->getContent(), 'Formatted output works'); + } + public function testInvalidHTMLTagNames() { - $value = new SS_HTMLValue(); + $value = new SS_HTMLValue(); $invalid = array( '

', '
', @@ -30,7 +44,7 @@ class SS_HTMLValueTest extends SapphireTest { foreach($invalid as $input) { $value->setContent($input); - $this->assertEquals ( + $this->assertEquals( 'test-link', $value->getElementsByTagName('a')->item(0)->getAttribute('href'), 'Link data can be extraced from malformed HTML' @@ -47,5 +61,5 @@ class SS_HTMLValueTest extends SapphireTest { 'Newlines get converted' ); } - + }