Passed
Push — master ( a91c75...3d6eb6 )
by Caen
03:47 queued 12s
created

HyperlinksTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 37
rs 10
c 2
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A test_image_helper_resolves_paths_for_nested_pages() 0 12 2
A test_image_helper_gets_relative_web_link_to_image_stored_in_site_media_folder() 0 11 2
1
<?php
2
3
namespace Hyde\Framework\Testing\Feature\Foundation;
4
5
use Hyde\Framework\Foundation\Hyperlinks;
6
use Hyde\Framework\HydeKernel;
7
use Hyde\Testing\TestCase;
8
9
/**
10
 * @covers \Hyde\Framework\Foundation\Hyperlinks
11
 */
12
class HyperlinksTest extends TestCase
13
{
14
    protected Hyperlinks $class;
15
16
    protected function setUp(): void
17
    {
18
        parent::setUp();
19
20
        $this->class = new Hyperlinks(HydeKernel::getInstance());
21
    }
22
23
    public function test_image_helper_gets_relative_web_link_to_image_stored_in_site_media_folder()
24
    {
25
        $tests = [
26
            'test.jpg' => 'media/test.jpg',
27
            'foo' => 'media/foo',
28
            'http://example.com/test.jpg' => 'http://example.com/test.jpg',
29
            'https://example.com/test.jpg' => 'https://example.com/test.jpg',
30
        ];
31
32
        foreach ($tests as $input => $expected) {
33
            $this->assertEquals($this->class->image($input), $expected);
34
        }
35
    }
36
37
    public function test_image_helper_resolves_paths_for_nested_pages()
38
    {
39
        $tests = [
40
            'test.jpg' => '../media/test.jpg',
41
            'foo' => '../media/foo',
42
            'http://example.com/test.jpg' => 'http://example.com/test.jpg',
43
            'https://example.com/test.jpg' => 'https://example.com/test.jpg',
44
        ];
45
46
        foreach ($tests as $input => $expected) {
47
            $this->mockCurrentPage('foo/bar');
48
            $this->assertEquals($this->class->image($input), $expected);
49
        }
50
    }
51
}
52