Skip to content

Commit

Permalink
Add users test
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro authored and ifox committed Nov 18, 2019
1 parent 28de078 commit 8bd24c2
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
|
*/

require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/helpers.php';
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/helpers.php';

use Carbon\Carbon;

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/CommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CommandsTest extends TestCase
{
public function testModuleCommand()
public function testCanExecuteModuleCommand()
{
$this->artisan('twill:module', ['moduleName' => 'Posts']);

Expand All @@ -20,7 +20,7 @@ public function testModuleCommand()
);
}

public function testBlocksCommand()
public function testCanExecuteBlocksCommand()
{
$this->deleteDirectory($path = resource_path('views/admin/blocks'));
$this->deleteDirectory(resource_path('assets/js/blocks'));
Expand Down Expand Up @@ -63,7 +63,7 @@ public function testBlocksCommand()
);
}

public function testSuperadminCommand()
public function testCanExecuteSuperadminCommand()
{
$this->artisan('twill:superadmin')
->expectsQuestion(
Expand All @@ -84,7 +84,7 @@ public function testSuperadminCommand()
);
}

public function testUpdateCommand()
public function testCanExecuteUpdateCommand()
{
$this->artisan('twill:update');

Expand Down
5 changes: 1 addition & 4 deletions tests/integration/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public function testCanRedirectToLogin()

public function testCanLogin()
{
$crawler = $this->followingRedirects()->call('POST', '/twill/login', [
'email' => $this->getSuperAdmin()->email,
'password' => $this->getSuperAdmin()->password,
]);
$crawler = $this->login();

$this->assertStringContainsString(
'Media Library',
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RoutesTest extends TestCase
'twill/users/{user}/edit',
];

public function testRoutesList()
public function testCanListAllRoutes()
{
$this->assertEquals(static::ROUTES, $this->getAllUris()->toArray());
}
Expand All @@ -66,3 +66,4 @@ public function ddRoutes()
dd($this->getAllUris()->toArray());
}
}
http: //twill.test/twill/users?sortKey=email&sortDir=asc&page=1&offset=20&columns[]=bulk&columns[]=published&columns[]=name&columns[]=email&columns[]=role_value&filter=%7B%22status%22:%22published%22%7D
77 changes: 74 additions & 3 deletions tests/integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestCase extends OrchestraTestCase
public $faker;

/**
* @var \A17\Twill\Models\User
* @var \A17\Twill\Tests\Integration\UserClass
*/
public $superAdmin;

Expand Down Expand Up @@ -234,18 +234,40 @@ public function installTwill()
);
}

/**
* Delete a directory.
*
* @param string $param
*/
public function deleteDirectory(string $param)
{
if ($this->files->exists($param)) {
$this->files->deleteDirectory($param);
}
}

public function getAllRoutes()
/**
* Get a collection with all routes.
*
* @param null $method
* @return \Illuminate\Support\Collection
*/
public function getAllRoutes($method = null)
{
return collect(Route::getRoutes());
$routes = Route::getRoutes();

if ($method) {
$routes = $routes->get($method);
}

return collect($routes);
}

/**
* Get a collection with all package uris.
*
* @return \Illuminate\Support\Collection
*/
public function getAllUris()
{
return $this->getAllRoutes()
Expand All @@ -257,6 +279,55 @@ public function getAllUris()
->unique()
->values();
}

/**
* Send request to an ajax route.
*
* @param $uri
* @param string $method
* @param array $parameters
* @param array $cookies
* @param array $files
* @param array $server
* @param null $content
* @return \Illuminate\Foundation\Testing\TestResponse
*/
public function ajax(
$uri,
$method = 'GET',
$parameters = [],
$cookies = [],
$files = [],
$server = [],
$content = null
) {
$server = array_merge($server, [
'HTTP_X-Requested-With' => 'XMLHttpRequest',
]);

return $this->call(
$method,
$uri,
$parameters,
$cookies,
$files,
$server,
$content
);
}

/**
* Login the current SuperUser.
*
* @return \Illuminate\Foundation\Testing\TestResponse|void
*/
protected function login()
{
return $this->followingRedirects()->call('POST', '/twill/login', [
'email' => $this->getSuperAdmin()->email,
'password' => $this->getSuperAdmin()->password,
]);
}
}

class UserClass
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/UsersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace A17\Twill\Tests\Integration;

class UsersTest extends TestCase
{
public function setUp(): void
{
parent::setUp();

$this->login();
}

public function testCanListUsers()
{
$crawler = $this->ajax(
'/twill/users?sortKey=email&sortDir=asc&page=1&offset=20&columns[]=bulk&columns[]=published&columns[]=name&columns[]=email&columns[]=role_value&filter=%7B%22status%22:%22published%22%7D'
);

$this->assertJson($crawler->getContent());
}
}

0 comments on commit 8bd24c2

Please sign in to comment.