-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue #27 #28
base: master
Are you sure you want to change the base?
issue #27 #28
Conversation
The result of this change can be seen in github workflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your pull request.
I've left some comments as to some things that need to be changed.
@@ -87,7 +87,7 @@ public function test_empty_image() { | |||
]; | |||
foreach ($sizes as $size) { | |||
$emptyimage = phpunit_util::call_internal_method($filter, 'empty_image', $size, get_class($filter)); | |||
$this->assertContains('width="'.$size[0].'" height="'.$size[1].'"', $emptyimage); | |||
$this->assertStringContainsString('width="'.$size[0].'" height="'.$size[1].'"', $emptyimage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for the pull request. Are there any benefits to changing this bit of code? I've taken a look at the original assertContains method and it works fine with strings. The only benefit I can see to using assertStringContainsString over assertContains is that it is more explicit in the type its testing for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHP 7.4 retired December 6 2021, PHP 8.0 is much stricter.
Otherwise you get a TypeError: PHPUnit\Framework\Assert::assertContains(): Argument $haystack must be of type iterable, string given.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, that makes total sense.
private static function check_component(array $pathcomponents) { | ||
if ($pathcomponents[1] !== 'mod_page') { | ||
throw new \coding_exception('Component is not a page ('.$pathcomponents[2].')'); | ||
} | ||
} | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment should not be used since the abstract base_component documents this function.
Moodle coding standards state that functions should not be documented if a base class already has a doc block.
You can add the following comment to clarify this if you wish:
// Inherited.
* @param array $pathcomponents | ||
* @param int $maxwidth | ||
* @return string | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inherited method should not have comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just going by Moodle's documented coding standards which state:
"You must include a description even if it appears to be obvious from the @param and/or @return lines.
An exception is made for overridden methods which make no change to the meaning of the parent method and maintain the same arguments/return values. In this case you should omit the comment completely"
https://docs.moodle.org/dev/Coding_style#Functions
I wonder if those errors would show if we documented the functions in an interface instead of the base class?
BTW - I do really appreciate your work on this.
@@ -73,6 +99,13 @@ public static function get_optimised_path(array $pathcomponents, $maxwidth) { | |||
return $optimisedpath; | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inherited method should not have comment.
class question extends base_component { | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inherited method should not have comment.
@@ -244,7 +258,7 @@ private function apply_loadonvisible(array $match, stored_file $file, $originals | |||
if (!$imageinfo || !isset($imageinfo->width)) { | |||
return ($img); | |||
} | |||
$width = $imageinfo->width; | |||
$width = $imageinfo->width > $maxwidth ? $maxwidth : $imageinfo->width; | |||
$height = $imageinfo->height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go over the maximum width then we should adjust the height in ratio to the adjusted width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why calculating max width in this function when you do not use it?
But yes, the height should be also adjusted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will take me a while to familiarise myself with the code before I can answer that - I wrote it about 5 years ago!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I've had a look at the code base and this is what I've found:
apply_loadonvisible only replaces the "<img" portion which should leave any width / height attributes intact.
The maxwidth variable as you stated is not used - it should actually be removed. That's the fix we should go with.
The maxwidth is actually handled in img_add_width_height so we don't need to worry about it in apply_loadonvisible.
* @author Guy Thomas <[email protected]> | ||
* @copyright Copyright (c) 2017 Guy Thomas. | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class behat_filter_imageopt extends behat_base { | ||
/** | ||
* If image optimiser is eneabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo on "eneabled"
* @author Guy Thomas <[email protected]> | ||
* @copyright Copyright (c) 2017 Guy Thomas. | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class behat_filter_imageopt extends behat_base { | ||
/** | ||
* If image optimiser is eneabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -104,26 +107,26 @@ public function test_image_opt_url() { | |||
set_config('maxwidth', '480', 'filter_imageopt'); | |||
|
|||
$fixturefile = 'testpng_2880x1800.png'; | |||
$context = context_system::instance(); | |||
$context = \context_system::instance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests aren't namespaced and therefore you don't need to add a backslash before the classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This goes for every other inserted backslash before a class in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AH - I am wrong. I see that you have inserted a namespace at the top of the file. Please try to add use statements to avoid repeated backslashing.
E.g. after "defined('MOODLE_INTERNAL') || die();"
use context_system
/** | ||
* Tests for filter class | ||
* @package filter_imageopt | ||
* @author Guy Thomas <[email protected]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're adding a file please add yourself as the author since you deserve credit for your work.
Fix Behat integration.