zend-blog-3-backend

Форк
0
/
ExternalLinkProcessorSpec.php 
78 строк · 2.5 Кб
1
<?php
2

3
namespace spec\App\Utils;
4

5
use App\Utils\ExternalLinkProcessor;
6
use PhpSpec\ObjectBehavior;
7

8
class ExternalLinkProcessorSpec extends ObjectBehavior
9
{
10
    public function let()
11
    {
12
        $this->beConstructedWith(['morontt.info', 'cdn.morontt.info']);
13
    }
14

15
    public function it_is_initializable()
16
    {
17
        $this->shouldHaveType(ExternalLinkProcessor::class);
18
    }
19

20
    public function it_is_internal_links()
21
    {
22
        $content = 'Test with <a href="https://morontt.info/about">Internal Link</a>';
23
        $this->upgradeLinks($content)->shouldBeNull();
24

25
        $content = <<<RAW
26
Test with <a href="https://cdn.morontt.info/info">Internal Link</a>
27
123
28
RAW;
29
        $this->upgradeLinks($content)->shouldBeNull();
30

31
        $content = 'Test with <a href="/statistika">Internal Link</a>';
32
        $this->upgradeLinks($content)->shouldBeNull();
33
    }
34

35
    public function it_is_content_without_links()
36
    {
37
        $this->upgradeLinks('Lorem ipsum')->shouldBeNull();
38
    }
39

40
    public function it_is_external_links()
41
    {
42
        $content = <<<RAW
43
Test with <a href="https://morontt.info/info">Internal Link</a>
44
And <a href="http://example.org/best-website-designs"  target="_blank">External Link</a>...
45
RAW;
46
        $pureContent = <<<RAW
47
Test with <a href="https://morontt.info/info">Internal Link</a>
48
And <a href="http://example.org/best-website-designs" target="_blank" rel="nofollow">External Link</a>...
49
RAW;
50
        $this->upgradeLinks($content)->shouldReturn($pureContent);
51
    }
52

53
    public function it_is_external_links_with_rel()
54
    {
55
        $content = <<<RAW
56
Test with <a href="https://morontt.info/about">Internal Link</a>
57
And <a href="http://example.org/one/two" rel="noopener" target="_blank">External Link</a>,
58
And <a href="http://example.org/" rel="nofollow noopener">External Link 2</a>...
59
RAW;
60
        $pureContent = <<<RAW
61
Test with <a href="https://morontt.info/about">Internal Link</a>
62
And <a href="http://example.org/one/two" rel="noopener nofollow" target="_blank">External Link</a>,
63
And <a href="http://example.org/" rel="nofollow noopener">External Link 2</a>...
64
RAW;
65
        $this->upgradeLinks($content)->shouldReturn($pureContent);
66
    }
67

68
    public function it_is_equals_before_after()
69
    {
70
        $content = 'Lorem <a href="https://validator.w3.org/feed/" target="_blank" rel="nofollow">Ipsum</a>';
71
        $this->upgradeLinks($content)->shouldBeNull();
72
    }
73

74
    public function it_is_null()
75
    {
76
        $this->upgradeLinks(null)->shouldBeNull();
77
    }
78
}
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.