Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Persistence\Post class #1974

Merged
merged 3 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/HtmlTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ public function cloneRegion(string $tag): self
protected function _unsetFromTagTree(TagTree $tagTree, int $k): void
{
\Closure::bind(function () use ($tagTree, $k) {
unset($tagTree->children[$k]);
if ($k === array_key_last($tagTree->children)) {
array_pop($tagTree->children);
} else {
unset($tagTree->children[$k]);
}
}, null, TagTree::class)();
}

Expand Down
34 changes: 0 additions & 34 deletions src/Persistence/Post.php

This file was deleted.

34 changes: 33 additions & 1 deletion tests/HtmlTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,21 @@ public function testHasTag(): void
static::assertFalse($t->hasTag(['foo', 'bar', 'non_existent_tag']));
}

public function testSetBadTypeException(): void
public function testSetInvalidUtf8Exception(): void
{
$t = new HtmlTemplate('{foo}hello{/} guys');

$this->expectException(Exception::class);
$this->expectExceptionMessage('Value is not valid UTF-8');
$t->set('foo', "\xc2");
}

public function testSetNonScalarException(): void
{
$t = new HtmlTemplate('{foo}hello{/} guys');

$this->expectException(Exception::class);
$this->expectExceptionMessage('Value must be scalar');
$t->set('foo', new \stdClass()); // @phpstan-ignore-line
}

Expand Down Expand Up @@ -125,6 +135,28 @@ public function testSetAppendDel(): void
static::assertSameTemplate('{foo}Hi and <b>welcome</b> my dear and <b>smart</b>{/} guys', $t);
}

public function testValueEncoded(): void
{
$t = new HtmlTemplate('{foo}hello{/} guys');
$tagTreeFoo = $t->getTagTree('foo');

static::assertTrue($tagTreeFoo->getChildren()[0]->isEncoded());
static::assertSame('hello', $tagTreeFoo->getChildren()[0]->getHtml());

$t->set('foo', '<br>');
static::assertFalse($tagTreeFoo->getChildren()[0]->isEncoded());
static::assertSame('&lt;br&gt;', $tagTreeFoo->getChildren()[0]->getHtml());
static::assertSame('<br>', $tagTreeFoo->getChildren()[0]->getUnencoded());

$t->dangerouslyAppendHtml('foo', '<br>');
static::assertTrue($tagTreeFoo->getChildren()[1]->isEncoded());
static::assertSame('<br>', $tagTreeFoo->getChildren()[1]->getHtml());

$this->expectException(Exception::class);
$this->expectExceptionMessage('Unencoded value is not available');
$tagTreeFoo->getChildren()[1]->getUnencoded();
}

public function testClone(): void
{
$t = new HtmlTemplate('{foo}{inner}hello{/}{/} guys');
Expand Down
51 changes: 0 additions & 51 deletions tests/PersistencePostTest.php

This file was deleted.