Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

testIsAdminRouteReturnsFalseWhenPreviewUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Tests\Helper;
4
5
use Kunstmaan\AdminBundle\Helper\AdminRouteHelper;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\HttpFoundation\Request;
8
use Kunstmaan\NodeBundle\Router\SlugRouter;
9
use Symfony\Component\HttpFoundation\RequestStack;
10
11
class AdminRouteHelperTest extends TestCase
12
{
13
    protected static $ADMIN_KEY = 'admin';
14
15
    protected static $ALTERNATIVE_ADMIN_KEY = 'vip';
16
17
    protected static $NON_ADMIN_URL = '/en/some_path/%s/nodes';
18
19
    protected static $ADMIN_URL = '/en/%s/nodes';
20
21
    protected static $PREVIEW_ADMIN_URL = '/en/%s/preview/blog/page/1';
22
23
    /**
24
     * @covers \Kunstmaan\AdminBundle\Helper\AdminRouteHelper::isAdminRoute
25
     */
26 View Code Duplication
    public function testIsAdminRouteReturnsTrueWhenAdminUrl()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $adminRouteHelper = $this->getAdminRouteHelper(self::$ADMIN_KEY);
29
        $result = $adminRouteHelper->isAdminRoute(sprintf(self::$ADMIN_URL, self::$ADMIN_KEY));
30
        $this->assertTrue($result);
31
32
        $adminRouteHelper = $this->getAdminRouteHelper(self::$ALTERNATIVE_ADMIN_KEY);
33
        $result = $adminRouteHelper->isAdminRoute(sprintf(self::$ADMIN_URL, self::$ALTERNATIVE_ADMIN_KEY));
34
        $this->assertTrue($result);
35
    }
36
37
    /**
38
     * @covers \Kunstmaan\AdminBundle\Helper\AdminRouteHelper::isAdminRoute
39
     */
40 View Code Duplication
    public function testIsAdminRouteReturnsFalseWhenFrontendUrl()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $adminRouteHelper = $this->getAdminRouteHelper(self::$ADMIN_KEY);
43
        $result = $adminRouteHelper->isAdminRoute(sprintf(self::$NON_ADMIN_URL, self::$ADMIN_KEY));
44
        $this->assertFalse($result);
45
46
        $adminRouteHelper = $this->getAdminRouteHelper(self::$ALTERNATIVE_ADMIN_KEY);
47
        $result = $adminRouteHelper->isAdminRoute(sprintf(self::$NON_ADMIN_URL, self::$ALTERNATIVE_ADMIN_KEY));
48
        $this->assertFalse($result);
49
    }
50
51
    /**
52
     * @covers \Kunstmaan\AdminBundle\Helper\AdminRouteHelper::isAdminRoute
53
     */
54
    public function testIsAdminRouteReturnsFalseWhenPreviewUrl()
55
    {
56
        $requestStack = new RequestStack();
57
        $requestStack->push($this->getPreviewRequest());
58
59
        $adminRouteHelper = new AdminRouteHelper(self::$ADMIN_KEY, $requestStack);
60
        $result = $adminRouteHelper->isAdminRoute(sprintf(self::$PREVIEW_ADMIN_URL, self::$ADMIN_KEY));
61
        $this->assertFalse($result);
62
63
        $adminRouteHelper = new AdminRouteHelper(self::$ALTERNATIVE_ADMIN_KEY, $requestStack);
64
        $result = $adminRouteHelper->isAdminRoute(sprintf(self::$PREVIEW_ADMIN_URL, self::$ALTERNATIVE_ADMIN_KEY));
65
        $this->assertFalse($result);
66
    }
67
68
    private function getAdminRouteHelper($adminKey)
69
    {
70
        return new AdminRouteHelper($adminKey, $this->getRequestStack());
71
    }
72
73
    private function getRequestStack()
74
    {
75
        $requestStack = new RequestStack();
76
        $requestStack->push($this->getRequest());
77
78
        return $requestStack;
79
    }
80
81
    private function getRequest()
82
    {
83
        return Request::create('http://domain.tld/');
84
    }
85
86
    private function getPreviewRequest()
87
    {
88
        return Request::create('http://domain.tld/', 'GET', array('_route' => SlugRouter::$SLUG_PREVIEW));
89
    }
90
}
91