Skip to content
Permalink
Browse files

Html: added toText() & toHtml()

  • Loading branch information
dg committed Nov 18, 2019
1 parent 711b1ac commit b7e6205ab012c3e81167ce3866485d705cf003a9
Showing with 14 additions and 0 deletions.
  1. +12 −0 src/Utils/Html.php
  2. +2 −0 tests/Utils/Html.basic.phpt
@@ -79,6 +79,18 @@ public static function el(string $name = null, $attrs = null)
}
final public function toText(): string
{
return $this->getText();
}
final public function toHtml(): string
{
return $this->render();
}
/**
* Changes element's name.
* @return static
@@ -17,6 +17,7 @@ test(function () {
Html::$xhtml = true;
$el = Html::el('img')->src('image.gif')->alt('');
Assert::same('<img src="image.gif" alt="" />', (string) $el);
Assert::same('<img src="image.gif" alt="" />', $el->toHtml());
Assert::same('<img src="image.gif" alt="" />', $el->startTag());
Assert::same('', $el->endTag());
});
@@ -149,6 +150,7 @@ test(function () { // getText vs. getHtml
$el->create('a')->setText('link');
Assert::same('<p>Hello &ndash; World<a>link</a></p>', (string) $el);
Assert::same('Hello – Worldlink', $el->getText());
Assert::same('Hello – Worldlink', $el->toText());
});

0 comments on commit b7e6205

Please sign in to comment.
You can’t perform that action at this time.