|
1
|
|
|
<?php namespace Nwidart\Modules\Tests; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
4
|
|
|
use Nwidart\Modules\Collection; |
|
5
|
|
|
use Nwidart\Modules\Exceptions\ModuleNotFoundException; |
|
6
|
|
|
use Nwidart\Modules\Module; |
|
7
|
|
|
use Nwidart\Modules\Repository; |
|
8
|
|
|
|
|
9
|
|
|
class RepositoryTest extends BaseTestCase |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var Repository |
|
13
|
|
|
*/ |
|
14
|
|
|
private $repository; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
parent::setUp(); |
|
19
|
|
|
$this->repository = new Repository($this->app); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** @test */ |
|
23
|
|
|
public function it_adds_location_to_paths() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->repository->addLocation('some/path'); |
|
26
|
|
|
$this->repository->addPath('some/other/path'); |
|
27
|
|
|
|
|
28
|
|
|
$paths = $this->repository->getPaths(); |
|
29
|
|
|
$this->assertCount(2, $paths); |
|
30
|
|
|
$this->assertEquals('some/path', $paths[0]); |
|
31
|
|
|
$this->assertEquals('some/other/path', $paths[1]); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** @test */ |
|
35
|
|
|
public function it_returns_a_collection() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs'); |
|
38
|
|
|
|
|
39
|
|
|
$this->assertInstanceOf(Collection::class, $this->repository->toCollection()); |
|
40
|
|
|
$this->assertInstanceOf(Collection::class, $this->repository->collections()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** @test */ |
|
44
|
|
|
public function it_returns_all_enabled_modules() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs'); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertCount(1, $this->repository->getByStatus(1)); |
|
49
|
|
|
$this->assertCount(1, $this->repository->enabled()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** @test */ |
|
53
|
|
|
public function it_returns_all_disabled_modules() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs'); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertCount(0, $this->repository->getByStatus(0)); |
|
58
|
|
|
$this->assertCount(0, $this->repository->disabled()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** @test */ |
|
62
|
|
|
public function it_counts_all_modules() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs'); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEquals(1, $this->repository->count()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** @test */ |
|
70
|
|
|
public function it_finds_a_module() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs/Recipe'); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertInstanceOf(Module::class, $this->repository->find('recipe')); |
|
75
|
|
|
$this->assertInstanceOf(Module::class, $this->repository->get('recipe')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** @test */ |
|
79
|
|
|
public function it_find_or_fail_throws_exception_if_module_not_found() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->setExpectedException(ModuleNotFoundException::class); |
|
82
|
|
|
|
|
83
|
|
|
$this->repository->findOrFail('something'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** @test */ |
|
87
|
|
|
public function it_finds_the_module_asset_path() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs/Recipe'); |
|
90
|
|
|
$assetPath = $this->repository->assetPath('recipe'); |
|
91
|
|
|
|
|
92
|
|
|
$this->assertEquals(public_path('modules/recipe'), $assetPath); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** @test */ |
|
96
|
|
|
public function it_gets_the_used_storage_path() |
|
97
|
|
|
{ |
|
98
|
|
|
$path = $this->repository->getUsedStoragePath(); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertEquals(storage_path('app/modules/modules.used'), $path); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** @test */ |
|
104
|
|
|
public function it_sets_used_module() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs/Recipe'); |
|
107
|
|
|
|
|
108
|
|
|
$this->repository->setUsed('Recipe'); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertEquals('Recipe', $this->repository->getUsed()); |
|
111
|
|
|
$this->assertEquals('Recipe', $this->repository->getUsedNow()); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** @test */ |
|
115
|
|
|
public function it_returns_laravel_filesystem() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->assertInstanceOf(Filesystem::class, $this->repository->getFiles()); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** @test */ |
|
121
|
|
|
public function it_gets_the_assets_path() |
|
122
|
|
|
{ |
|
123
|
|
|
$this->assertEquals(public_path('modules'), $this->repository->getAssetsPath()); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** @test */ |
|
127
|
|
|
public function it_gets_a_specific_module_asset() |
|
128
|
|
|
{ |
|
129
|
|
|
$path = $this->repository->asset('recipe:test.js'); |
|
130
|
|
|
|
|
131
|
|
|
$this->assertEquals('//localhost/modules/recipe/test.js', $path); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** @test */ |
|
135
|
|
|
public function it_can_detect_if_module_is_active() |
|
136
|
|
|
{ |
|
137
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs/Recipe'); |
|
138
|
|
|
|
|
139
|
|
|
$this->assertTrue($this->repository->active('Recipe')); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** @test */ |
|
143
|
|
|
public function it_can_detect_if_module_is_inactive() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->repository->addLocation(__DIR__ . '/stubs/Recipe'); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertFalse($this->repository->notActive('Recipe')); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** @test */ |
|
151
|
|
|
public function it_can_get_and_set_the_stubs_path() |
|
152
|
|
|
{ |
|
153
|
|
|
$this->repository->setStubPath('some/stub/path'); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertEquals('some/stub/path', $this->repository->getStubPath()); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** @test */ |
|
159
|
|
|
public function it_gets_the_configured_stubs_path_if_enabled() |
|
160
|
|
|
{ |
|
161
|
|
|
$this->app['config']->set('modules.stubs.enabled', true); |
|
162
|
|
|
|
|
163
|
|
|
$this->assertEquals(base_path('vendor/nwidart/laravel-modules/src/Commands/stubs'), $this->repository->getStubPath()); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** @test */ |
|
167
|
|
|
public function it_returns_default_stub_path() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->assertNull($this->repository->getStubPath()); |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|