-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14283 from jeabakker/fixes
fix(icons): improved handling of invalid cropping coordinates
- Loading branch information
Showing
4 changed files
with
108 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
engine/tests/phpunit/integration/Elgg/EntityIconServiceIntegrationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Elgg; | ||
|
||
class EntityIconServiceIntegrationTest extends IntegrationTestCase { | ||
|
||
public function up() { | ||
$this->createApplication([ | ||
'isolate' => true, | ||
]); | ||
} | ||
|
||
/** | ||
* @dataProvider invalidCoordinatesProvider | ||
*/ | ||
public function testInvalidDetectCroppingCoordinates($input_name, $params) { | ||
$request = $this->prepareHttpRequest('', 'POST', $params); | ||
|
||
_elgg_services()->set('request', $request); | ||
|
||
$service = _elgg_services()->iconService; | ||
$inspector = new \ReflectionClass($service); | ||
$method = $inspector->getMethod('detectCroppingCoordinates'); | ||
$method->setAccessible(true); | ||
|
||
$this->assertFalse($method->invoke($service, $input_name)); | ||
} | ||
|
||
public function invalidCoordinatesProvider() { | ||
return [ | ||
['foo', []], // no input | ||
['foo', ['x1' => '1', 'x2' => '100', 'y1' => '10']], // missing one coordinate (using fallback coords) | ||
['foo', ['foo_x1' => '1', 'foo_x2' => '100', 'foo_y1' => '10']], // missing one coordinate | ||
['foo', ['x1' => '1', 'x2' => '100', 'y1' => '10', 'y2' => 'string']], // one invalid coordinate (using fallback coords) | ||
['foo', ['foo_x1' => '1', 'foo_x2' => '100', 'foo_y1' => '10', 'foo_y2' => 'string']], // one invalid coordinate | ||
['foo', ['x1' => '100', 'x2' => '1', 'y1' => '10', 'y2' => '100']], // x2 < x1 (using fallback coords) | ||
['foo', ['foo_x1' => '100', 'foo_x2' => '1', 'foo_y1' => '10', 'foo_y2' => '100']], // x2 < x1 | ||
['foo', ['x1' => '10', 'x2' => '100', 'y1' => '100', 'y2' => '10']], // y2 < y1 (using fallback coords) | ||
['foo', ['foo_x1' => '10', 'foo_x2' => '100', 'foo_y1' => '100', 'foo_y2' => '10']], // y2 < y1 | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider detectCroppingCoordinatesDataProvider | ||
*/ | ||
public function testDetectCroppingCoordinates($input_name, $params, $expected_value) { | ||
$request = $this->prepareHttpRequest('', 'POST', $params); | ||
|
||
_elgg_services()->set('request', $request); | ||
|
||
$reflector = new \ReflectionClass(_elgg_services()->iconService); | ||
$method = $reflector->getMethod('detectCroppingCoordinates'); | ||
$method->setAccessible(true); | ||
|
||
$result = $method->invoke(_elgg_services()->iconService, $input_name); | ||
|
||
$this->assertEquals($expected_value, $result); | ||
} | ||
|
||
public function detectCroppingCoordinatesDataProvider() { | ||
return [ | ||
['icon', ['x1' => '1', 'x2' => '100', 'y1' => '10', 'y2' => '100'], ['x1' => 1, 'x2' => 100, 'y1' => 10, 'y2' => 100]], | ||
['icon', ['x1' => '1.0', 'x2' => '100.2', 'y1' => '10', 'y2' => '100'], ['x1' => 1, 'x2' => 100, 'y1' => 10, 'y2' => 100]], // handle floats | ||
['icon', ['icon_x1' => '1', 'icon_x2' => '100', 'icon_y1' => '10', 'icon_y2' => '100'], ['x1' => 1, 'x2' => 100, 'y1' => 10, 'y2' => 100]], | ||
['icon', ['x1' => '1', 'x2' => '100', 'y1' => '10', 'y2' => '100'], ['x1' => 1, 'x2' => 100, 'y1' => 10, 'y2' => 100]], // test BC input is used | ||
['icon', ['icon_x1' => '1', 'icon_x2' => '100', 'icon_y1' => '10', 'icon_y2' => '100', 'x1' => '10', 'x2' => '1000', 'y1' => '100', 'y2' => '1000'], ['x1' => 1, 'x2' => 100, 'y1' => 10, 'y2' => 100]], // test BC input isn't used | ||
]; | ||
} | ||
} |
38 changes: 0 additions & 38 deletions
38
engine/tests/phpunit/integration/Elgg/Integration/EntityIconServiceIntegrationTest.php
This file was deleted.
Oops, something went wrong.