Skip to content

Commit

Permalink
Merge branch 'fix_810' of https://github.com/itsmerhp/api into fix_810
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Patel committed Apr 25, 2019
2 parents 0c954b1 + f2189a0 commit 6496c43
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,8 @@ protected function applyLegacyParams(Builder $query, array $params = [])
$entriesIds = [$entriesIds];
}

$query->whereIn($this->primaryKeyFieldName, $entriesIds);
//$query->whereIn($this->primaryKeyFieldName, $entriesIds);
$query->whereIn(new Expression('CAST('.$this->primaryKeyFieldName.' as CHAR)'), $entriesIds);
}

if (!ArrayUtils::has($params, 'q')) {
Expand Down
55 changes: 55 additions & 0 deletions tests/api/AuthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
use Directus\Api\Routes\Auth as Auth;
use GuzzleHttp\Client;
class AuthTest extends PHPUnit_Framework_TestCase
{
private $http;

public function setUp()
{
$this->http = new GuzzleHttp\Client([
'base_uri' => 'http://localhost/directus-api/public/_/',
'exceptions' => false
]);
}

public function tearDown() {
$this->http = null;
}

public function testAuthentication()
{

$data = [
'form_params' => [
'email' => "admin@example.com",
'password' => "password"
]
];

$response = $this->http->request('POST', 'auth/authenticate', $data);

$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(true), true);
$this->assertArrayHasKey('token', $data['data']);
$this->assertTrue(!empty($data['data']['token']));

}

public function testForgotPassword()
{

$data = [
'form_params' => [
'email' => "admin@example.com"
]
];

$response = $this->http->request('POST', 'auth/password/request', $data);

$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(true), true);
$this->assertTrue($data['public']);

}
}
156 changes: 156 additions & 0 deletions tests/api/CollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?php
use Directus\Api\Routes\Auth as Auth;
use GuzzleHttp\Client;
class CollectionTest extends PHPUnit_Framework_TestCase
{
private $http,$token;

public function setUp()
{
$this->http = new GuzzleHttp\Client([
'base_uri' => 'http://localhost/directus-api/public/_/',
'exceptions' => false
]);

//Get token
$data = [
'form_params' => [
'email' => "admin@example.com",
'password' => "password"
]
];

$response = $this->http->request('POST', 'auth/authenticate', $data);
$data = json_decode($response->getBody(true), true);
$this->token = $data['data']['token'];

}

public function tearDown() {
$this->http = null;
}

public function testCreateCollection()
{
$data = [
'headers' => ['Authorization' => 'bearer '.$this->token],
'form_params' => json_decode('{
"collection": "test111_collection",
"hidden": 0,
"fields": [{
"type": "integer",
"datatype": "INT",
"length": 15,
"field": "id",
"interface": "primary-key",
"auto_increment": true,
"primary_key": true,
"hidden_detail": true,
"hidden_browse": true
}, {
"type": "status",
"datatype": "VARCHAR",
"length": 20,
"field": "status",
"interface": "status",
"options": {
"status_mapping": {
"published": {
"name": "Published",
"text_color": "white",
"background_color": "accent",
"browse_subdued": false,
"browse_badge": true,
"soft_delete": false,
"published": true
},
"draft": {
"name": "Draft",
"text_color": "white",
"background_color": "blue-grey-200",
"browse_subdued": true,
"browse_badge": true,
"soft_delete": false,
"published": false
},
"deleted": {
"name": "Deleted",
"text_color": "white",
"background_color": "red",
"browse_subdued": true,
"browse_badge": true,
"soft_delete": true,
"published": false
}
}
}
}, {
"type": "sort",
"datatype": "INT",
"field": "sort",
"interface": "sort"
}, {
"type": "user_created",
"datatype": "INT",
"field": "created_by",
"interface": "user-created",
"options": {
"template": "{{first_name}} {{last_name}}",
"display": "both"
},
"readonly": true,
"hidden_detail": true,
"hidden_browse": true
}, {
"type": "datetime_created",
"datatype": "DATETIME",
"field": "created_on",
"interface": "datetime-created",
"readonly": true,
"hidden_detail": true,
"hidden_browse": true
}, {
"type": "user_updated",
"datatype": "INT",
"field": "modified_by",
"interface": "user-updated",
"options": {
"template": "{{first_name}} {{last_name}}",
"display": "both"
},
"readonly": true,
"hidden_detail": true,
"hidden_browse": true
}, {
"type": "datetime_updated",
"datatype": "DATETIME",
"field": "modified_on",
"interface": "datetime-updated",
"readonly": true,
"hidden_detail": true,
"hidden_browse": true
}]
}',true)
];

//echo "<pre>";
//print_r($data);exit;
$response = $this->http->request('POST', 'collections', $data);
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody(true), true);
$this->assertArrayHasKey('collection', $data['data']);
$this->assertTrue(!empty($data['data']['collection']));
}

public function testDeleteCollection()
{
$data = [
'headers' => ['Authorization' => 'bearer '.$this->token],
];

$response = $this->http->request('DELETE', 'collections/test111_collection', $data);

$this->assertEquals(204, $response->getStatusCode());
}

}

0 comments on commit 6496c43

Please sign in to comment.