function LinkFormatterDisplayTest::getTestCases
1 call to LinkFormatterDisplayTest::getTestCases()
- LinkFormatterDisplayTest::testLinkFormatter in core/
modules/ link/ tests/ src/ Kernel/ LinkFormatterDisplayTest.php - Tests that links are rendered correctly.
File
-
core/
modules/ link/ tests/ src/ Kernel/ LinkFormatterDisplayTest.php, line 95
Class
- LinkFormatterDisplayTest
- Tests the default 'link' field formatter.
Namespace
Drupal\Tests\link\KernelCode
public function getTestCases() : \Generator {
$default = [
0 => '<div><a href="http://www.example.com/content/articles/archive?author=John&year=2012#com">http://www.example.com/content/articles/archive?author=John&year=2012#com</a></div>',
1 => '<div><a href="http://www.example.org/content/articles/archive?author=John&year=2012#org">A very long & strange example title that could break the nice layout of the site</a></div>',
2 => '<div><a href="#net">Fragment only</a></div>',
3 => '<div><a href="?a%5B0%5D=1&a%5B1%5D=2">?a%5B0%5D=1&a%5B1%5D=2</a></div>',
4 => '<div><a href="?b%5B0%5D=1&b%5B1%5D=2">?b%5B0%5D=1&b%5B1%5D=2</a></div>',
16 => '<div><a href="?b%5B0%5D=9&b%5B1%5D=8">?b%5B0%5D=9&b%5B1%5D=8</a></div>',
5 => '<div><a href="?c%5B0%5D=1&c%5B1%5D=2&d=3">?c%5B0%5D=1&c%5B1%5D=2&d=3</a></div>',
6 => '<div><a href="?e%5Bf%5D%5Bg%5D=h">?e%5Bf%5D%5Bg%5D=h</a></div>',
7 => '<div><a href="?i%5Bj%5Bk%5D=l">?i%5Bj%5Bk%5D=l</a></div>',
8 => '<div><a href="?x=2">?x=2</a></div>',
9 => '<div><a href="?z%5B0%5D=2">?z%5B0%5D=2</a></div>',
10 => '<div><a href=""></a></div>',
11 => '<div><a href="">Title, no link</a></div>',
12 => '<div><span></span></div>',
13 => '<div><span>Title, no link</span></div>',
14 => '<div><button type="button"></button></div>',
15 => '<div><button type="button">Title, button</button></div>',
];
(yield 'default settings' => [
'display settings' => [],
'expected_results' => $default,
]);
(yield 'trim_length=null' => [
'display_settings' => [
'trim_length' => NULL,
],
'expected_results' => $default,
]);
(yield 'trim_length=6' => [
'display settings' => [
'trim_length' => 6,
],
'expected_results' => [
0 => '<div><a href="http://www.example.com/content/articles/archive?author=John&year=2012#com">http:…</a></div>',
1 => '<div><a href="http://www.example.org/content/articles/archive?author=John&year=2012#org">A ver…</a></div>',
2 => '<div><a href="#net">Fragm…</a></div>',
3 => '<div><a href="?a%5B0%5D=1&a%5B1%5D=2">?a%5B…</a></div>',
4 => '<div><a href="?b%5B0%5D=1&b%5B1%5D=2">?b%5B…</a></div>',
16 => '<div><a href="?b%5B0%5D=9&b%5B1%5D=8">?b%5B…</a></div>',
5 => '<div><a href="?c%5B0%5D=1&c%5B1%5D=2&d=3">?c%5B…</a></div>',
6 => '<div><a href="?e%5Bf%5D%5Bg%5D=h">?e%5B…</a></div>',
7 => '<div><a href="?i%5Bj%5Bk%5D=l">?i%5B…</a></div>',
8 => '<div><a href="?x=2">?x=2</a></div>',
9 => '<div><a href="?z%5B0%5D=2">?z%5B…</a></div>',
10 => '<div><a href=""></a></div>',
11 => '<div><a href="">Title…</a></div>',
12 => '<div><span></span></div>',
13 => '<div><span>Title…</span></div>',
14 => '<div><button type="button"></button></div>',
15 => '<div><button type="button">Title…</button></div>',
],
]);
(yield 'attribute rel=null' => [
'display_settings' => [
'rel' => NULL,
],
'expected_results' => $default,
]);
(yield 'attribute rel=nofollow' => [
'display_settings' => [
'rel' => 'nofollow',
],
'expected_results' => [
0 => '<div><a href="http://www.example.com/content/articles/archive?author=John&year=2012#com" rel="nofollow">http://www.example.com/content/articles/archive?author=John&year=2012#com</a></div>',
1 => '<div><a href="http://www.example.org/content/articles/archive?author=John&year=2012#org" rel="nofollow">A very long & strange example title that could break the nice layout of the site</a></div>',
2 => '<div><a href="#net" rel="nofollow">Fragment only</a></div>',
3 => '<div><a href="?a%5B0%5D=1&a%5B1%5D=2" rel="nofollow">?a%5B0%5D=1&a%5B1%5D=2</a></div>',
4 => '<div><a href="?b%5B0%5D=1&b%5B1%5D=2" rel="nofollow">?b%5B0%5D=1&b%5B1%5D=2</a></div>',
16 => '<div><a href="?b%5B0%5D=9&b%5B1%5D=8" rel="nofollow">?b%5B0%5D=9&b%5B1%5D=8</a></div>',
5 => '<div><a href="?c%5B0%5D=1&c%5B1%5D=2&d=3" rel="nofollow">?c%5B0%5D=1&c%5B1%5D=2&d=3</a></div>',
6 => '<div><a href="?e%5Bf%5D%5Bg%5D=h" rel="nofollow">?e%5Bf%5D%5Bg%5D=h</a></div>',
7 => '<div><a href="?i%5Bj%5Bk%5D=l" rel="nofollow">?i%5Bj%5Bk%5D=l</a></div>',
8 => '<div><a href="?x=2" rel="nofollow">?x=2</a></div>',
9 => '<div><a href="?z%5B0%5D=2" rel="nofollow">?z%5B0%5D=2</a></div>',
10 => '<div><a href="" rel="nofollow"></a></div>',
11 => '<div><a href="" rel="nofollow">Title, no link</a></div>',
12 => '<div><span rel="nofollow"></span></div>',
13 => '<div><span rel="nofollow">Title, no link</span></div>',
14 => '<div><button rel="nofollow" type="button"></button></div>',
15 => '<div><button rel="nofollow" type="button">Title, button</button></div>',
],
]);
(yield 'attribute target=null' => [
'display_settings' => [
'target' => NULL,
],
'expected_results' => $default,
]);
(yield 'attribute target=_blank' => [
'display_settings' => [
'target' => '_blank',
],
'expected_results' => [
0 => '<div><a href="http://www.example.com/content/articles/archive?author=John&year=2012#com" target="_blank">http://www.example.com/content/articles/archive?author=John&year=2012#com</a></div>',
1 => '<div><a href="http://www.example.org/content/articles/archive?author=John&year=2012#org" target="_blank">A very long & strange example title that could break the nice layout of the site</a></div>',
2 => '<div><a href="#net" target="_blank">Fragment only</a></div>',
3 => '<div><a href="?a%5B0%5D=1&a%5B1%5D=2" target="_blank">?a%5B0%5D=1&a%5B1%5D=2</a></div>',
4 => '<div><a href="?b%5B0%5D=1&b%5B1%5D=2" target="_blank">?b%5B0%5D=1&b%5B1%5D=2</a></div>',
16 => '<div><a href="?b%5B0%5D=9&b%5B1%5D=8" target="_blank">?b%5B0%5D=9&b%5B1%5D=8</a></div>',
5 => '<div><a href="?c%5B0%5D=1&c%5B1%5D=2&d=3" target="_blank">?c%5B0%5D=1&c%5B1%5D=2&d=3</a></div>',
6 => '<div><a href="?e%5Bf%5D%5Bg%5D=h" target="_blank">?e%5Bf%5D%5Bg%5D=h</a></div>',
7 => '<div><a href="?i%5Bj%5Bk%5D=l" target="_blank">?i%5Bj%5Bk%5D=l</a></div>',
8 => '<div><a href="?x=2" target="_blank">?x=2</a></div>',
9 => '<div><a href="?z%5B0%5D=2" target="_blank">?z%5B0%5D=2</a></div>',
10 => '<div><a href="" target="_blank"></a></div>',
11 => '<div><a href="" target="_blank">Title, no link</a></div>',
12 => '<div><span target="_blank"></span></div>',
13 => '<div><span target="_blank">Title, no link</span></div>',
14 => '<div><button target="_blank" type="button"></button></div>',
15 => '<div><button target="_blank" type="button">Title, button</button></div>',
],
]);
(yield 'url_only=false' => [
'display_settings' => [
'url_only' => FALSE,
],
'expected_results' => $default,
]);
(yield 'url_only=true' => [
'display_settings' => [
'url_only' => TRUE,
],
'expected_results' => [
0 => '<div><a href="http://www.example.com/content/articles/archive?author=John&year=2012#com">http://www.example.com/content/articles/archive?author=John&year=2012#com</a></div>',
1 => '<div><a href="http://www.example.org/content/articles/archive?author=John&year=2012#org">http://www.example.org/content/articles/archive?author=John&year=2012#org</a></div>',
2 => '<div><a href="#net">#net</a></div>',
3 => '<div><a href="?a%5B0%5D=1&a%5B1%5D=2">?a%5B0%5D=1&a%5B1%5D=2</a></div>',
4 => '<div><a href="?b%5B0%5D=1&b%5B1%5D=2">?b%5B0%5D=1&b%5B1%5D=2</a></div>',
16 => '<div><a href="?b%5B0%5D=9&b%5B1%5D=8">?b%5B0%5D=9&b%5B1%5D=8</a></div>',
5 => '<div><a href="?c%5B0%5D=1&c%5B1%5D=2&d=3">?c%5B0%5D=1&c%5B1%5D=2&d=3</a></div>',
6 => '<div><a href="?e%5Bf%5D%5Bg%5D=h">?e%5Bf%5D%5Bg%5D=h</a></div>',
7 => '<div><a href="?i%5Bj%5Bk%5D=l">?i%5Bj%5Bk%5D=l</a></div>',
8 => '<div><a href="?x=2">?x=2</a></div>',
9 => '<div><a href="?z%5B0%5D=2">?z%5B0%5D=2</a></div>',
10 => '<div><a href=""></a></div>',
11 => '<div><a href=""></a></div>',
12 => '<div><span></span></div>',
13 => '<div><span></span></div>',
14 => '<div><button type="button"></button></div>',
15 => '<div><button type="button"></button></div>',
],
]);
(yield 'url_only=false, url_plain=true' => [
'display_settings' => [
'url_only' => FALSE,
'url_plain' => TRUE,
],
'expected_results' => $default,
]);
(yield 'url_only=true, url_plain=true' => [
'display_settings' => [
'url_only' => TRUE,
'url_plain' => TRUE,
],
'expected_results' => [
0 => '<div>http://www.example.com/content/articles/archive?author=John&year=2012#com</div>',
1 => '<div>http://www.example.org/content/articles/archive?author=John&year=2012#org</div>',
2 => '<div>#net</div>',
3 => '<div>?a%5B0%5D=1&a%5B1%5D=2</div>',
4 => '<div>?b%5B0%5D=1&b%5B1%5D=2</div>',
16 => '<div>?b%5B0%5D=9&b%5B1%5D=8</div>',
5 => '<div>?c%5B0%5D=1&c%5B1%5D=2&d=3</div>',
6 => '<div>?e%5Bf%5D%5Bg%5D=h</div>',
7 => '<div>?i%5Bj%5Bk%5D=l</div>',
8 => '<div>?x=2</div>',
9 => '<div>?z%5B0%5D=2</div>',
10 => '<div></div>',
11 => '<div></div>',
12 => '<div></div>',
13 => '<div></div>',
14 => '<div></div>',
15 => '<div></div>',
],
]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.