Skip to content

Commit 8fb5d65

Browse files
committed
Merge branch 'integration-tests'
2 parents 22b872f + 9c71f25 commit 8fb5d65

File tree

10 files changed

+491
-79
lines changed

10 files changed

+491
-79
lines changed

classes/Collections/Elements.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ public function clearCache()
205205
}
206206

207207
/**
208-
* Clea the internal store as well as the cache, in effect totally resetting
209-
* hydration
208+
* Clear the internal store as well as the cache, in effect
209+
* totally resetting hydration
210210
*
211-
* @return $this;
211+
* @return $this
212212
*/
213-
public function empty()
213+
public function reset()
214214
{
215215
$this->items = [];
216216
$this->clearCache();

example/config/decoy/elements.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
homepage:
66
marquee:
77
title: Welcome to Decoy
8+
image,image:
9+
file,file:

example/config/decoy/site.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,21 @@
4848
'viewer' => '<b>Viewer</b> - Can only read.',
4949
],
5050

51-
/**
52-
* Permissions rules. These are described in more detail in the README.
53-
*
54-
* @var array
55-
*/
56-
'permissions' => [
57-
'viewer' => [
58-
'can' => [
59-
'read.articles',
60-
'read.admins',
61-
'manage.tags',
62-
],
63-
'cant' => [
64-
'destroy.tags',
65-
]
66-
],
67-
],
51+
/**
52+
* Permissions rules. These are described in more detail in the README.
53+
*
54+
* @var array
55+
*/
56+
'permissions' => [
57+
'viewer' => [
58+
'can' => [
59+
'manage.articles',
60+
],
61+
'cant' => [
62+
'destroy.articles',
63+
]
64+
],
65+
],
6866

6967
/**
7068
* A hash of localization slugs and readable labels for all the locales for this

example/database/factories/ModelFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Bkwld\Decoy\Models\Admin as BkwldAdmin;
4+
35
/*
46
|--------------------------------------------------------------------------
57
| Model Factories
@@ -68,3 +70,13 @@
6870
'label' => $faker->word,
6971
];
7072
});
73+
74+
$factory->define(BkwldAdmin::class, function (Faker\Generator $faker) {
75+
return [
76+
'first_name' => $faker->firstName,
77+
'last_name' => $faker->lastName,
78+
'email' => $faker->safeEmail,
79+
'password' => bcrypt(str_random(10)),
80+
'role' => 'viewer',
81+
];
82+
});

tests/Integration/AdminTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Tests\Integration;
3+
4+
use App\Article;
5+
use Tests\TestCase;
6+
use Bkwld\Decoy\Models\Admin;
7+
8+
class AdminTest extends TestCase
9+
{
10+
11+
/**
12+
* @var Article
13+
*/
14+
protected $article;
15+
16+
/**
17+
* Seed with a tag and article
18+
*
19+
* @return void
20+
*/
21+
public function setUp() {
22+
parent::setUp();
23+
$this->actingAs(Admin::create([
24+
'first_name' => 'First',
25+
'last_name' => 'Last',
26+
'email' => 'test@domain.com',
27+
'password' => 'pass',
28+
'role' => 'viewer',
29+
]), 'decoy');
30+
31+
$this->article = factory(Article::class)->create();
32+
}
33+
34+
/**
35+
* Test the admin can permissions
36+
*
37+
* @return void
38+
*/
39+
public function testAdminCanPermissions()
40+
{
41+
$response = $this->get('admin/articles/1/edit');
42+
$this->assertResponseOk();
43+
}
44+
45+
/**
46+
* Test the admin can't permissions
47+
*/
48+
public function testAdminCantPermissions()
49+
{
50+
$article = Article::first();
51+
$this->assertEquals(1, $article->id);
52+
$response = $this->get('admin/articles/1/delete');
53+
$this->assertResponseStatus(403);
54+
}
55+
56+
/**
57+
* Test the specific admin disable button for admins
58+
*
59+
* @return void
60+
*/
61+
public function testAdminDisableAdmins()
62+
{
63+
$new_admin = factory(Admin::class)->create();
64+
$this->assertEquals(2, $new_admin->id);
65+
66+
$response = $this->get('admin/admins/2/disable');
67+
$this->assertResponseStatus(403);
68+
}
69+
70+
}

tests/Integration/CrudTest.php

Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,13 @@ protected function setUp() {
2525
*/
2626
private function createData()
2727
{
28-
29-
// Create an image in the tmp directory where Upchuck is expecting it
30-
$tmp_dir = ini_get('upload_tmp_dir') ?: sys_get_temp_dir();
31-
$img_name = 'decoy-article-image.png';
32-
$img_path = $tmp_dir.'/'.$img_name;
33-
if (!file_exists($img_path)) {
34-
$img = imagecreatetruecolor(20, 20);
35-
imagepng($img, $img_path);
36-
imagedestroy($img);
37-
}
38-
39-
// Make the file record
40-
$file = new UploadedFile(
41-
$img_path,
42-
$img_name,
43-
'image/png',
44-
null,
45-
null,
46-
true
47-
);
48-
4928
return [
50-
51-
// Params
52-
[
53-
'title' => 'Example Title',
54-
'body' => 'Body',
55-
'category' => 'first',
56-
'date' => '2020-01-01',
57-
'featured' => 1,
58-
'public' => 1,
59-
'images' => [
60-
'_xxxx' => [
61-
'name' => '',
62-
],
63-
],
64-
],
65-
66-
// Files
67-
[
68-
'images' => [
69-
'_xxxx' => [
70-
'file' => $file,
71-
],
72-
],
73-
],
29+
'title' => 'Example Title',
30+
'body' => 'Body',
31+
'category' => 'first',
32+
'date' => '2020-01-01',
33+
'featured' => 1,
34+
'public' => 1,
7435
];
7536
}
7637

@@ -106,18 +67,15 @@ public function testStoreFailsValidation()
10667
*/
10768
public function testStore()
10869
{
109-
list($params, $files) = $this->createData();
110-
111-
$response = $this->call('POST', 'admin/articles/create', array_merge($params, [
70+
$response = $this->call('POST', 'admin/articles/create', array_merge($this->createData(), [
11271
'_save' => 'save',
113-
]), [], $files);
72+
]));
11473

11574
$this->assertRedirectedTo('admin/articles/1/edit');
11675

11776
$article = Article::findBySlug('example-title');
11877
$this->assertNotEmpty($article);
11978
$this->assertEquals(1, $article->position);
120-
$this->assertNotEmpty($article->img()->url);
12179
}
12280

12381
/**

tests/Integration/ElementsLocalizationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testSavedValueQuarantined()
5252
]);
5353

5454
// Clear the cache
55-
app('decoy.elements')->empty();
55+
app('decoy.elements')->reset();
5656

5757
// Test that in english, we don't see the sapnish title
5858
$element = (string) Decoy::el('homepage.marquee.title');
@@ -71,7 +71,7 @@ public function testSavedValue()
7171
]);
7272

7373
// Clear the cache
74-
app('decoy.elements')->empty();
74+
app('decoy.elements')->reset();
7575

7676
// Set to spanish adn confirm the locale scene
7777
Decoy::locale('es');

0 commit comments

Comments
 (0)