зеркало из https://github.com/nextcloud/cookbook.git
Merge pull request #1162 from nextcloud/fix/multiline-filter
Fix filters to allow for multi-line text in some fields
This commit is contained in:
Коммит
31ad96caab
|
@ -66,11 +66,11 @@ class TestRunner:
|
|||
|
||||
sp = p.pr.run(cmd, env=env)
|
||||
|
||||
l.logger.printSetOutput('silent-fail', 'false')
|
||||
l.logger.printSetOutput('silentFail', 'false')
|
||||
if sp.returncode != 0:
|
||||
if args.install_untested:
|
||||
l.logger.printWarning('Failed testing with setting --install-untested')
|
||||
l.logger.printSetOutput('silent-fail', 'true')
|
||||
l.logger.printSetOutput('silentFail', 'true')
|
||||
return 0
|
||||
else:
|
||||
return sp.returncode
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
[#1119](https://github.com/nextcloud/cookbook/pull/1119) @MarcelRobitaille
|
||||
- Reactivate step debugging in PHP
|
||||
[#1160](https://github.com/nextcloud/cookbook/pull/1160) @christianlupus
|
||||
- Fix multi-line code entry in some fields during editing
|
||||
[#1162](https://github.com/nextcloud/cookbook/pull/1162) @christianlupus
|
||||
|
||||
### Maintenance
|
||||
- Add composer.json to version control to have unique installed dependency versions
|
||||
|
|
|
@ -49,8 +49,7 @@ class FixIngredientsFilter extends AbstractJSONFilter {
|
|||
|
||||
$ingredients = array_map(function ($t) {
|
||||
$t = trim($t);
|
||||
$t = preg_replace('/\s+/', ' ', $t);
|
||||
$t = $this->textCleaner->cleanUp($t);
|
||||
$t = $this->textCleaner->cleanUp($t, false);
|
||||
return $t;
|
||||
}, $ingredients);
|
||||
$ingredients = array_values($ingredients);
|
||||
|
|
|
@ -103,7 +103,6 @@ class FixInstructionsFilter extends AbstractJSONFilter {
|
|||
|
||||
$instructions = array_map(function ($x) {
|
||||
$x = trim($x);
|
||||
$x = preg_replace('/\s+/', ' ', $x);
|
||||
$x = $this->textCleaner->cleanUp($x, false);
|
||||
|
||||
return $x;
|
||||
|
|
|
@ -49,8 +49,7 @@ class FixToolsFilter extends AbstractJSONFilter {
|
|||
|
||||
$tools = array_map(function ($t) {
|
||||
$t = trim($t);
|
||||
$t = preg_replace('/\s+/', ' ', $t);
|
||||
$t = $this->textCleaner->cleanUp($t);
|
||||
$t = $this->textCleaner->cleanUp($t, false);
|
||||
return $t;
|
||||
}, $tools);
|
||||
$tools = array_filter($tools, fn ($t) => ($t));
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Cookbook\tests\Integration\Helper\Filter\JSON;
|
||||
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use OCA\Cookbook\Helper\TextCleanupHelper;
|
||||
use OCA\Cookbook\Exception\InvalidRecipeException;
|
||||
use OCA\Cookbook\Helper\Filter\JSON\FixIngredientsFilter;
|
||||
|
||||
class FixIngredientsFilterTest extends TestCase {
|
||||
/** @var FixIngredientsFilter */
|
||||
private $dut;
|
||||
|
||||
/** @var TextCleanupHelper */
|
||||
private $textCleanupHelper;
|
||||
|
||||
/** @var array */
|
||||
private $stub;
|
||||
|
||||
protected function setUp(): void {
|
||||
/** @var Stub|IL10N $l */
|
||||
$l = $this->createStub(IL10N::class);
|
||||
$l->method('t')->willReturnArgument(0);
|
||||
|
||||
/** @var ILogger */
|
||||
$logger = $this->createStub(ILogger::class);
|
||||
|
||||
$this->textCleanupHelper = new TextCleanupHelper();
|
||||
|
||||
$this->dut = new FixIngredientsFilter($l, $logger, $this->textCleanupHelper);
|
||||
|
||||
$this->stub = [
|
||||
'name' => 'The name of the recipe',
|
||||
'id' => 1234,
|
||||
];
|
||||
}
|
||||
|
||||
public function dp() {
|
||||
return [
|
||||
[['a','b','c'], ['a','b','c'], false],
|
||||
[[' a ',''], ['a'], true],
|
||||
[[" a \tb ",' c '],['a b','c'],true],
|
||||
[["a\nb"],["a\nb"],false],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dp */
|
||||
public function testApply($startVal, $expectedVal, $changed) {
|
||||
$recipe = $this->stub;
|
||||
$recipe['recipeIngredient'] = $startVal;
|
||||
|
||||
$ret = $this->dut->apply($recipe);
|
||||
|
||||
$this->stub['recipeIngredient'] = $expectedVal;
|
||||
$this->assertEquals($changed, $ret);
|
||||
$this->assertEquals($this->stub, $recipe);
|
||||
}
|
||||
|
||||
public function testApplyString() {
|
||||
$recipe = $this->stub;
|
||||
$recipe['recipeIngredient'] = 'some text';
|
||||
|
||||
$this->expectException(InvalidRecipeException::class);
|
||||
|
||||
$this->dut->apply($recipe);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Cookbook\tests\Integration\Helper\Filter\JSON;
|
||||
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use OCA\Cookbook\Service\JsonService;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use OCA\Cookbook\Helper\TextCleanupHelper;
|
||||
use OCA\Cookbook\Helper\Filter\JSON\FixInstructionsFilter;
|
||||
|
||||
/**
|
||||
* @covers OCA\Cookbook\Helper\Filter\JSON\FixInstructionsFilter
|
||||
* @covers OCA\Cookbook\Exception\InvalidRecipeException
|
||||
*/
|
||||
class FixInstructionsFilterTest extends TestCase {
|
||||
/** @var FixInstructionsFilter */
|
||||
private $dut;
|
||||
|
||||
/** @var TextCleanupHelper */
|
||||
private $textCleanupHelper;
|
||||
|
||||
/** @var array */
|
||||
private $stub;
|
||||
|
||||
protected function setUp(): void {
|
||||
/** @var Stub|IL10N $l */
|
||||
$l = $this->createStub(IL10N::class);
|
||||
$l->method('t')->willReturnArgument(0);
|
||||
|
||||
/** @var ILogger */
|
||||
$logger = $this->createStub(ILogger::class);
|
||||
|
||||
$this->textCleanupHelper = new TextCleanupHelper();
|
||||
$jsonService = new JsonService();
|
||||
|
||||
$this->dut = new FixInstructionsFilter($l, $logger, $this->textCleanupHelper, $jsonService);
|
||||
|
||||
$this->stub = [
|
||||
'name' => 'The name of the recipe',
|
||||
'id' => 1234,
|
||||
];
|
||||
}
|
||||
|
||||
public function dpParseInstructions() {
|
||||
yield 'Instructions in multiple lines' => [
|
||||
"a\nb\rc\r\nd",
|
||||
['a','b','c','d'], true
|
||||
];
|
||||
yield 'Instructions with HTML Entities' => [
|
||||
"<p>a</p>\n<ul><li>b</li><li>c</li></ul><p>d</p>",
|
||||
['a','b','c','d'], true
|
||||
];
|
||||
yield 'Instructions with empty HTML Entities' => [
|
||||
"a\n<p></p><ul><li></li><li></li></ul><p></p>\nb\nc\nd",
|
||||
['a','b','c','d'], true
|
||||
];
|
||||
|
||||
yield 'Instructions with Markdown' => [
|
||||
["a\nb\nc"],
|
||||
["a\nb\nc"], false
|
||||
];
|
||||
yield 'Instructions with untrimmed Markdown' => [
|
||||
["a\n b \td\nc"],
|
||||
["a\n b d\nc"], true
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dpParseInstructions */
|
||||
public function testParseInstructions($originalInstructions, $expected, $changeExpected) {
|
||||
$recipe = $this->stub;
|
||||
$recipe['recipeInstructions'] = $originalInstructions;
|
||||
|
||||
$changed = $this->dut->apply($recipe);
|
||||
|
||||
$this->stub['recipeInstructions'] = $expected;
|
||||
$this->assertEquals($this->stub, $recipe);
|
||||
$this->assertEquals($changeExpected, $changed);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\Cookbook\tests\Integration\Helper\Filter\JSON;
|
||||
|
||||
use OCP\IL10N;
|
||||
use OCP\ILogger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\MockObject\Stub;
|
||||
use OCA\Cookbook\Helper\TextCleanupHelper;
|
||||
use OCA\Cookbook\Helper\Filter\JSON\FixToolsFilter;
|
||||
|
||||
class FixToolsFilterTest extends TestCase {
|
||||
/** @var FixToolsFilter */
|
||||
private $dut;
|
||||
|
||||
/** @var TextCleanupHelper */
|
||||
private $textCleanupHelper;
|
||||
|
||||
/** @var array */
|
||||
private $stub;
|
||||
|
||||
protected function setUp(): void {
|
||||
/** @var Stub|IL10N $l */
|
||||
$l = $this->createStub(IL10N::class);
|
||||
$l->method('t')->willReturnArgument(0);
|
||||
|
||||
/** @var ILogger */
|
||||
$logger = $this->createStub(ILogger::class);
|
||||
|
||||
$this->textCleanupHelper = new TextCleanupHelper();
|
||||
|
||||
$this->dut = new FixToolsFilter($l, $logger, $this->textCleanupHelper);
|
||||
|
||||
$this->stub = [
|
||||
'name' => 'The name of the recipe',
|
||||
'id' => 1234,
|
||||
];
|
||||
}
|
||||
|
||||
public function dp() {
|
||||
return [
|
||||
[['a','b','c'], ['a','b','c'], false],
|
||||
[[" a \tb ",' c '],['a b','c'],true],
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dp */
|
||||
public function testApply($startVal, $expectedVal, $changed) {
|
||||
$recipe = $this->stub;
|
||||
$recipe['tools'] = $startVal;
|
||||
|
||||
$ret = $this->dut->apply($recipe);
|
||||
|
||||
$this->stub['tools'] = $expectedVal;
|
||||
$this->assertEquals($changed, $ret);
|
||||
$this->assertEquals($this->stub, $recipe);
|
||||
}
|
||||
}
|
|
@ -50,7 +50,6 @@ class FixIngredientsFilterTest extends TestCase {
|
|||
return [
|
||||
[['a','b','c'], ['a','b','c'], false],
|
||||
[[' a ',''], ['a'], true],
|
||||
[[" a \tb ",' c '],['a b','c'],true],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -137,6 +137,11 @@ class FixInstructionsFilterTest extends TestCase {
|
|||
"a\n<p></p><ul><li></li><li></li></ul><p></p>\nb\nc\nd",
|
||||
['a','b','c','d'], true
|
||||
];
|
||||
|
||||
yield 'Instructions with Markdown' => [
|
||||
["a\nb\nc"],
|
||||
["a\nb\nc"], false
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dpParseInstructions */
|
||||
|
|
|
@ -50,7 +50,6 @@ class FixToolsFilterTest extends TestCase {
|
|||
return [
|
||||
[['a','b','c'], ['a','b','c'], false],
|
||||
[[' a ',''], ['a'], true],
|
||||
[[" a \tb ",' c '],['a b','c'],true],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче