Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wellingguzman committed Aug 22, 2018
1 parent 633a1ae commit 9398472
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ customs/interfaces/*
!customs/interfaces/_example
/customs/listviews/*
!customs/listviews/.gitignore
!storage/uploads/.gitignore
!storage/uploads/thumbs/.gitignore
!public/uploads/_/originals/.gitignore
!public/uploads/_/thumbnails/.gitignore

thumbnail/**/

Expand Down
1 change: 0 additions & 1 deletion public/thumbnail/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion tests/io/ActivityCommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static function clearData()
reset_table_id(static::$db, 'directus_users', 4);
reset_table_id(static::$db, 'directus_files', 2);
truncate_table(static::$db, 'directus_folders');
$storagePath = __DIR__ . '/../../public/storage';
$storagePath = __DIR__ . '/../../public/uploads/_/originals';

clear_storage($storagePath);
}
Expand Down
18 changes: 17 additions & 1 deletion tests/io/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Directus\Tests\Api\Io;

use function Directus\array_get;
use Directus\Authentication\Exception\ExpiredTokenException;
use Directus\Authentication\Exception\InvalidTokenException;
use Directus\Authentication\Exception\InvalidUserCredentialsException;
use Directus\Authentication\Exception\UserInactiveException;
use Directus\Authentication\Provider;
use Directus\Util\JWTUtils;
use Directus\Validator\Exception\InvalidRequestException;
use GuzzleHttp\Exception\ClientException;
Expand Down Expand Up @@ -178,7 +180,7 @@ public function testInvalidTokenRefresh()

// valid but expired token
$response = request_error_post($path, [
'token' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZXhwIjoxNTM0NTE1MTA4LCJ0eXBlIjoiYXV0aCJ9.Ux3JhxReqiSZIJOb_7_-R-1JzJ4krYRodyco09ZG6gI'
'token' => $this->generateExpiredToken()
]);

assert_response_error($this, $response, [
Expand Down Expand Up @@ -209,4 +211,18 @@ public function testDisabledUserToken()
'code' => UserInactiveException::ERROR_CODE
]);
}

protected function generateExpiredToken()
{
$config = require __DIR__ . '/../../config/api.php';
$secretKey = array_get($config, 'auth.secret_key');

$payload = [
'id' => 1,
'type' => JWTUtils::TYPE_AUTH,
'exp' => time() - 3600,
];

return JWTUtils::encode($payload, $secretKey, 'HS256');
}
}
10 changes: 1 addition & 9 deletions tests/io/FilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ class FilesTest extends \PHPUnit_Framework_TestCase
*/
protected static $uploadPath;

/**
* @var string
*/
protected static $thumbsPath;

public static function resetDatabase()
{
static::$uploadPath = realpath(__DIR__ . '/../../public/storage/uploads');
static::$thumbsPath = static::$uploadPath . '/thumbs';
static::$uploadPath = realpath(__DIR__ . '/../../public/uploads/_/originals');

static::$db = create_db_connection();
reset_table_id(static::$db, 'directus_files', 2);
Expand Down Expand Up @@ -214,7 +208,6 @@ public function testDelete()
]);

$this->assertFalse(file_exists(static::$uploadPath . '/' . static::$fileName));
$this->assertFalse(file_exists(static::$thumbsPath . '/2.jpg'));

// delete second file
$response = request_delete('files/4', ['query' => $this->queryParams]);
Expand All @@ -227,7 +220,6 @@ public function testDelete()
]);

$this->assertFalse(file_exists(static::$uploadPath . '/' . static::$fileName2));
$this->assertFalse(file_exists(static::$thumbsPath . '/4.jpg'));
}

protected function getImageBase64()
Expand Down
2 changes: 1 addition & 1 deletion tests/io/ItemsBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function resetData()
['name' => 'Old Category']
]);
fill_table(static::$db, 'products', static::$data);
$uploadPath = realpath(__DIR__ . '/../../public/storage/uploads');
$uploadPath = realpath(__DIR__ . '/../../public/uploads/_/originals');
clear_storage($uploadPath);

request_patch('fields/products/status', ['options' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/io/ItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function resetData()
['name' => 'Old Category']
]);
fill_table(static::$db, 'products', static::$data);
$uploadPath = realpath(__DIR__ . '/../../public/storage/uploads');
$uploadPath = realpath(__DIR__ . '/../../public/uploads/_/originals');
clear_storage($uploadPath);

request_patch('fields/products/status', ['options' => [
Expand Down
11 changes: 0 additions & 11 deletions tests/utils/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,4 @@ function clear_storage($basePath)

unlink($filename);
}

$thumbsOmit = ['.gitignore', '1.jpg'];
$thumbsPath = $basePath . '/thumbs';
foreach (glob($thumbsPath . "/*.*") as $filename) {
$name = basename($filename);
if (is_dir($filename) || in_array($name, $thumbsOmit)) {
continue;
}

unlink($filename);
}
}

0 comments on commit 9398472

Please sign in to comment.