From bccec99fed2dbc36bf5b9d89156f43b76afc5857 Mon Sep 17 00:00:00 2001 From: Sameer Date: Sat, 16 Oct 2021 01:43:07 +0530 Subject: [PATCH 1/8] Add A::nofollow() method, Html::nofollow() method, test cases --- src/Html.php | 17 +++++++++++++++++ src/Tag/A.php | 5 +++++ tests/common/HtmlTest.php | 8 ++++++++ tests/common/Tag/ATest.php | 15 +++++++++++++++ 4 files changed, 45 insertions(+) diff --git a/src/Html.php b/src/Html.php index 6310baa8..c3378c9f 100644 --- a/src/Html.php +++ b/src/Html.php @@ -510,6 +510,23 @@ public static function mailto(string $content, ?string $mail = null, array $attr } return $tag; } + + /** + * Generates a hyperlink tag with nofollow attribute. + * + * @param string|Stringable $content The tag content. + * @param array $attributes The tag attributes in terms of name-value pairs. + * + * @psalm-param HtmlAttributes|array $attributes + * + * @see A + */ + public static function nofollow($content = '', ?string $url = null, array $attributes = []): A + { + $tag = self::a($content, $url, $attributes); + $tag = $tag->nofollow(); + return $tag; + } /** * Generates an {@see Img} tag. diff --git a/src/Tag/A.php b/src/Tag/A.php index d4545fb9..f5cbbd37 100644 --- a/src/Tag/A.php +++ b/src/Tag/A.php @@ -37,6 +37,11 @@ public function mailto(?string $mail): self return $this->href($mail === null ? null : 'mailto:' . $mail); } + public function nofollow() + { + return $this->rel('nofollow'); + } + /** * @link https://www.w3.org/TR/html52/links.html#element-attrdef-a-rel */ diff --git a/tests/common/HtmlTest.php b/tests/common/HtmlTest.php index f659f89f..e27752a4 100644 --- a/tests/common/HtmlTest.php +++ b/tests/common/HtmlTest.php @@ -204,6 +204,14 @@ public function testMailto(): void ); } + public function testNofollow(): void + { + $this->assertSame( + 'Link Text', + Html::nofollow('Link Text', 'https://example.com')->render() + ); + } + public function testImg(): void { $this->assertSame('', Html::img()->render()); diff --git a/tests/common/Tag/ATest.php b/tests/common/Tag/ATest.php index 61fbc07c..b2ccc22b 100644 --- a/tests/common/Tag/ATest.php +++ b/tests/common/Tag/ATest.php @@ -84,6 +84,21 @@ public function testRel(string $expected, ?string $rel): void $this->assertSame($expected, (string)A::tag()->rel($rel)); } + public function dataNofollow(): array + { + return [ + ['', 'nofollow'], + ]; + } + + /** + * @dataProvider dataNofollow + */ + public function testNofollow(string $expected, ?string $rel): void + { + $this->assertSame($expected, (string)A::tag()->nofollow($rel)); + } + public function dataTarget(): array { return [ From f106483630ffeb976b8c6ce61c033f59f5bb6c98 Mon Sep 17 00:00:00 2001 From: Evgeniy Zyubin Date: Fri, 15 Oct 2021 23:37:09 +0300 Subject: [PATCH 2/8] Simplify Html::nofollow() method --- src/Html.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Html.php b/src/Html.php index c3378c9f..e7df615a 100644 --- a/src/Html.php +++ b/src/Html.php @@ -524,8 +524,7 @@ public static function mailto(string $content, ?string $mail = null, array $attr public static function nofollow($content = '', ?string $url = null, array $attributes = []): A { $tag = self::a($content, $url, $attributes); - $tag = $tag->nofollow(); - return $tag; + return $tag->nofollow(); } /** From 0db0b5874a129c09f77a282d62e6cd8e31ca0840 Mon Sep 17 00:00:00 2001 From: Evgeniy Zyubin Date: Fri, 15 Oct 2021 23:41:36 +0300 Subject: [PATCH 3/8] Fix StyleCI --- src/Html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Html.php b/src/Html.php index e7df615a..c798f18b 100644 --- a/src/Html.php +++ b/src/Html.php @@ -510,7 +510,7 @@ public static function mailto(string $content, ?string $mail = null, array $attr } return $tag; } - + /** * Generates a hyperlink tag with nofollow attribute. * From b51c4dfd188a2c849994f20ede24a58311160a77 Mon Sep 17 00:00:00 2001 From: Evgeniy Zyubin Date: Fri, 15 Oct 2021 23:43:59 +0300 Subject: [PATCH 4/8] Add a return type --- src/Tag/A.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tag/A.php b/src/Tag/A.php index f5cbbd37..4f21328d 100644 --- a/src/Tag/A.php +++ b/src/Tag/A.php @@ -37,7 +37,7 @@ public function mailto(?string $mail): self return $this->href($mail === null ? null : 'mailto:' . $mail); } - public function nofollow() + public function nofollow(): self { return $this->rel('nofollow'); } From 67ab2b8520b7472ffe79689b68256eae0e816c00 Mon Sep 17 00:00:00 2001 From: Sameer Date: Sat, 16 Oct 2021 17:19:22 +0530 Subject: [PATCH 5/8] [#89] Tage A test case for nofollow method updated and related test data method removed. --- tests/common/Tag/ATest.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/tests/common/Tag/ATest.php b/tests/common/Tag/ATest.php index b2ccc22b..2acf2db2 100644 --- a/tests/common/Tag/ATest.php +++ b/tests/common/Tag/ATest.php @@ -84,19 +84,9 @@ public function testRel(string $expected, ?string $rel): void $this->assertSame($expected, (string)A::tag()->rel($rel)); } - public function dataNofollow(): array + public function testNofollow(): void { - return [ - ['', 'nofollow'], - ]; - } - - /** - * @dataProvider dataNofollow - */ - public function testNofollow(string $expected, ?string $rel): void - { - $this->assertSame($expected, (string)A::tag()->nofollow($rel)); + $this->assertSame('', (string)A::tag()->nofollow()); } public function dataTarget(): array From c333c78992ab0dbe7765582ecec109c401eda892 Mon Sep 17 00:00:00 2001 From: Sameer Date: Sat, 16 Oct 2021 17:23:00 +0530 Subject: [PATCH 6/8] [#89] Remove nofollow() from Html --- src/Html.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/Html.php b/src/Html.php index c798f18b..6310baa8 100644 --- a/src/Html.php +++ b/src/Html.php @@ -511,22 +511,6 @@ public static function mailto(string $content, ?string $mail = null, array $attr return $tag; } - /** - * Generates a hyperlink tag with nofollow attribute. - * - * @param string|Stringable $content The tag content. - * @param array $attributes The tag attributes in terms of name-value pairs. - * - * @psalm-param HtmlAttributes|array $attributes - * - * @see A - */ - public static function nofollow($content = '', ?string $url = null, array $attributes = []): A - { - $tag = self::a($content, $url, $attributes); - return $tag->nofollow(); - } - /** * Generates an {@see Img} tag. * From bcd32cbdacccbc634dec2ea36b0abd0c2d7ae300 Mon Sep 17 00:00:00 2001 From: Sameer Date: Sat, 16 Oct 2021 17:25:45 +0530 Subject: [PATCH 7/8] [#89] Remove nofollow() test case from HtmlTest --- tests/common/HtmlTest.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tests/common/HtmlTest.php b/tests/common/HtmlTest.php index e27752a4..f659f89f 100644 --- a/tests/common/HtmlTest.php +++ b/tests/common/HtmlTest.php @@ -204,14 +204,6 @@ public function testMailto(): void ); } - public function testNofollow(): void - { - $this->assertSame( - 'Link Text', - Html::nofollow('Link Text', 'https://example.com')->render() - ); - } - public function testImg(): void { $this->assertSame('', Html::img()->render()); From ec26fa01a72b5e856cec66d5d818bdd9f32c44c3 Mon Sep 17 00:00:00 2001 From: Sameer Date: Sat, 16 Oct 2021 17:28:53 +0530 Subject: [PATCH 8/8] [#89] Changelog updated --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5fad87f..08f89c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 2.1.1 under development -- no changes in this release. +- New #89: Add method `nofollow()` to the `A` tag (soodssr) ## 2.1.0 September 23, 2021