Skip to content

Commit

Permalink
Drop Persistence\Post class (#1974)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 22, 2023
1 parent 9aa0cc5 commit af72a2b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 87 deletions.
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.

0 comments on commit af72a2b

Please sign in to comment.