From d8b4ca91d90bc8ee85786558ff4fbe669a73872c Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 6 Nov 2017 12:08:29 +1300 Subject: [PATCH 1/8] FIX: Fix ContextSummary behaviour with UTF8 chars Fixes https://github.com/silverstripe/silverstripe-framework/issues/1396 Ensure that DBTextTest has UTF8 test cases --- src/ORM/FieldType/DBText.php | 10 +++++----- tests/php/ORM/DBTextTest.php | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/ORM/FieldType/DBText.php b/src/ORM/FieldType/DBText.php index 1e6066727..494d21986 100644 --- a/src/ORM/FieldType/DBText.php +++ b/src/ORM/FieldType/DBText.php @@ -198,7 +198,7 @@ class DBText extends DBString $keywords = Convert::raw2xml($keywords); // Find the search string - $position = (int) stripos($text, $keywords); + $position = (int) mb_stripos($text, $keywords); // We want to search string to be in the middle of our block to give it some context $position = max(0, $position - ($characters / 2)); @@ -206,19 +206,19 @@ class DBText extends DBString if ($position > 0) { // We don't want to start mid-word $position = max( - (int) strrpos(substr($text, 0, $position), ' '), - (int) strrpos(substr($text, 0, $position), "\n") + (int) mb_strrpos(substr($text, 0, $position), ' '), + (int) mb_strrpos(substr($text, 0, $position), "\n") ); } - $summary = substr($text, $position, $characters); + $summary = mb_substr($text, $position, $characters); $stringPieces = explode(' ', $keywords); if ($highlight) { // Add a span around all key words from the search term as well if ($stringPieces) { foreach ($stringPieces as $stringPiece) { - if (strlen($stringPiece) > 2) { + if (mb_strlen($stringPiece) > 2) { // Maintain case of original string $summary = preg_replace( '/' . preg_quote($stringPiece, '/') . '/i', diff --git a/tests/php/ORM/DBTextTest.php b/tests/php/ORM/DBTextTest.php index e5985cc33..2fde108a0 100644 --- a/tests/php/ORM/DBTextTest.php +++ b/tests/php/ORM/DBTextTest.php @@ -41,6 +41,7 @@ class DBTextTest extends SapphireTest ['The little brown fox jumped over the lazy cow.', 'The little brown fox...'], ['

Short & Sweet

', '<p>Short & Sweet</p>'], ['This text contains & in it', 'This text contains &...'], + ['Is an umault in schön?', 'Is an umault in schö...'], ]; } @@ -80,7 +81,10 @@ class DBTextTest extends SapphireTest ['

Lorem ipsum dolor sit amet

', 24, '<p>Lorem ipsum dolor...'], ['

Lorem ipsum dolor sit amet

', 24, '<p><span>Lorem ipsum...'], ['

Lorem ipsum

', 24, '<p>Lorem ipsum</p>'], - ['Lorem & ipsum dolor sit amet', 24, 'Lorem &amp; ipsum dolor...'] + ['Lorem & ipsum dolor sit amet', 24, 'Lorem &amp; ipsum dolor...'], + + ['Is an umault in schön or not?', 22, 'Is an umault in schön...'], + ]; } @@ -124,6 +128,9 @@ class DBTextTest extends SapphireTest // If storing HTML you should use DBHTMLText instead ['

Text inside a paragraph tag should also work

', 3, '<p>Text inside a...'], ['

Two words

', 3, '<p>Two words</p>'], + + // Check UTF8 + ['Is an umault in schön or not?', 5, 'Is an umault in schön...'], ]; } @@ -156,6 +163,9 @@ class DBTextTest extends SapphireTest // If storing HTML you should use DBHTMLText instead ['

First sentence.

', 2, '<p>First sentence.</p>'], ['

First sentence. Second sentence. Third sentence

', 2, '<p>First sentence. Second sentence.'], + + // Check UTF8 + ['Is schön. Isn\'t schön.', 1, 'Is schön.'], ]; } @@ -187,6 +197,9 @@ class DBTextTest extends SapphireTest // If storing HTML you should use DBHTMLText instead ['
First sentence.', '<br />First sentence.'], ['

First sentence. Second sentence. Third sentence

