Permalink
Browse files
Html: added toText() & toHtml()
- Loading branch information
Showing
with
14 additions
and
0 deletions.
-
+12
−0
src/Utils/Html.php
-
+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 – World<a>link</a></p>', (string) $el); |
|
|
Assert::same('Hello – Worldlink', $el->getText()); |
|
|
Assert::same('Hello – Worldlink', $el->toText()); |
|
|
}); |
|
|
|
|
|
|
|
|
0 comments on commit
b7e6205