Skip to content

Commit

Permalink
Merge pull request #16455 from niden/T16441-tag-factory-reset
Browse files Browse the repository at this point in the history
T16441 tag factory reset
  • Loading branch information
niden authored Oct 24, 2023
2 parents 3e46944 + 4d5f7ba commit 24d225d
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
name: Setup Zephir Extensions
run: |
echo "::set-output name=extensions::zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}"
# echo "extensions=zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}" >> "$GITHUB_ENV" # Need to change the templates to use this


# PHP CodeSniffer inspection
phpcs:
Expand Down Expand Up @@ -180,6 +182,7 @@ jobs:
$PhalconExtPath = "$(php-config --extension-dir)/phalcon.so"
}
echo "::set-output name=extension-path::$PhalconExtPath"
# echo "extension-path=$PhalconExtPath" >> "$GITHUB_ENV" # This needs to be checked, used below somehow

- name: Creates build artifact with Phalcon extension
uses: ./.github/actions/pack-phalcon-ext
Expand Down Expand Up @@ -388,6 +391,7 @@ jobs:
id: get-version
run: |
echo ::set-output name=version::${GITHUB_REF#refs/tags/}
# echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV" # This needs to be checked

- name: Download Phalcon build artifacts
id: download
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

- Changed `Phalcon\Mvc\Model::getMessages()` to also filter with an array of fields [#16265](https://github.com/phalcon/cphalcon/issues/16265)
- Changed `Phalcon\DataMapper\Query\Select::columns()` to accept an array of columns (keys as aliases) instead of `func_get_args` [#16451](https://github.com/phalcon/cphalcon/issues/16451)
- Changed `Phalcon\Html\Helper\AbstractSeries::__invoke()` to no longer clear the internal store when called [#16441](https://github.com/phalcon/cphalcon/issues/16441)

### Added

- Added the ability to define interpolator characters for the `Phalcon\Logger\Formatter\Line` [#16430](https://github.com/phalcon/cphalcon/issues/16430)
- Added `Phalcon\Html\Helper\AbstractSeries::reset()` to clear the internal store when needed [#16441](https://github.com/phalcon/cphalcon/issues/16441)

### Fixed

Expand Down
11 changes: 9 additions & 2 deletions phalcon/Assets/Manager.zep
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ class Manager extends AbstractInjectionAware
string type,
string name
) -> string {
var helper, params, tag;
var helper, output, params, tag;

let params = parameters;

Expand Down Expand Up @@ -1061,6 +1061,13 @@ class Manager extends AbstractInjectionAware
helper->__invoke(""); // no indentation
helper->add(tag, params);

return (string) helper;
let output = (string) helper;

/**
* This is because the helper no longer resets the store automatically
*/
helper->reset();

return output;
}
}
13 changes: 11 additions & 2 deletions phalcon/Html/Helper/AbstractSeries.zep
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ abstract class AbstractSeries extends AbstractHelper
string delimiter = null
) -> <AbstractSeries> {
let this->delimiter = null === delimiter ? PHP_EOL : delimiter,
this->indent = indent,
this->store = [];
this->indent = indent;

return this;
}
Expand All @@ -56,6 +55,16 @@ abstract class AbstractSeries extends AbstractHelper
);
}

/**
* Resets the internal store.
*/
public function reset() -> <AbstractSeries>
{
let this->store = [];

return this;
}

/**
* Returns the tag name.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public function mvcViewEngineVoltCompilerCompileStringExecuted(IntegrationTester
$I->assertSame($expected, $actual);

// Style executed in code
$this->tag->style()->reset();
$expected = '+<link rel="stylesheet" type="text/css" href="/css/some.css" media="screen" />'
. PHP_EOL
. '+<link rel="stylesheet" type="text/css" href="/css/other.css" media="screen" />'
Expand All @@ -186,6 +187,7 @@ public function mvcViewEngineVoltCompilerCompileStringExecuted(IntegrationTester
$I->assertSame($expected, $actual);

// Style after volt parsing
$this->tag->style()->reset();
$code = 'echo $this->tag->style("+")->add("/css/some.css")->add("/css/other.css");';
$expected = '+<link rel="stylesheet" type="text/css" href="/css/some.css" media="screen" />'
. PHP_EOL
Expand All @@ -210,10 +212,12 @@ public function mvcViewEngineVoltCompilerCompileStringExecuted(IntegrationTester
. PHP_EOL
. '+<script type="application/javascript" src="/js/other.js"></script>'
. PHP_EOL;
$this->tag->script()->reset();
$actual = (string) $this->tag->script('+')->add('/js/some.js')->add('/js/other.js');
$I->assertSame($expected, $actual);

// Script after volt parsing
$this->tag->script()->reset();
$code = 'echo $this->tag->script("+")->add("/js/some.js")->add("/js/other.js");';
$expected = '+<script type="application/javascript" src="/js/some.js"></script>'
. PHP_EOL
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/Html/Helper/Link/UnderscoreInvokeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,58 @@ public function htmlHelperLinkUnderscoreInvoke(UnitTester $I, Example $example)
$I->assertSame($expected, $actual);
}

/**
* Tests Phalcon\Html\Helper\Link :: __invoke() - reset
*
* @param UnitTester $I
*
* @author Phalcon Team <team@phalcon.io>
* @since 2023-10-24
*/
public function htmlHelperLinkUnderscoreInvokeReset(UnitTester $I)
{
$I->wantToTest('Html\Helper\Link - __invoke() - reset');

$escaper = new Escaper();
$helper = new Link($escaper);

$helper
->add(
'https://phalcon.io/page/1',
['rel' => 'prev']
)
;

$expected = " <link rel=\"prev\" href=\"https://phalcon.io/page/1\" />" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);

$helper
->add(
'https://phalcon.io/page/2',
['rel' => 'next']
)
;

$expected = " <link rel=\"prev\" href=\"https://phalcon.io/page/1\" />" . PHP_EOL
. " <link rel=\"next\" href=\"https://phalcon.io/page/2\" />" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);

