1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Menu\Tests; |
4
|
|
|
|
5
|
|
|
use Faker\Factory; |
6
|
|
|
use Illuminate\Contracts\Console\Kernel; |
7
|
|
|
use Illuminate\Database\Eloquent\Model; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
use Maatwebsite\Sidebar\SidebarServiceProvider; |
10
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
11
|
|
|
use Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider; |
12
|
|
|
use Modules\Core\Providers\CoreServiceProvider; |
13
|
|
|
use Modules\Menu\Providers\MenuServiceProvider; |
14
|
|
|
use Modules\Menu\Repositories\MenuItemRepository; |
15
|
|
|
use Modules\Menu\Repositories\MenuRepository; |
16
|
|
|
use Modules\Page\Providers\PageServiceProvider; |
17
|
|
|
use Modules\Tag\Providers\TagServiceProvider; |
18
|
|
|
use Nwidart\Modules\LaravelModulesServiceProvider; |
19
|
|
|
use Orchestra\Testbench\TestCase; |
20
|
|
|
|
21
|
|
|
abstract class BaseMenuTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var MenuRepository |
25
|
|
|
*/ |
26
|
|
|
protected $menu; |
27
|
|
|
/** |
28
|
|
|
* @var MenuItemRepository |
29
|
|
|
*/ |
30
|
|
|
protected $menuItem; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* |
34
|
|
|
*/ |
35
|
|
|
public function setUp() |
36
|
|
|
{ |
37
|
|
|
parent::setUp(); |
38
|
|
|
|
39
|
|
|
$this->resetDatabase(); |
40
|
|
|
|
41
|
|
|
$this->menu = app(MenuRepository::class); |
42
|
|
|
$this->menuItem = app(MenuItemRepository::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getPackageProviders($app) |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
LaravelModulesServiceProvider::class, |
49
|
|
|
CoreServiceProvider::class, |
50
|
|
|
TagServiceProvider::class, |
51
|
|
|
PageServiceProvider::class, |
52
|
|
|
MenuServiceProvider::class, |
53
|
|
|
LaravelLocalizationServiceProvider::class, |
54
|
|
|
SidebarServiceProvider::class, |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function getPackageAliases($app) |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
'Eloquent' => Model::class, |
62
|
|
|
'LaravelLocalization' => LaravelLocalization::class, |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function getEnvironmentSetUp($app) |
67
|
|
|
{ |
68
|
|
|
$app['path.base'] = __DIR__ . '/..'; |
69
|
|
|
$app['config']->set('database.default', 'sqlite'); |
70
|
|
|
$app['config']->set('database.connections.sqlite', array( |
71
|
|
|
'driver' => 'sqlite', |
72
|
|
|
'database' => ':memory:', |
73
|
|
|
'prefix' => '', |
74
|
|
|
)); |
75
|
|
|
$app['config']->set('translatable.locales', ['en', 'fr']); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function resetDatabase() |
79
|
|
|
{ |
80
|
|
|
// Relative to the testbench app folder: vendors/orchestra/testbench/src/fixture |
81
|
|
|
$migrationsPath = 'Database/Migrations'; |
82
|
|
|
// Makes sure the migrations table is created |
83
|
|
|
$this->artisan('migrate', [ |
84
|
|
|
'--database' => 'sqlite', |
85
|
|
|
'--path' => $migrationsPath, |
86
|
|
|
]); |
87
|
|
|
// We empty all tables |
88
|
|
|
$this->artisan('migrate:reset', [ |
89
|
|
|
'--database' => 'sqlite', |
90
|
|
|
]); |
91
|
|
|
// Migrate |
92
|
|
|
$this->artisan('migrate', [ |
93
|
|
|
'--database' => 'sqlite', |
94
|
|
|
'--path' => $migrationsPath, |
95
|
|
|
]); |
96
|
|
|
$this->artisan('migrate', [ |
97
|
|
|
'--database' => 'sqlite', |
98
|
|
|
'--path' => 'Modules/Page/Database/Migrations', |
99
|
|
|
]); |
100
|
|
|
$this->artisan('migrate', [ |
101
|
|
|
'--database' => 'sqlite', |
102
|
|
|
'--path' => 'Modules/Tag/Database/Migrations', |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function createMenu($name, $title) |
107
|
|
|
{ |
108
|
|
|
$data = [ |
109
|
|
|
'name' => $name, |
110
|
|
|
'primary' => true, |
111
|
|
|
'en' => [ |
112
|
|
|
'title' => $title, |
113
|
|
|
'status' => 1, |
114
|
|
|
], |
115
|
|
|
]; |
116
|
|
|
|
117
|
|
|
return $this->menu->create($data); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Create a menu item for the given menu and position |
122
|
|
|
* |
123
|
|
|
* @param int $menuId |
124
|
|
|
* @param int $position |
125
|
|
|
* @param null $parentId |
126
|
|
|
* @return object |
127
|
|
|
*/ |
128
|
|
|
protected function createMenuItemForMenu($menuId, $position, $parentId = null) |
129
|
|
|
{ |
130
|
|
|
$faker = Factory::create(); |
131
|
|
|
|
132
|
|
|
$title = implode(' ', $faker->words(3)); |
133
|
|
|
$slug = Str::slug($title); |
134
|
|
|
|
135
|
|
|
$data = [ |
136
|
|
|
'menu_id' => $menuId, |
137
|
|
|
'position' => $position, |
138
|
|
|
'parent_id' => $parentId, |
139
|
|
|
'target' => '_self', |
140
|
|
|
'module_name' => 'blog', |
141
|
|
|
'en' => [ |
142
|
|
|
'status' => 1, |
143
|
|
|
'title' => $title, |
144
|
|
|
'uri' => $slug, |
145
|
|
|
], |
146
|
|
|
'fr' => [ |
147
|
|
|
'status' => 1, |
148
|
|
|
'title' => $title, |
149
|
|
|
'uri' => $slug, |
150
|
|
|
], |
151
|
|
|
]; |
152
|
|
|
|
153
|
|
|
return $this->menuItem->create($data); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|