diff --git a/src/Tag/Tag.php b/src/Tag/Tag.php index ddc9e27a..eaa19426 100644 --- a/src/Tag/Tag.php +++ b/src/Tag/Tag.php @@ -220,6 +220,26 @@ public static function create(string $tag, string $content = '', array $attribut return $voidElement . PHP_EOL . $content . ''; } + /** + * The `
` HTML element is the generic container for flow content. It has no effect on the content or layout + * until styled in some way using CSS (e.g. styling is directly applied to it, or some kind of layout model like + * Flexbox is applied to its parent element). + * + * @param array $attributes The tag attributes in terms of name-value pairs. These will be rendered as the + * attributes of the resulting tag. The values will be HTML-encoded using {@see Attributes::encode()}. + * See {@see Attributes::render()} for details on how attributes are being rendered. + * @param string $content The content of the tag. + * + * @return string The generated `
` HTML element. + * + * @link https://html.spec.whatwg.org/multipage/grouping-content.html#the-div-element + * @link https://html.spec.whatwg.org/multipage/dom.html#global-attributes + */ + public static function div(array $attributes = [], string $content = ''): string + { + return self::create('div', $content, $attributes); + } + /** * Create a closing tag. * @@ -340,6 +360,28 @@ public static function p(array $attributes = [], string $content = ''): string return self::create('p', $content, $attributes); } + /** + * The `` HTML element is a generic inline container for phrasing content, which does not inherently represent + * anything. It can be used to group elements for styling purposes (using the class or id attributes), or because + * they share attribute values, such as lang. It should be used only when no other semantic element is appropriate. + * `` is very much like a `
` element, but `
` is a block-level element whereas a `` is an + * inline element. + * + * @param array $attributes The tag attributes in terms of name-value pairs. These will be rendered as the + * attributes of the resulting tag. The values will be HTML-encoded using {@see Attributes::encode()}. + * See {@see Attributes::render()} for details on how attributes are being rendered. + * @param string $content The content of the tag. + * + * @return string The generated `` HTML element. + * + * @link https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-span-element + * @link https://html.spec.whatwg.org/multipage/dom.html#global-attributes + */ + public static function span(array $attributes = [], string $content = ''): string + { + return self::create('span', $content, $attributes); + } + /** * The `
    ` HTML element represents an unordered list of items, typically rendered as a bulleted list. * diff --git a/tests/Tag/DivTest.php b/tests/Tag/DivTest.php new file mode 100644 index 00000000..dce7ac07 --- /dev/null +++ b/tests/Tag/DivTest.php @@ -0,0 +1,35 @@ +' . PHP_EOL . '
'], + [['class' => 'class'], '', '
' . PHP_EOL . '
'], + [[], 'Content', '
' . PHP_EOL . 'Content' . PHP_EOL . '
'], + ]; + } + + /** + * @dataProvider createProvider + * + * @param array $attributes Tag attributes. + * @param string $content Tag content. + * @param string $expected Expected result. + */ + public function testCreate(array $attributes, string $content, string $expected): void + { + $assert = new Assert(); + + $assert->equalsWithoutLE($expected, Tag::div($attributes, $content)); + } +} diff --git a/tests/Tag/SpanTest.php b/tests/Tag/SpanTest.php new file mode 100644 index 00000000..d1a3fb8d --- /dev/null +++ b/tests/Tag/SpanTest.php @@ -0,0 +1,35 @@ +'], + [['class' => 'class'], '', ''], + [[], 'Content', 'Content'], + ]; + } + + /** + * @dataProvider createProvider + * + * @param array $attributes Tag attributes. + * @param string $content Tag content. + * @param string $expected Expected result. + */ + public function testCreate(array $attributes, string $content, string $expected): void + { + $assert = new Assert(); + + $assert->equalsWithoutLE($expected, Tag::span($attributes, $content)); + } +}