$helper->reset();

$helper
->add(
'https://phalcon.io/page/2',
['rel' => 'next']
)
;

$expected = " <link rel=\"next\" href=\"https://phalcon.io/page/2\" />" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);
}

/**
* @return array
*/
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/Html/Helper/Meta/UnderscoreInvokeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ public function htmlHelperMetaUnderscoreInvoke(UnitTester $I, Example $example)
$I->assertSame($expected, $actual);
}

/**
* Tests Phalcon\Html\Helper\Meta :: __invoke() - reset
*
* @param UnitTester $I
*
* @throws Exception
*
* @author Phalcon Team <team@phalcon.io>
* @since 2023-10-24
*/
public function htmlHelperMetaUnderscoreInvokeReset(UnitTester $I)
{
$I->wantToTest('Html\Helper\Meta - __invoke() - reset');

$escaper = new Escaper();
$helper = new Meta($escaper);
$helper
->add(['charset' => 'utf-8'])
->addName('generator', 'Phalcon')
;

$expected = " <meta charset=\"utf-8\">" . PHP_EOL
. " <meta name=\"generator\" content=\"Phalcon\">" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);

$helper->reset();

$helper->addName('generator', 'Phalcon Team');
$expected = " <meta name=\"generator\" content=\"Phalcon Team\">" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);
}

/**
* @return array
*/
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/Html/Helper/Style/UnderscoreInvokeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,48 @@ public function htmlHelperStyleUnderscoreInvoke(UnitTester $I, Example $example)
$I->assertSame($expected, $actual);
}

/**
* Tests Phalcon\Html\Helper\Style :: __invoke() - reset
*
* @param UnitTester $I
*
* @throws Exception
*
* @author Phalcon Team <team@phalcon.io>
* @since 2023-10-24
*/
public function htmlHelperStyleUnderscoreInvokeReset(UnitTester $I)
{
$I->wantToTest('Html\Helper\Style - __invoke() - reset');

$escaper = new Escaper();
$helper = new Style($escaper);
$helper->add('custom.css');

$expected = " <link rel=\"stylesheet\" type=\"text/css\" "
. "href=\"custom.css\" media=\"screen\" />" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);

$helper->add('print.css', ['media' => 'print']);

$expected = " <link rel=\"stylesheet\" type=\"text/css\" "
. "href=\"custom.css\" media=\"screen\" />" . PHP_EOL
. " <link rel=\"stylesheet\" type=\"text/css\" "
. "href=\"print.css\" media=\"print\" />" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);

$helper->reset();

$helper->add('print.css', ['media' => 'print']);

$expected = " <link rel=\"stylesheet\" type=\"text/css\" "
. "href=\"print.css\" media=\"print\" />" . PHP_EOL;
$actual = (string)$helper;
$I->assertSame($expected, $actual);
}

/**
* @return array
*/
Expand Down

0 comments on commit 24d225d

Please sign in to comment.