Passed
Push — master ( d19b6f...b2bfd0 )
by Jonathan
02:31 queued 10s
created

ModuleManagerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
c 0
b 0
f 0
dl 0
loc 89
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMandatoryModuleActivatonCannotBeChanged() 0 26 1
A testModuleActivatonCanBeChanged() 0 39 1
A testModuleNotDefined() 0 16 1
1
<?php
2
3
namespace Uccello\Core\Tests\Feature;
4
5
use Tests\TestCase;
0 ignored issues
show
Bug introduced by
The type Tests\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Foundation\Testing\RefreshDatabase;
7
use Uccello\Core\Models\User;
8
use Uccello\Core\Models\Domain;
9
10
class ModuleManagerTest extends TestCase
11
{
12
    use RefreshDatabase;
13
14
    public function testModuleActivatonCanBeChanged()
15
    {
16
        $user = User::where('is_admin', 1)->first();
17
        $this->actingAs($user);
18
19
        $domain = Domain::first();
20
21
        // Create fake module
22
        $module = factory(\Uccello\Core\Models\Module::class)->create();
23
        $moduleName = $module->name;
24
25
        $url = ucroute('uccello.settings.module.activation', $domain);
26
27
        // Deactivate module
28
        $response = $this->post($url, [
29
            'src_module' => $moduleName,
30
            'active' => 0
31
        ]);
32
33
        // Test response content
34
        $response->assertJson(['success' => true, 'message' => uctrans('message.module_deactivated', ucmodule('settings'))]);
35
36
        // Activation status wash changed
37
        $module = $module->refresh();
38
        $this->assertFalse($module->isActiveOnDomain($domain));
39
40
41
        // Activate module
42
        $response = $this->json('POST', $url, [
43
            'src_module' => $moduleName,
44
            'active' => 1
45
        ]);
46
47
        // Test response content
48
        $response->assertJson(['success' => true, 'message' => uctrans('message.module_activated', ucmodule('settings'))]);
49
50
        // Test if activation status was changed
51
        $module = $module->refresh();
52
        $this->assertTrue($module->isActiveOnDomain($domain));
53
    }
54
55
    public function testMandatoryModuleActivatonCannotBeChanged()
56
    {
57
        $user = User::where('is_admin', 1)->first();
58
        $this->actingAs($user);
59
60
        $domain = Domain::first();
61
62
        $moduleName = 'settings';
63
        $module = ucmodule($moduleName);
64
65
        $this->assertTrue($module->isMandatory());
66
67
        $url = ucroute('uccello.settings.module.activation', $domain);
68
69
        // Try to deactivate module
70
        $response = $this->json('POST', $url, [
71
            'src_module' => $moduleName,
72
            'active' => 0
73
        ]);
74
75
        // Test response content
76
        $response->assertJson(['success' => false, 'error' => uctrans('error.module_is_mandatory', ucmodule('settings'))]);
77
78
        // Test if activation status was not changed
79
        $module = $module->refresh();
80
        $this->assertTrue($module->isActiveOnDomain($domain));
81
    }
82
83
    public function testModuleNotDefined()
84
    {
85
        $user = User::where('is_admin', 1)->first();
86
        $this->actingAs($user);
87
88
        $domain = Domain::first();
89
90
        $url = ucroute('uccello.settings.module.activation', $domain);
91
92
        // Try to deactivate module
93
        $response = $this->json('POST', $url, [
94
            'active' => 0
95
        ]);
96
97
        // Test response content
98
        $response->assertJson(['success' => false, 'error' => uctrans('error.module_not_defined', ucmodule('settings'))]);
99
    }
100
}
101