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