Skip to content

Commit

Permalink
Merge pull request #15867 from niden/T15866-title-separator
Browse files Browse the repository at this point in the history
T15866 title separator
  • Loading branch information
niden committed Jan 19, 2022
2 parents 8f4a413 + 03004c0 commit 1706073
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 146 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ tests/_output/*

.php_cs.cache
.env
zephir
3 changes: 3 additions & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

## Fixed
- Fixed `Phalcon\Logger\AbstractAdapter::getFormattedItem()` to not add `PHP_EOL` at the end of the message and added it to the `Phalcon\Logger\Adapter\Stream` [#14547](https://github.com/phalcon/cphalcon/issues/14547)
- Fixed `Phalcon\Html\Helper\Title:__invoke()` to not use the `$separator` as parameter - no need to redefine it in a view [#15866](https://github.com/phalcon/cphalcon/issues/15866)

## Added
- Added `Phalcon\Html\Helper\Title:setSeparator` to allow setting the separator independently [#15866](https://github.com/phalcon/cphalcon/issues/15866)

# [5.0.0beta2](https://github.com/phalcon/cphalcon/releases/tag/v5.0.0beta2) (2022-01-06)

Expand Down
20 changes: 16 additions & 4 deletions phalcon/Html/Helper/Title.zep
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,17 @@ class Title extends AbstractHelper
/**
* Sets the separator and returns the object back
*
* @param string $separator
* @param string|null $indent
* @param string|null $delimiter
*
* @return Title
*/
public function __invoke(
string separator = "",
string indent = null,
string delimiter = null
) -> <Title> {
let this->delimiter = delimiter,
this->indent = indent,
this->separator = separator;
this->indent = indent;

return this;
}
Expand Down Expand Up @@ -142,6 +139,21 @@ class Title extends AbstractHelper
return this;
}

/**
* Sets the separator
*
* @param string $separator
* @param bool $raw
*
* @return Title
*/
public function setSeparator(string separator, bool raw = false) -> <Title>
{
let this->separator = raw ? separator : this->escaper->html(separator);

return this;
}

/**
* Prepends text to current document title
*
Expand Down
29 changes: 0 additions & 29 deletions tests/_data/fixtures/Security/ExtendedBuilder.php

This file was deleted.

13 changes: 0 additions & 13 deletions tests/_data/fixtures/Traits/JWTTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Phalcon\Encryption\Security\JWT\Exceptions\ValidatorException;
use Phalcon\Encryption\Security\JWT\Signer\Hmac;
use Phalcon\Encryption\Security\JWT\Token\Token;
use Phalcon\Tests\Fixtures\Security\ExtendedBuilder;

trait JWTTrait
{
Expand All @@ -31,18 +30,6 @@ protected function newToken($signerClass = Hmac::class, int $issDrift = 0): Toke
return $this->generateToken(Builder::class, $signerClass, $issDrift);
}

/**
* @param string $signerClass
* @param int $issDrift
*
* @return Token
* @throws ValidatorException
*/
protected function newExtendedToken($signerClass = Hmac::class, int $issDrift = 0): Token
{
return $this->generateToken(ExtendedBuilder::class, $signerClass, $issDrift);
}

/**
* @param string $builderClass
* @param string $signerClass
Expand Down
81 changes: 0 additions & 81 deletions tests/integration/Session/Factory/LoadCest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/
class ValidateCest
{

/**
* Tests Phalcon\Filter\Validation\Validator\Confirmation :: validate() - single
* field
Expand All @@ -51,7 +50,6 @@ public function filterValidationValidatorConfirmationValidateSingleField(Integra
)
);


$messages = $validation->validate(
[
'name' => 'SomeValue',
Expand Down
55 changes: 38 additions & 17 deletions tests/unit/Html/Helper/Title/UnderscoreInvokeCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,67 @@ public function htmlHelperTitleUnderscoreInvoke(UnitTester $I, Example $example)
$escaper = new Escaper();
$helper = new Title($escaper);

$result = $helper($example['separator'], $example['indent'], $example['delimiter']);
$indent = $example['indent'];
$delimiter = $example['delimiter'];
$separator = $example['separator'];
$prepend = $example['prepend'];
$title = $example['title'];
$titleRaw = $example['titleRaw'];
$append = $example['append'];

if (!empty($example['prepend'])) {
foreach ($example['prepend'] as $text => $raw) {
$result = $helper($indent, $delimiter);

$result->setSeparator($separator);

if (!empty($prepend)) {
foreach ($prepend as $text => $raw) {
$result->prepend($text, $raw);
}
}

$result->set($example['title'], $example['titleRaw']);

if (!empty($example['append'])) {
foreach ($example['append'] as $text => $raw) {
$result->set($title, $titleRaw);
if (!empty($append)) {
foreach ($append as $text => $raw) {
$result->append($text, $raw);
}
}

$I->assertEquals($example['get'], $result->get());
$I->assertEquals($example['render'], (string) $result);
$expected = $example['get'];
$actual = $result->get();
$I->assertEquals($expected, $actual);

$expected = $example['render'];
$actual = (string) $result;
$I->assertEquals($expected, $actual);

$factory = new TagFactory($escaper);
$locator = $factory->newInstance('title');

$result = $locator($example['separator'], $example['indent'], $example['delimiter']);
$result = $locator($indent, $delimiter);

if (!empty($example['prepend'])) {
foreach ($example['prepend'] as $text => $raw) {
$result->setSeparator($separator);
if (!empty($prepend)) {
foreach ($prepend as $text => $raw) {
$result->prepend($text, $raw);
}
}

$result->set($example['title'], $example['titleRaw']);
$result->set($title, $titleRaw);

if (!empty($example['append'])) {
foreach ($example['append'] as $text => $raw) {
if (!empty($append)) {
foreach ($append as $text => $raw) {
$result->append($text, $raw);
}
}

$I->assertEquals($example['get'], $result->get());
$I->assertEquals($example['render'], (string) $result);

$expected = $example['get'];
$actual = $result->get();
$I->assertEquals($expected, $actual);

$expected = $example['render'];
$actual = (string) $result;
$I->assertEquals($expected, $actual);
}

/**
Expand Down

0 comments on commit 1706073

Please sign in to comment.