Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
[#1202](https://github.com/nextcloud/cookbook/pull/1202) @christianlupus
- Fix XPath to allow for microdata parsing with multiple adjacent schema objects in HTML code
[#1220](https://github.com/nextcloud/cookbook/pull/1220) @christianlupus
- Fix filters for array-valued entries in recipes
[#1222](https://github.com/nextcloud/cookbook/pull/1222) @christianlupus

### Maintenance
- Use the pre-built database images for MySQL and PostgreSQL tests
Expand Down
2 changes: 1 addition & 1 deletion lib/Helper/Filter/JSON/FixIngredientsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function apply(array &$json): bool {
$t = $this->textCleaner->cleanUp($t, false);
return $t;
}, $ingredients);
$ingredients = array_values($ingredients);
$ingredients = array_filter($ingredients, fn ($t) => ($t));
$ingredients = array_values($ingredients);

$changed = $ingredients !== $json[self::INGREDIENTS];
$json[self::INGREDIENTS] = $ingredients;
Expand Down
2 changes: 2 additions & 0 deletions lib/Helper/Filter/JSON/FixInstructionsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function apply(array &$json): bool {
return $x;
}, $instructions);
$instructions = array_filter($instructions);
ksort($instructions);
$instructions = array_values($instructions);

$changed = $instructions !== $json[self::INSTRUCTIONS];
$json[self::INSTRUCTIONS] = $instructions;
Expand Down
4 changes: 3 additions & 1 deletion lib/Helper/Filter/JSON/FixToolsFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* If there is already an array present, the entries are cleaned up to prevent malicious chars to be present.
*/
class FixToolsFilter extends AbstractJSONFilter {
private const TOOLS = 'tools';
private const TOOLS = 'tool';

/** @var IL10N */
private $l;
Expand Down Expand Up @@ -53,6 +53,8 @@ public function apply(array &$json): bool {
return $t;
}, $tools);
$tools = array_filter($tools, fn ($t) => ($t));
ksort($tools);
$tools = array_values($tools);

$changed = $tools !== $json[self::TOOLS];
$json[self::TOOLS] = $tools;
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Helper/Filter/JSON/FixToolsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function dp() {
/** @dataProvider dp */
public function testApply($startVal, $expectedVal, $changed) {
$recipe = $this->stub;
$recipe['tools'] = $startVal;
$recipe['tool'] = $startVal;

$ret = $this->dut->apply($recipe);

$this->stub['tools'] = $expectedVal;
$this->stub['tool'] = $expectedVal;
$this->assertEquals($changed, $ret);
$this->assertEquals($this->stub, $recipe);
}
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Helper/Filter/JSON/FixIngredientsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function dp() {
return [
[['a','b','c'], ['a','b','c'], false],
[[' a ',''], ['a'], true],
[[' a ','', 'b'], ['a', 'b'], true],
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Helper/Filter/JSON/FixInstructionsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function dpParseInstructions() {
],
], ['a', 'b', 'c'], true
];

yield 'Issue1210' => [
['a', '', 'b'], ['a', 'b'], true
];
}

/** @dataProvider dpParseInstructions */
Expand Down
9 changes: 5 additions & 4 deletions tests/Unit/Helper/Filter/JSON/FixToolsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,35 @@ public function testNonExisting() {
$recipe = $this->stub;
$this->assertTrue($this->dut->apply($recipe));

$this->stub['tools'] = [];
$this->stub['tool'] = [];
$this->assertEquals($this->stub, $recipe);
}

public function dp() {
return [
[['a','b','c'], ['a','b','c'], false],
[[' a ',''], ['a'], true],
[[' a ','', 'b'], ['a', 'b'], true],
];
}

/** @dataProvider dp */
public function testApply($startVal, $expectedVal, $changed) {
$recipe = $this->stub;
$recipe['tools'] = $startVal;
$recipe['tool'] = $startVal;

$this->textCleanupHelper->method('cleanUp')->willReturnArgument(0);

$ret = $this->dut->apply($recipe);

$this->stub['tools'] = $expectedVal;
$this->stub['tool'] = $expectedVal;
$this->assertEquals($changed, $ret);
$this->assertEquals($this->stub, $recipe);
}

public function testApplyString() {
$recipe = $this->stub;
$recipe['tools'] = 'some text';
$recipe['tool'] = 'some text';

$this->textCleanupHelper->method('cleanUp')->willReturnArgument(0);
$this->expectException(InvalidRecipeException::class);
Expand Down