1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Blog\Tests; |
4
|
|
|
|
5
|
|
|
use Faker\Factory; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use Maatwebsite\Sidebar\SidebarServiceProvider; |
8
|
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
9
|
|
|
use Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider; |
10
|
|
|
use Modules\Blog\Providers\BlogServiceProvider; |
11
|
|
|
use Modules\Core\Providers\CoreServiceProvider; |
12
|
|
|
use Nwidart\Modules\LaravelModulesServiceProvider; |
13
|
|
|
use Orchestra\Testbench\TestCase; |
14
|
|
|
|
15
|
|
|
abstract class BaseBlogTestCase extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var \Modules\Blog\Repositories\PostRepository |
19
|
|
|
*/ |
20
|
|
|
protected $post; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var \Modules\Blog\Repositories\TagRepository |
24
|
|
|
*/ |
25
|
|
|
protected $tag; |
26
|
|
|
|
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
$this->resetDatabase(); |
32
|
|
|
|
33
|
|
|
$this->post = app('Modules\Blog\Repositories\PostRepository'); |
34
|
|
|
$this->tag = app('Modules\Blog\Repositories\TagRepository'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function getPackageProviders($app) |
38
|
|
|
{ |
39
|
|
|
return [ |
40
|
|
|
LaravelModulesServiceProvider::class, |
41
|
|
|
LaravelLocalizationServiceProvider::class, |
42
|
|
|
CoreServiceProvider::class, |
43
|
|
|
BlogServiceProvider::class, |
44
|
|
|
SidebarServiceProvider::class, |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function getPackageAliases($app) |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
'LaravelLocalization' => LaravelLocalization::class, |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function getEnvironmentSetUp($app) |
56
|
|
|
{ |
57
|
|
|
$app['path.base'] = __DIR__ . '/..'; |
58
|
|
|
$app['config']->set('database.default', 'sqlite'); |
59
|
|
|
$app['config']->set('database.connections.sqlite', array( |
60
|
|
|
'driver' => 'sqlite', |
61
|
|
|
'database' => ':memory:', |
62
|
|
|
'prefix' => '', |
63
|
|
|
)); |
64
|
|
|
$app['config']->set('translatable.locales', ['en', 'fr']); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Helper method to create a blog post |
69
|
|
|
* @return object |
70
|
|
|
*/ |
71
|
|
|
public function createBlogPost() |
72
|
|
|
{ |
73
|
|
|
$faker = Factory::create(); |
74
|
|
|
|
75
|
|
|
$title = implode(' ', $faker->words(3)); |
76
|
|
|
$slug = Str::slug($title); |
77
|
|
|
|
78
|
|
|
$data = [ |
79
|
|
|
'en' => [ |
80
|
|
|
'title' => $title, |
81
|
|
|
'slug' => $slug, |
82
|
|
|
'content' => $faker->paragraph(), |
83
|
|
|
], |
84
|
|
|
'fr' => [ |
85
|
|
|
'title' => $title, |
86
|
|
|
'slug' => $slug, |
87
|
|
|
'content' => $faker->paragraph(), |
88
|
|
|
], |
89
|
|
|
'category_id' => 1, |
90
|
|
|
]; |
91
|
|
|
|
92
|
|
|
return $this->post->create($data); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function createTag() |
96
|
|
|
{ |
97
|
|
|
$faker = Factory::create(); |
98
|
|
|
|
99
|
|
|
$enName = $faker->word; |
100
|
|
|
$enSlug = Str::slug($enName); |
101
|
|
|
|
102
|
|
|
$frName = $faker->word; |
103
|
|
|
$frSlug = Str::slug($enName); |
104
|
|
|
|
105
|
|
|
$data = [ |
106
|
|
|
'en' => [ |
107
|
|
|
'name' => $enName, |
108
|
|
|
'slug' => $enSlug, |
109
|
|
|
], |
110
|
|
|
'fr' => [ |
111
|
|
|
'name' => $frName, |
112
|
|
|
'slug' => $frSlug, |
113
|
|
|
], |
114
|
|
|
]; |
115
|
|
|
|
116
|
|
|
return $this->tag->create($data); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
private function resetDatabase() |
120
|
|
|
{ |
121
|
|
|
// Relative to the testbench app folder: vendors/orchestra/testbench/src/fixture |
122
|
|
|
$migrationsPath = realpath('Database/Migrations'); |
123
|
|
|
// Makes sure the migrations table is created |
124
|
|
|
$this->artisan('migrate', [ |
125
|
|
|
'--database' => 'sqlite', |
126
|
|
|
'--realpath' => $migrationsPath, |
127
|
|
|
]); |
128
|
|
|
// We empty all tables |
129
|
|
|
$this->artisan('migrate:reset', [ |
130
|
|
|
'--database' => 'sqlite', |
131
|
|
|
]); |
132
|
|
|
// Migrate |
133
|
|
|
$this->artisan('migrate', [ |
134
|
|
|
'--database' => 'sqlite', |
135
|
|
|
'--realpath' => $migrationsPath, |
136
|
|
|
]); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|