Skip to content

Commit

Permalink
Merge branch '4.7' into 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Mar 1, 2021
2 parents 229672a + 705b746 commit 2c54a3f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/View/Parsers/ShortcodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ protected function insertListAfter($new, $after)
([^\s\/\'"=,]+) # Name
\s* = \s*
(?:
(?:\'([^\']+)\') | # Value surrounded by \'
(?:"([^"]+)") | # Value surrounded by "
(?:\'([^\']*)\') | # Value surrounded by \'
(?:"([^"]*)") | # Value surrounded by "
([^\s,\]]+) # Bare value
)
';
Expand Down
81 changes: 59 additions & 22 deletions tests/php/View/Parsers/ShortcodeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,54 @@ public function testNotRegisteredShortcode()
);
}

public function testSimpleTag()
public function simpleTagDataProvider()
{
$tests = [
'[test_shortcode]',
'[test_shortcode ]', '[test_shortcode,]', '[test_shortcode, ]' . '[test_shortcode/]', '[test_shortcode /]', '[test_shortcode,/]', '[test_shortcode, /]'
return [
['[test_shortcode]'],
['[test_shortcode ]'],
['[test_shortcode,]'],
['[test_shortcode, ][test_shortcode/]'],
['[test_shortcode /]'],
['[test_shortcode,/]'],
['[test_shortcode, /]']
];
}

foreach ($tests as $test) {
$this->parser->parse($test);

$this->assertEquals([], $this->arguments, $test);
$this->assertEquals('', $this->contents, $test);
$this->assertEquals('test_shortcode', $this->tagName, $test);
}
/**
* @dataProvider simpleTagDataProvider
*/
public function testSimpleTag($test)
{
$this->parser->parse($test);
$this->assertEquals([], $this->arguments, $test);
$this->assertEquals('', $this->contents, $test);
$this->assertEquals('test_shortcode', $this->tagName, $test);
}

public function testOneArgument()
public function oneArgumentDataProvider()
{
$tests = [
'[test_shortcode foo="bar"]', '[test_shortcode,foo="bar"]',
"[test_shortcode foo='bar']", "[test_shortcode,foo='bar']",
'[test_shortcode foo = "bar" /]', '[test_shortcode, foo = "bar" /]'
return [
['[test_shortcode foo="bar"]'],
['[test_shortcode,foo="bar"]'],
["[test_shortcode foo='bar']"],
["[test_shortcode,foo='bar']"],
["[test_shortcode foo=bar]"],
["[test_shortcode,foo=bar]"],
['[test_shortcode foo = "bar" /]'],
['[test_shortcode, foo = "bar" /]']
];
}

foreach ($tests as $test) {
$this->parser->parse($test);
/**
* @dataProvider oneArgumentDataProvider
*/
public function testOneArgument($test)
{
$this->parser->parse($test);

$this->assertEquals(['foo' => 'bar'], $this->arguments, $test);
$this->assertEquals('', $this->contents, $test);
$this->assertEquals('test_shortcode', $this->tagName, $test);
}
$this->assertEquals(['foo' => 'bar'], $this->arguments, $test);
$this->assertEquals('', $this->contents, $test);
$this->assertEquals('test_shortcode', $this->tagName, $test);
}

public function testMultipleArguments()
Expand All @@ -121,6 +138,26 @@ public function testMultipleArguments()
$this->assertEquals('test_shortcode', $this->tagName);
}

public function emptyArgumentsDataProvider()
{
return [
['[test_shortcode foo=""]'],
['[test_shortcode,foo=\'\']'],
['[test_shortcode foo=""][/test_shortcode]'],
];
}

/**
* @dataProvider emptyArgumentsDataProvider
*/
public function testEmptyArguments($test)
{
$this->parser->parse($test);
$this->assertEquals(['foo' => ''], $this->arguments);
$this->assertEquals('', $this->contents);
$this->assertEquals('test_shortcode', $this->tagName);
}

public function testEnclosing()
{
$this->parser->parse('[test_shortcode]foo[/test_shortcode]');
Expand Down

0 comments on commit 2c54a3f

Please sign in to comment.