zend-blog-3-backend
78 строк · 2.5 Кб
1<?php
2
3namespace spec\App\Utils;4
5use App\Utils\ExternalLinkProcessor;6use PhpSpec\ObjectBehavior;7
8class ExternalLinkProcessorSpec extends ObjectBehavior9{
10public function let()11{12$this->beConstructedWith(['morontt.info', 'cdn.morontt.info']);13}14
15public function it_is_initializable()16{17$this->shouldHaveType(ExternalLinkProcessor::class);18}19
20public 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 = <<<RAW26Test with <a href="https://cdn.morontt.info/info">Internal Link</a>
27123
28RAW;29$this->upgradeLinks($content)->shouldBeNull();30
31$content = 'Test with <a href="/statistika">Internal Link</a>';32$this->upgradeLinks($content)->shouldBeNull();33}34
35public function it_is_content_without_links()36{37$this->upgradeLinks('Lorem ipsum')->shouldBeNull();38}39
40public function it_is_external_links()41{42$content = <<<RAW43Test with <a href="https://morontt.info/info">Internal Link</a>
44And <a href="http://example.org/best-website-designs" target="_blank">External Link</a>...
45RAW;46$pureContent = <<<RAW47Test with <a href="https://morontt.info/info">Internal Link</a>
48And <a href="http://example.org/best-website-designs" target="_blank" rel="nofollow">External Link</a>...
49RAW;50$this->upgradeLinks($content)->shouldReturn($pureContent);51}52
53public function it_is_external_links_with_rel()54{55$content = <<<RAW56Test with <a href="https://morontt.info/about">Internal Link</a>
57And <a href="http://example.org/one/two" rel="noopener" target="_blank">External Link</a>,
58And <a href="http://example.org/" rel="nofollow noopener">External Link 2</a>...
59RAW;60$pureContent = <<<RAW61Test with <a href="https://morontt.info/about">Internal Link</a>
62And <a href="http://example.org/one/two" rel="noopener nofollow" target="_blank">External Link</a>,
63And <a href="http://example.org/" rel="nofollow noopener">External Link 2</a>...
64RAW;65$this->upgradeLinks($content)->shouldReturn($pureContent);66}67
68public 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
74public function it_is_null()75{76$this->upgradeLinks(null)->shouldBeNull();77}78}
79