Completed
Push — master ( c73837...66cd91 )
by Gabriel
01:54
created

SectionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 20
c 2
b 0
f 1
dl 0
loc 41
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_visibleIn() 0 7 1
A test_printIcon() 0 8 1
A test_getURL() 0 6 1
A initRequest() 0 11 1
1
<?php
2
3
namespace Nip\Mvc\Tests\Sections;
4
5
use Nip\Container\Container;
6
use Nip\Mvc\Sections\Section;
7
use Nip\Mvc\Tests\AbstractTest;
8
9
/**
10
 * Class SectionTest
11
 * @package Nip\Mvc\Tests\Sections
12
 */
13
class SectionTest extends AbstractTest
14
{
15
    public function test_visibleIn()
16
    {
17
        $section = new Section();
18
        $section->writeData(['visibleIn' => ['admin']]);
19
20
        self::assertTrue($section->visibleIn('admin'));
21
        self::assertFalse($section->visibleIn('frontend'));
22
    }
23
24
    public function test_printIcon()
25
    {
26
        $section = new Section();
27
        $section->writeData(['icon' => '<path class="fil0" d="M512 402l0 110" >']);
28
29
        self::assertSame(
30
            '<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"  focusable="false" aria-hidden="true" role="presentation"><path class="fil0" d="M512 402l0 110" ></svg>',
31
            $section->printIcon()
32
        );
33
    }
34
35
    public function test_getURL()
36
    {
37
        $this->initRequest();
38
        $section = new Section();
39
40
        self::assertSame('http://mydomain.com/subfolder', $section->getURL());
41
    }
42
43
    protected function initRequest()
44
    {
45
        $server = [
46
            'HTTP_HOST' => 'mydomain.com',
47
            'SCRIPT_FILENAME' => '/home/app/subfolder/index.php',
48
            'SCRIPT_NAME' => '/subfolder/index.php',
49
            'REQUEST_URI' => '/subfolder/',
50
        ];
51
        $request = new \Nip\Http\Request([], [], [], [], [], $server);
52
53
        Container::getInstance()->set('request', $request);
54
    }
55
}