function LinkSeparateFormatterDisplayTest::getTestCases

1 call to LinkSeparateFormatterDisplayTest::getTestCases()
LinkSeparateFormatterDisplayTest::testLinkSeparateFormatter in core/modules/link/tests/src/Kernel/LinkSeparateFormatterDisplayTest.php
Tests that links are rendered correctly.

File

core/modules/link/tests/src/Kernel/LinkSeparateFormatterDisplayTest.php, line 95

Class

LinkSeparateFormatterDisplayTest
Tests the 'link_separate' field formatter.

Namespace

Drupal\Tests\link\Kernel

Code

protected function getTestCases() : \Generator {
    $defaultExpectedResults = [
        0 => '<div>
<a href="http://www.example.com/content/articles/archive?author=John&amp;year=2012#com">http://www.example.com/content/articles/archive?author=John&amp;year=2012#com</a>
</div>',
        1 => '<div>A very long &amp; strange example title that could break the nice layout of the site
<a href="http://www.example.org/content/articles/archive?author=John&amp;year=2012#org">http://www.example.org/content/articles/archive?author=John&amp;year=2012#org</a>
</div>',
        2 => '<div>Fragment only
<a href="#net">#net</a>
</div>',
        3 => '<div>
<a href="?a%5B0%5D=1&amp;a%5B1%5D=2">?a%5B0%5D=1&amp;a%5B1%5D=2</a>
</div>',
        4 => '<div>
<a href="?b%5B0%5D=1&amp;b%5B1%5D=2">?b%5B0%5D=1&amp;b%5B1%5D=2</a>
</div>',
        16 => '<div>
<a href="?b%5B0%5D=9&amp;b%5B1%5D=8">?b%5B0%5D=9&amp;b%5B1%5D=8</a>
</div>',
        5 => '<div>
<a href="?c%5B0%5D=1&amp;c%5B1%5D=2&amp;d=3">?c%5B0%5D=1&amp;c%5B1%5D=2&amp;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>Title, no link
<a href=""></a>
</div>',
        12 => '<div>
<span></span>
</div>',
        13 => '<div>Title, no link
<span></span>
</div>',
        14 => '<div>
<button type="button"></button>
</div>',
        15 => '<div>Title, button
<button type="button"></button>
</div>',
    ];
    (yield 'default settings' => [
        'display settings' => [],
        'expected_results' => $defaultExpectedResults,
    ]);
    (yield 'trim_length=null' => [
        'display_settings' => [
            'trim_length' => NULL,
        ],
        'expected_results' => $defaultExpectedResults,
    ]);
    (yield 'trim_length=6' => [
        'display settings' => [
            'trim_length' => 6,
        ],
        'expected_results' => [
            0 => '<div>
<a href="http://www.example.com/content/articles/archive?author=John&amp;year=2012#com">http:…</a>
</div>',
            1 => '<div>A ver…
<a href="http://www.example.org/content/articles/archive?author=John&amp;year=2012#org">http:…</a>
</div>',
            2 => '<div>Fragm…
<a href="#net">#net</a>
</div>',
            3 => '<div>
<a href="?a%5B0%5D=1&amp;a%5B1%5D=2">?a%5B…</a>
</div>',
            4 => '<div>
<a href="?b%5B0%5D=1&amp;b%5B1%5D=2">?b%5B…</a>
</div>',
            16 => '<div>
<a href="?b%5B0%5D=9&amp;b%5B1%5D=8">?b%5B…</a>
</div>',
            5 => '<div>
<a href="?c%5B0%5D=1&amp;c%5B1%5D=2&amp;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>Title…
<a href=""></a>
</div>',
            12 => '<div>
<span></span>
</div>',
            13 => '<div>Title…
<span></span>
</div>',
            14 => '<div>
<button type="button"></button>
</div>',
            15 => '<div>Title…
<button type="button"></button>
</div>',
        ],
    ]);
    (yield 'attribute rel=null' => [
        'display_settings' => [
            'rel' => NULL,
        ],
        'expected_results' => $defaultExpectedResults,
    ]);
    (yield 'attribute rel=nofollow' => [
        'display_settings' => [
            'rel' => 'nofollow',
        ],
        'expected_results' => [
            0 => '<div>
<a href="http://www.example.com/content/articles/archive?author=John&amp;year=2012#com" rel="nofollow">http://www.example.com/content/articles/archive?author=John&amp;year=2012#com</a>
</div>',
            1 => '<div>A very long &amp; strange example title that could break the nice layout of the site
<a href="http://www.example.org/content/articles/archive?author=John&amp;year=2012#org" rel="nofollow">http://www.example.org/content/articles/archive?author=John&amp;year=2012#org</a>
</div>',
            2 => '<div>Fragment only
<a href="#net" rel="nofollow">#net</a>
</div>',
            3 => '<div>
<a href="?a%5B0%5D=1&amp;a%5B1%5D=2" rel="nofollow">?a%5B0%5D=1&amp;a%5B1%5D=2</a>
</div>',
            4 => '<div>
<a href="?b%5B0%5D=1&amp;b%5B1%5D=2" rel="nofollow">?b%5B0%5D=1&amp;b%5B1%5D=2</a>
</div>',
            16 => '<div>
<a href="?b%5B0%5D=9&amp;b%5B1%5D=8" rel="nofollow">?b%5B0%5D=9&amp;b%5B1%5D=8</a>
</div>',
            5 => '<div>
<a href="?c%5B0%5D=1&amp;c%5B1%5D=2&amp;d=3" rel="nofollow">?c%5B0%5D=1&amp;c%5B1%5D=2&amp;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>Title, no link
<a href="" rel="nofollow"></a>
</div>',
            12 => '<div>
<span rel="nofollow"></span>
</div>',
            13 => '<div>Title, no link
<span rel="nofollow"></span>
</div>',
            14 => '<div>
<button rel="nofollow" type="button"></button>
</div>',
            15 => '<div>Title, button
<button rel="nofollow" type="button"></button>
</div>',
        ],
    ]);
    (yield 'attribute target=null' => [
        'display_settings' => [
            'target' => NULL,
        ],
        'expected_results' => $defaultExpectedResults,
    ]);
    (yield 'attribute target=_blank' => [
        'display_settings' => [
            'target' => '_blank',
        ],
        'expected_results' => [
            0 => '<div>
<a href="http://www.example.com/content/articles/archive?author=John&amp;year=2012#com" target="_blank">http://www.example.com/content/articles/archive?author=John&amp;year=2012#com</a>
</div>',
            1 => '<div>A very long &amp; strange example title that could break the nice layout of the site
<a href="http://www.example.org/content/articles/archive?author=John&amp;year=2012#org" target="_blank">http://www.example.org/content/articles/archive?author=John&amp;year=2012#org</a>
</div>',
            2 => '<div>Fragment only
<a href="#net" target="_blank">#net</a>
</div>',
            3 => '<div>
<a href="?a%5B0%5D=1&amp;a%5B1%5D=2" target="_blank">?a%5B0%5D=1&amp;a%5B1%5D=2</a>
</div>',
            4 => '<div>
<a href="?b%5B0%5D=1&amp;b%5B1%5D=2" target="_blank">?b%5B0%5D=1&amp;b%5B1%5D=2</a>
</div>',
            16 => '<div>
<a href="?b%5B0%5D=9&amp;b%5B1%5D=8" target="_blank">?b%5B0%5D=9&amp;b%5B1%5D=8</a>
</div>',
            5 => '<div>
<a href="?c%5B0%5D=1&amp;c%5B1%5D=2&amp;d=3" target="_blank">?c%5B0%5D=1&amp;c%5B1%5D=2&amp;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>Title, no link
<a href="" target="_blank"></a>
</div>',
            12 => '<div>
<span target="_blank"></span>
</div>',
            13 => '<div>Title, no link
<span target="_blank"></span>
</div>',
            14 => '<div>
<button target="_blank" type="button"></button>
</div>',
            15 => '<div>Title, button
<button target="_blank" type="button"></button>
</div>',
        ],
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.