Skip to content

Commit

Permalink
ENGCOM-8056: Fix Parameter Tokenizer omitting first char of key #29542
Browse files Browse the repository at this point in the history
 - Merge Pull Request #29542 from marvinhinz/magento2:patch-5
 - Merged commits:
   1. 4328a2d
   2. 55a1543
   3. 1b322f4
  • Loading branch information
magento-engcom-team committed Sep 16, 2020
2 parents b9c13fd + 1b322f4 commit 789bed8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Filter\Template\Tokenizer;

class ParameterTest extends \PHPUnit\Framework\TestCase
use Magento\Catalog\Block\Product\Widget\NewWidget;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* Test for \Magento\Framework\Filter\Template\Tokenizer\Parameter.
*/
class ParameterTest extends TestCase
{
/**
* Test for getValue
*
* @dataProvider getValueDataProvider
*
* @param string $string
* @param array $values
* @dataProvider getValueDataProvider
* @return void
*/
public function testGetValue($string, $values)
public function testGetValue($string, $values): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Framework\Filter\Template\Tokenizer\Parameter $parameter */
$parameter = $objectManager->create(\Magento\Framework\Filter\Template\Tokenizer\Parameter::class);
$objectManager = Bootstrap::getObjectManager();
/** @var Parameter $parameter */
$parameter = $objectManager->create(Parameter::class);
$parameter->setString($string);

foreach ($values as $value) {
Expand All @@ -25,30 +38,36 @@ public function testGetValue($string, $values)
}

/**
* Test for tokenize
*
* @dataProvider tokenizeDataProvider
*
* @param string $string
* @param array $params
* @return void
*/
public function testTokenize($string, $params)
public function testTokenize(string $string, array $params): void
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Framework\Filter\Template\Tokenizer\Parameter $parameter */
$parameter = $objectManager->create(\Magento\Framework\Filter\Template\Tokenizer\Parameter::class);
$objectManager = Bootstrap::getObjectManager();
$parameter = $objectManager->create(Parameter::class);
$parameter->setString($string);

$this->assertEquals($params, $parameter->tokenize());
}

/**
* DataProvider for testTokenize
*
* @return array
*/
public function tokenizeDataProvider()
public function tokenizeDataProvider(): array
{
return [
[
' type="Magento\\Catalog\\Block\\Product\\Widget\\NewWidget" display_type="all_products"'
. ' products_count="10" template="product/widget/new/content/new_grid.phtml"',
[
'type' => \Magento\Catalog\Block\Product\Widget\NewWidget::class,
'type' => NewWidget::class,
'display_type' => 'all_products',
'products_count' => 10,
'template' => 'product/widget/new/content/new_grid.phtml'
Expand All @@ -58,12 +77,24 @@ public function tokenizeDataProvider()
' type="Magento\Catalog\Block\Product\Widget\NewWidget" display_type="all_products"'
. ' products_count="10" template="product/widget/new/content/new_grid.phtml"',
[
'type' => \Magento\Catalog\Block\Product\Widget\NewWidget::class,
'type' => NewWidget::class,
'display_type' => 'all_products',
'products_count' => 10,
'template' => 'product/widget/new/content/new_grid.phtml'
]
]
],
[
sprintf(
'type="%s" display_type="all_products" products_count="1" template="content/new_grid.phtml"',
NewWidget::class
),
[
'type' => NewWidget::class,
'display_type' => 'all_products',
'products_count' => 1,
'template' => 'content/new_grid.phtml'
],
],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function reset()
*/
public function isWhiteSpace()
{
return trim($this->char()) != $this->char();
return $this->_string === '' ?: trim($this->char()) !== $this->char();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ public function tokenize()
{
$parameters = [];
$parameterName = '';
while ($this->next()) {
do {
if ($this->isWhiteSpace()) {
continue;
} elseif ($this->char() != '=') {
}

if ($this->char() !== '=') {
$parameterName .= $this->char();
} else {
$parameters[$parameterName] = $this->getValue();
$parameterName = '';
}
}
} while ($this->next());
return $parameters;
}

Expand Down

0 comments on commit 789bed8

Please sign in to comment.