Passed
Branch feature/6.x (4633a7)
by Schlaefer
03:28
created

AdminControllerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 50
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A AdminsControllerTest::testPhpInfoUserAllowence() 0 3 1
A AdminsControllerTest::testAdminEmptyCachesNonAdmin() 0 5 1
A AdminsControllerTest::testAdminEmptyCaches() 0 7 1
A AdminsControllerTest::testAdminEmptyCachesUser() 0 6 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Saito - The Threaded Web Forum
6
 *
7
 * @copyright Copyright (c) the Saito Project Developers
8
 * @link https://github.com/Schlaefer/Saito
9
 * @license http://opensource.org/licenses/MIT
10
 */
11
12
namespace App\Test\TestCase\Controller;
13
14
use Cake\Cache\Cache;
15
use Saito\Exception\SaitoForbiddenException;
16
use Saito\Test\IntegrationTestCase;
17
18
/**
19
 * App\Controller\ToolsController Test Case
20
 */
21
class AdminsControllerTest extends IntegrationTestCase
22
{
23
    /**
24
     * Fixtures
25
     *
26
     * @var array
27
     */
28
    public $fixtures = [
29
        'app.Category',
30
        'app.Entry',
31
        'app.Setting',
32
        'app.User',
33
        'app.UserBlock',
34
        'app.UserIgnore',
35
        'app.UserOnline',
36
        'app.UserRead',
37
    ];
38
39
    /**
40
     * testAdminEmptyCaches method
41
     *
42
     * @return void
43
     */
44
    public function testAdminEmptyCachesNonAdmin()
45
    {
46
        $url = '/admin/admins/emptyCaches';
47
        $this->get($url);
48
        $this->assertRedirectLogin($url);
49
    }
50
51
    public function testAdminEmptyCachesUser()
52
    {
53
        $this->_loginUser(2);
54
        $url = '/admin/admins/emptyCaches';
55
        $this->expectException(SaitoForbiddenException::class);
56
        $this->get($url);
57
    }
58
59
    public function testAdminEmptyCaches()
60
    {
61
        $this->_loginUser(1);
62
        Cache::write('foo', 'bar');
63
        $this->assertEquals('bar', Cache::read('foo'));
64
        $this->get('admin/admins/emptyCaches');
65
        $this->assertEmpty(Cache::read('foo'));
66
    }
67
68
    public function testPhpInfoUserAllowence()
69
    {
70
        $this->assertRouteForRole('/admin/admins/phpinfo', 'admin');
71
    }
72
}
73