', '<p>First sentence.'], + + // Check UTF8 + ['Is schön. Isn\'t schön.', 'Is schön.'], ]; } @@ -243,7 +256,16 @@ class DBTextTest extends SapphireTest 'ate', // it should highlight 3 letters or more. 'A dog ate a cat while looking at a Foobar', + ], + [ + 'both schön and können have umlauts', + 21, + 'schön', + // check UTF8 support + 'both schön and können...', ] + + ]; } From e696d87b9c89fb3cb0173ae24160f23439861a1d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 8 Nov 2017 17:10:58 +1300 Subject: [PATCH 2/8] Adjust getting started docs --- docs/en/00_Getting_Started/02_Composer.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/00_Getting_Started/02_Composer.md b/docs/en/00_Getting_Started/02_Composer.md index 437399cb3..f24618ce8 100644 --- a/docs/en/00_Getting_Started/02_Composer.md +++ b/docs/en/00_Getting_Started/02_Composer.md @@ -41,7 +41,7 @@ For those that use WAMP as a development environment, [detailed information is a Composer can create a new site for you, using the installer as a template (by default composer will download the latest stable version): ``` -composer create-project silverstripe/installer ./my/website/folder +composer create-project silverstripe/installer ./my/website/folder ^4 ``` If you want to get all additional fixtures for testing, such as behat and phpunit configuration, @@ -282,7 +282,7 @@ the latest unstable silverstripe/installer composer create-project silverstripe/installer ./my/website/folder dev-master ``` -Or for the latest development version in the 3.0.x series +Or for the latest development version in the 4.0.x series ``` composer create-project silverstripe/installer ./my/website/folder 4.0.x-dev From 079fffb0f0689ce0ed982c70bad7ec8a7a1d1628 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 8 Nov 2017 12:58:30 +0000 Subject: [PATCH 3/8] DOCS Update 4.0.0 changelog to indicate stable release --- docs/en/04_Changelogs/4.0.0.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 72c761b7e..391c45480 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -1,4 +1,4 @@ -# 4.0.0 (unreleased) +# 4.0.0 ## Introduction @@ -81,7 +81,6 @@ Backup your existing `composer.json` and overwrite it with the following content This composer file uses the new [recipe](https://github.com/silverstripe/recipe-plugin) approach which bundles all core dependencies in a meta package. If you want more granular control over what gets installed, check the `composer.json` files in [recipe-core](https://github.com/silverstripe/recipe-core) and [recipe-cms](https://github.com/silverstripe/recipe-cms). -Since this is a pre-release, you need to allow composer to install unstable dependencies via `minimum-stability: dev`. Now run a `composer update`. This will remove all existing modules from your local codebase since we replaced your project's `composer.json`. Now you can move back your modules From 3cd0b23172d14695c619d081bebe25bbb3dc2a63 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 8 Nov 2017 14:56:13 +0000 Subject: [PATCH 4/8] DOCS add import to upgrade example --- docs/en/04_Changelogs/4.0.0.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 391c45480..12f414bfd 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -487,6 +487,7 @@ For instance, code which logs errors should be upgraded as below: ```diff -SS_Log::log('My error message', SS_Log::ERR); +use Psr\Log\LoggerInterface; ++use SilverStripe\Core\Injector\Injector; +Injector::inst()->get(LoggerInterface::class)->error('My error message'); ``` From 2f9fae32c157a9b36b78c87f34b4ef2e4efc6d6f Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 8 Nov 2017 15:29:15 +0000 Subject: [PATCH 5/8] DOCS Improve return tags for requiredfields class --- src/Forms/RequiredFields.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Forms/RequiredFields.php b/src/Forms/RequiredFields.php index 9972f042d..27916f03b 100644 --- a/src/Forms/RequiredFields.php +++ b/src/Forms/RequiredFields.php @@ -44,7 +44,7 @@ class RequiredFields extends Validator /** * Clears all the validation from this object. * - * @return RequiredFields + * @return $this */ public function removeValidation() { @@ -56,6 +56,7 @@ class RequiredFields extends Validator /** * Debug helper + * @return string */ public function debug() { @@ -152,7 +153,7 @@ class RequiredFields extends Validator * * @param string $field * - * @return RequiredFields + * @return $this */ public function addRequiredField($field) { @@ -166,7 +167,7 @@ class RequiredFields extends Validator * * @param string $field * - * @return RequiredFields + * @return $this */ public function removeRequiredField($field) { @@ -179,7 +180,7 @@ class RequiredFields extends Validator * Add {@link RequiredField} objects together * * @param RequiredFields $requiredFields - * @return RequiredFields + * @return $this */ public function appendRequiredFields($requiredFields) { From 6139de868021f2c6626230a69628de74dc8f03d7 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 8 Nov 2017 15:32:51 +0000 Subject: [PATCH 6/8] FIX Make sure plain parts are rendered when re-rendering emails --- src/Control/Email/Email.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Control/Email/Email.php b/src/Control/Email/Email.php index ffa0dbfd6..230af870f 100644 --- a/src/Control/Email/Email.php +++ b/src/Control/Email/Email.php @@ -621,6 +621,12 @@ class Email extends ViewableData */ public function setBody($body) { + $plainPart = $this->findPlainPart(); + if ($plainPart) { + $this->getSwiftMessage()->detach($plainPart); + } + unset($plainPart); + $body = HTTP::absoluteURLs($body); $this->getSwiftMessage()->setBody($body); @@ -856,6 +862,12 @@ class Email extends ViewableData */ public function generatePlainPartFromBody() { + $plainPart = $this->findPlainPart(); + if ($plainPart) { + $this->getSwiftMessage()->detach($plainPart); + } + unset($plainPart); + $this->getSwiftMessage()->addPart( Convert::xml2raw($this->getBody()), 'text/plain', From fba33ad2e094313ea2654fc474a94e823dcccea5 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 9 Nov 2017 11:52:44 +1300 Subject: [PATCH 7/8] Remove imagick install --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7e07b40a6..ca6eb50ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,7 +58,6 @@ matrix: before_script: # Init PHP - pecl channel-update pecl.php.net - - travis_retry printf "\n" | pecl install imagick - phpenv rehash - phpenv config-rm xdebug.ini || true - echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini From bf20d59cb80050d57fd7ea1baeefef9ec18dc46c Mon Sep 17 00:00:00 2001 From: Russell Michell Date: Thu, 9 Nov 2017 15:39:20 +1300 Subject: [PATCH 8/8] FIX: Fixes SapphireTest masking userland coding errors. --- src/Dev/SapphireTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Dev/SapphireTest.php b/src/Dev/SapphireTest.php index 0c3fec858..8b4cc28cc 100644 --- a/src/Dev/SapphireTest.php +++ b/src/Dev/SapphireTest.php @@ -343,12 +343,18 @@ class SapphireTest extends PHPUnit_Framework_TestCase implements TestOnly * - Custom state helpers * * User code should call parent::setUpBeforeClass() before custom setup code + * + * @throws Exception */ public static function setUpBeforeClass() { // Start tests static::start(); + if (!static::$state) { + throw new Exception('SapphireTest failed to bootstrap!'); + } + // Call state helpers static::$state->setUpOnce(static::class);