From eacfe280c1524ff12b61e3fe7665ecbbef8bf53e Mon Sep 17 00:00:00 2001 From: Matthias Schelling Date: Wed, 6 Sep 2017 09:28:33 +0200 Subject: [PATCH 01/11] TreeDropdownField: replace onadd by onmatch Makes TreeDropdownField work in situations where it's moved around in the DOM (e.g. when inside a drag'n'drop container) --- javascript/TreeDropdownField.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/javascript/TreeDropdownField.js b/javascript/TreeDropdownField.js index 782f697e0..32453695e 100644 --- a/javascript/TreeDropdownField.js +++ b/javascript/TreeDropdownField.js @@ -47,7 +47,7 @@ // XMLHttpRequest CurrentXhr: null, - onadd: function() { + onmatch: function() { this.append( '' + '' + @@ -334,7 +334,7 @@ }); $('.TreeDropdownField.searchable').entwine({ - onadd: function() { + onmatch: function() { this._super(); var title = ss.i18n._t('TreeDropdownField.ENTERTOSEARCH'); this.find('.treedropdownfield-panel').prepend( @@ -431,13 +431,13 @@ }); $('.TreeDropdownField input[type=hidden]').entwine({ - onadd: function() { + onmatch: function() { this._super(); this.bind('change.TreeDropdownField', function() { $(this).getField().updateTitle(); }); }, - onremove: function() { + onunmatch: function() { this._super(); this.unbind('.TreeDropdownField'); } From dda14e89596a0de0b70eace27f7015bc0bb40669 Mon Sep 17 00:00:00 2001 From: Roman Schmid Date: Thu, 16 Nov 2017 11:07:20 +0100 Subject: [PATCH 02/11] Fix HTTP::get_mime_type with uppercase filenames. The fallback of `HTTP::get_mime_type` (that uses a lookup instead of `finfo`) doesn't ensure the extension is converted to lowercase before the lookup. A file named `Image.JPG` will return `'application/unknown'`. This change fixes this issue. --- control/HTTP.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/control/HTTP.php b/control/HTTP.php index 3b9cdf2e5..1f0d088c6 100644 --- a/control/HTTP.php +++ b/control/HTTP.php @@ -271,7 +271,7 @@ class HTTP { // Fallback to use the list from the HTTP.yml configuration and rely on the file extension // to get the file mime-type - $ext = File::get_file_extension($filename); + $ext = strtolower(File::get_file_extension($filename)); // Get the mime-types $mimeTypes = Config::inst()->get('HTTP', 'MimeTypes'); From 3d3096485b176c61bebf8e3f80dc99e2cfe9326d Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 16 Nov 2017 11:00:35 +0000 Subject: [PATCH 03/11] TEST Uppercase file extensions return correct mime type --- tests/control/HTTPTest.php | 1 + tests/control/files/upperfile.JPG | Bin 0 -> 331 bytes 2 files changed, 1 insertion(+) create mode 100644 tests/control/files/upperfile.JPG diff --git a/tests/control/HTTPTest.php b/tests/control/HTTPTest.php index d15bc3655..b208f44ae 100644 --- a/tests/control/HTTPTest.php +++ b/tests/control/HTTPTest.php @@ -179,6 +179,7 @@ class HTTPTest extends FunctionalTest { $this->assertEquals('image/gif', HTTP::get_mime_type(FRAMEWORK_DIR.'/tests/control/files/file.gif')); $this->assertEquals('text/html', HTTP::get_mime_type(FRAMEWORK_DIR.'/tests/control/files/file.html')); $this->assertEquals('image/jpeg', HTTP::get_mime_type(FRAMEWORK_DIR.'/tests/control/files/file.jpg')); + $this->assertEquals('image/jpeg', HTTP::get_mime_type(FRAMEWORK_DIR.'/tests/control/files/upperfile.JPG')); $this->assertEquals('image/png', HTTP::get_mime_type(FRAMEWORK_DIR.'/tests/control/files/file.png')); $this->assertEquals('image/vnd.adobe.photoshop', HTTP::get_mime_type(FRAMEWORK_DIR.'/tests/control/files/file.psd')); diff --git a/tests/control/files/upperfile.JPG b/tests/control/files/upperfile.JPG new file mode 100644 index 0000000000000000000000000000000000000000..3aad05d8fadd75f8d9e02866f695b486f0b46343 GIT binary patch literal 331 zcmex=iF;o{=v;^GnD0RsUZK7IjyJ|1CV5fNcw z8EI*08F@HhWM^mR<>8eO5Ri}(6%>_%OAyQWe}F-dgF%IXk(p7Dfk}{&S&;Gn5r#;h zvzdX8L;}n#9E^ Date: Wed, 15 Nov 2017 19:04:45 -0800 Subject: [PATCH 04/11] FIX for #7606: Ensure the object we're handling is actually an Image instance before calling methods specific to that class (e.g. in case of using SVG's in tag which may be File instances). --- forms/HtmlEditorField.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/forms/HtmlEditorField.php b/forms/HtmlEditorField.php index e088b8401..a43b1cee4 100644 --- a/forms/HtmlEditorField.php +++ b/forms/HtmlEditorField.php @@ -87,13 +87,14 @@ class HtmlEditorField extends TextareaField { $img->setAttribute('src', preg_replace('/([^\?]*)\?r=[0-9]+$/i', '$1', $img->getAttribute('src'))); // Resample the images if the width & height have changed. - if($image = File::find(urldecode(Director::makeRelative($img->getAttribute('src'))))){ + $image = File::find(urldecode(Director::makeRelative($img->getAttribute('src')))); + if($image instanceof Image){ $width = (int)$img->getAttribute('width'); $height = (int)$img->getAttribute('height'); if($width && $height && ($width != $image->getWidth() || $height != $image->getHeight())) { //Make sure that the resized image actually returns an image: - $resized=$image->ResizedImage($width, $height); + $resized = $image->ResizedImage($width, $height); if($resized) $img->setAttribute('src', $resized->getRelativePath()); } } From 4f3deb13e00df74915ecae3f0d9e010708c5d244 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Thu, 16 Nov 2017 11:09:57 +0000 Subject: [PATCH 05/11] TEST filterAny on many_many relations return correct items --- tests/model/DataListTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/model/DataListTest.php b/tests/model/DataListTest.php index ffcc94d63..945c172d5 100755 --- a/tests/model/DataListTest.php +++ b/tests/model/DataListTest.php @@ -774,6 +774,15 @@ class DataListTest extends SapphireTest { $this->assertEquals(1, $list->count()); } + public function testFilterAnyWithRelation() { + $list = DataObjectTest_Player::get(); + $list = $list->filterAny(array( + 'Teams.Title:StartsWith' => 'Team', + 'ID:GreaterThan' => 0, + )); + $this->assertCount(4, $list); + } + public function testFilterAnyMultipleArray() { $list = DataObjectTest_TeamComment::get(); $list = $list->filterAny(array('Name'=>'Bob', 'Comment'=>'This is a team comment by Bob')); From ce3fd370fb07ffc18742323b0dd99f30cf28cf14 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 15 Nov 2017 17:34:41 +0000 Subject: [PATCH 06/11] FIX ManyMany link table joined with LEFT JOIN --- model/DataQuery.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/DataQuery.php b/model/DataQuery.php index 9ccb5912b..733576526 100644 --- a/model/DataQuery.php +++ b/model/DataQuery.php @@ -726,7 +726,7 @@ class DataQuery { list($parentClass, $componentClass, $parentField, $componentField, $relationTable) = $component; $parentBaseClass = ClassInfo::baseDataClass($parentClass); $componentBaseClass = ClassInfo::baseDataClass($componentClass); - $this->query->addInnerJoin($relationTable, + $this->query->addLeftJoin($relationTable, "\"$relationTable\".\"$parentField\" = \"$parentBaseClass\".\"ID\""); if (!$this->query->isJoinedTo($componentBaseClass)) { $this->query->addLeftJoin($componentBaseClass, From 36bb28a41dacd76c7737e239fda90038e11d72b8 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 17 Nov 2017 11:48:24 +0000 Subject: [PATCH 07/11] Loosen PHPUnit constraints --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0c3105f1e..dbc389d59 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "mustangostang/spyc": "^0.6.2" }, "require-dev": { - "phpunit/PHPUnit": "~3.7" + "phpunit/phpunit": "^3 || ^4 || ^5" }, "extra": { "branch-alias": { From a63bb12d92a2a3f23f711ba6ac99e684c4957ad5 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Wed, 22 Nov 2017 13:18:57 +0000 Subject: [PATCH 08/11] Travis retry on imagick install --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b4aa49730..eeff7c468 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,8 +28,8 @@ matrix: before_script: - export CORE_RELEASE=$TRAVIS_BRANCH - - if ! [ $(phpenv version-name) = "5.3" ]; then printf "\n" | pecl install imagick; fi - - if [ $(phpenv version-name) = "5.3" ]; then printf "\n" | pecl install imagick-3.3.0; fi + - if ! [ $(phpenv version-name) = "5.3" ]; then printf "\n" | travis_retry pecl install imagick; fi + - if [ $(phpenv version-name) = "5.3" ]; then printf "\n" | travis_retry pecl install imagick-3.3.0; fi - composer self-update || true - phpenv rehash - phpenv config-rm xdebug.ini From 1053de7ec39d1a2ce6826ea2db8f55114755098d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 9 Nov 2017 14:15:32 +1300 Subject: [PATCH 09/11] BUG Don't redirect in force_redirect() in CLI Replaces #4025 --- control/Director.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/control/Director.php b/control/Director.php index 46565d7b5..1e8fd439b 100644 --- a/control/Director.php +++ b/control/Director.php @@ -810,9 +810,13 @@ class Director implements TemplateGlobalProvider { /** * Skip any further processing and immediately respond with a redirect to the passed URL. * - * @param string $destURL - The URL to redirect to + * @param string $destURL The URL to redirect to + * @return string URL redirected to if on CLI */ protected static function force_redirect($destURL) { + if (static::is_cli()) { + return $destURL; + } $response = new SS_HTTPResponse(); $response->redirect($destURL, 301); @@ -859,9 +863,6 @@ class Director implements TemplateGlobalProvider { $matched = false; if($patterns) { - // Calling from the command-line? - if(!isset($_SERVER['REQUEST_URI'])) return; - $relativeURL = self::makeRelative(Director::absoluteURL($_SERVER['REQUEST_URI'])); // protect portions of the site based on the pattern @@ -887,12 +888,7 @@ class Director implements TemplateGlobalProvider { $destURL = str_replace('http:', 'https:', Director::absoluteURL($url)); - // This coupling to SapphireTest is necessary to test the destination URL and to not interfere with tests - if(class_exists('SapphireTest', false) && SapphireTest::is_running_test()) { - return $destURL; - } else { - self::force_redirect($destURL); - } + return self::force_redirect($destURL); } else { return false; } From 09a003bc13390359fa717a4256f9278303d59544 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Fri, 24 Nov 2017 14:30:47 +0000 Subject: [PATCH 10/11] Fix deprecated usage of getMock in unit tests --- tests/core/manifest/ConfigManifestTest.php | 22 ++++++++-------------- tests/injector/InjectorTest.php | 2 +- tests/model/PaginatedListTest.php | 2 +- tests/parsers/ShortcodeParserTest.php | 4 +++- tests/view/SSViewerTest.php | 4 +++- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/tests/core/manifest/ConfigManifestTest.php b/tests/core/manifest/ConfigManifestTest.php index 5b14df254..337894101 100644 --- a/tests/core/manifest/ConfigManifestTest.php +++ b/tests/core/manifest/ConfigManifestTest.php @@ -30,13 +30,10 @@ class ConfigManifestTest extends SapphireTest { * @return Zend_Cache_Core */ protected function getCacheMock() { - return $this->getMock( - 'Zend_Cache_Core', - array('load', 'save'), - array(), - '', - false - ); + return $this->getMockBuilder('Zend_Cache_Core') + ->setMethods(array('load', 'save')) + ->disableOriginalConstructor() + ->getMock(); } /** @@ -45,13 +42,10 @@ class ConfigManifestTest extends SapphireTest { * @return SS_ConfigManifest */ protected function getManifestMock($methods) { - return $this->getMock( - 'SS_ConfigManifest', - $methods, - array(), // no constructor arguments - '', // default - false // don't call the constructor - ); + return $this->getMockBuilder('SS_ConfigManifest') + ->setMethods($methods) + ->disableOriginalConstructor() + ->getMock(); } /** diff --git a/tests/injector/InjectorTest.php b/tests/injector/InjectorTest.php index de7173523..2fb577ef8 100644 --- a/tests/injector/InjectorTest.php +++ b/tests/injector/InjectorTest.php @@ -605,7 +605,7 @@ class InjectorTest extends SapphireTest { 'service' => array('factory' => 'factory', 'constructor' => array(1, 2, 3)) )); - $factory = $this->getMock('SilverStripe\\Framework\\Injector\\Factory'); + $factory = $this->getMockBuilder('SilverStripe\\Framework\\Injector\\Factory')->getMock(); $factory ->expects($this->once()) ->method('create') diff --git a/tests/model/PaginatedListTest.php b/tests/model/PaginatedListTest.php index 73dc5f879..3447467cc 100644 --- a/tests/model/PaginatedListTest.php +++ b/tests/model/PaginatedListTest.php @@ -43,7 +43,7 @@ class PaginatedListTest extends SapphireTest { } public function testSetPaginationFromQuery() { - $query = $this->getMock('SQLQuery'); + $query = $this->getMockBuilder('SQLQuery')->getMock(); $query->expects($this->once()) ->method('getLimit') ->will($this->returnValue(array('limit' => 15, 'start' => 30))); diff --git a/tests/parsers/ShortcodeParserTest.php b/tests/parsers/ShortcodeParserTest.php index 796d06478..06ec059a5 100644 --- a/tests/parsers/ShortcodeParserTest.php +++ b/tests/parsers/ShortcodeParserTest.php @@ -277,7 +277,9 @@ class ShortcodeParserTest extends SapphireTest { } public function testNoParseAttemptIfNoCode() { - $stub = $this->getMock('ShortcodeParser', array('replaceElementTagsWithMarkers')); + $stub = $this->getMockBuilder('ShortcodeParser') + ->setMethods(array('replaceElementTagsWithMarkers')) + ->getMock(); $stub->register('test', function() { return ''; }); diff --git a/tests/view/SSViewerTest.php b/tests/view/SSViewerTest.php index 440e3fdc0..5f7e0e337 100644 --- a/tests/view/SSViewerTest.php +++ b/tests/view/SSViewerTest.php @@ -138,7 +138,9 @@ class SSViewerTest extends SapphireTest { } public function testRequirements() { - $requirements = $this->getMock("Requirements_Backend", array("javascript", "css")); + $requirements = $this->getMockBuilder("Requirements_Backend") + ->setMethods(array("javascript", "css")) + ->getMock(); $jsFile = FRAMEWORK_DIR . '/tests/forms/a.js'; $cssFile = FRAMEWORK_DIR . '/tests/forms/a.js'; From 7b719d7b9d2a034f7396297fd98d85a89cfa4f72 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 24 Nov 2017 21:16:36 +0000 Subject: [PATCH 11/11] Specify Firefox 31 for Travis Behat builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index eeff7c468..3cb849f4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ addons: apt: packages: - tidy + firefox: "31.0" matrix: include: