indentations and wipes out empty lines
This commit is contained in:
parent
73d0fe5e10
commit
a6e052e216
|
@ -316,11 +316,9 @@ class Test_Importer extends Importer {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
@ -334,7 +332,6 @@ class Test_Importer extends Importer {
|
|||
if ($tax1->validate()) {
|
||||
$tax1 = $this->tax_repo->insert($tax1);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* In these set up steps, if we have an error adding
|
||||
* a taxonomy, collection or metadatum, there is no point
|
||||
|
@ -345,14 +342,12 @@ class Test_Importer extends Importer {
|
|||
$this->add_error_log('Error creating taxonomy Color');
|
||||
$this->add_error_log($tax1->get_errors());
|
||||
$this->abort();
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->add_transient('tax_1_id', $tax1->get_id());
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public function create_collections() {
|
||||
|
@ -366,11 +361,9 @@ class Test_Importer extends Importer {
|
|||
$this->add_error_log('Error creating Collection 1');
|
||||
$this->add_error_log($col1->get_errors());
|
||||
$this->abort();
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$col1_map = [];
|
||||
|
||||
// metadata
|
||||
|
@ -696,8 +689,7 @@ class Test_Importer extends Importer {
|
|||
* @param $collection
|
||||
*
|
||||
*/
|
||||
private function create_metadata( $args, $collection ){
|
||||
|
||||
private function create_metadata( $args, $collection ) {
|
||||
$metadatum = new Entities\Metadatum();
|
||||
$metadatum->set_name($args['name']);
|
||||
$metadatum->set_collection($collection);
|
||||
|
@ -758,7 +750,6 @@ class Test_Importer extends Importer {
|
|||
return $array;
|
||||
}
|
||||
|
||||
|
||||
public function get_col2_item($index) {
|
||||
return [
|
||||
'field1' => 'Collection 2 item ' . $index,
|
||||
|
@ -766,7 +757,5 @@ class Test_Importer extends Importer {
|
|||
'field3' => 'Collection 2 whatever ' . $index,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -64,5 +64,3 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_UnitApiTestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -952,5 +952,3 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -8,23 +8,14 @@ namespace Tainacan\Tests;
|
|||
class TAINACAN_REST_Metadata_Types_Controller extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
public function test_get_metadata_types(){
|
||||
|
||||
$ftype_request = new \WP_REST_Request('GET', $this->namespace . '/metadata-types');
|
||||
|
||||
$ftype_response = $this->server->dispatch($ftype_request);
|
||||
|
||||
$data = $ftype_response->get_data();
|
||||
|
||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||
|
||||
$metadata_types = $Tainacan_Metadata->fetch_metadata_types('NAME');
|
||||
|
||||
$this->assertEquals(count($metadata_types), count($data));
|
||||
|
||||
foreach ($data as $ftype){
|
||||
$this->assertContains($ftype['name'], $metadata_types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -7,8 +7,6 @@ namespace Tainacan\Tests;
|
|||
*/
|
||||
class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
|
||||
|
||||
public function test_create_item() {
|
||||
|
||||
$orig_file = './tests/attachment/codeispoetrywp.jpg';
|
||||
|
@ -62,12 +60,9 @@ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase {
|
|||
$folder = 'tainacan-items/' . $this->collection->get_id() . '/' . $this->item->get_id();
|
||||
|
||||
$this->assertContains( $folder, $attachment_data['file'] );
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_internal_api() {
|
||||
|
||||
$orig_file = './tests/attachment/codeispoetrywp.jpg';
|
||||
$this->test_file = '/tmp/codeispoetrywp.jpg';
|
||||
copy( $orig_file, $this->test_file );
|
||||
|
@ -94,15 +89,10 @@ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase {
|
|||
);
|
||||
|
||||
$attachment_id = \Tainacan\Media::get_instance()->insert_attachment_from_file($this->test_file, $this->item->get_id());
|
||||
|
||||
$attachment_data = wp_get_attachment_metadata($attachment_id);
|
||||
|
||||
$folder = 'tainacan-items/' . $this->collection->get_id() . '/' . $this->item->get_id();
|
||||
|
||||
$this->assertContains( $folder, $attachment_data['file'] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -8,9 +8,7 @@ namespace Tainacan\Tests;
|
|||
class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
public function test_queries(){
|
||||
|
||||
// Populate the database
|
||||
|
||||
$collectionB = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
[
|
||||
|
@ -57,8 +55,8 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
),
|
||||
true
|
||||
);
|
||||
// Create Term
|
||||
|
||||
// Create Term
|
||||
$termA = $this->tainacan_entity_factory->create_entity(
|
||||
'term',
|
||||
array(
|
||||
|
@ -173,8 +171,6 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertCount(1, $data1);
|
||||
$this->assertEquals($collectionB->get_name(), $data1[0]['name']);
|
||||
|
||||
|
||||
|
||||
// Search collection with a specific keyword and not other keyword
|
||||
$search_query = ['search' => 'Collection -A'];
|
||||
|
||||
|
@ -190,14 +186,9 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
$names = [$data2[0]['name'], $data2[1]['name']];
|
||||
$this->assertNotContains('A', $names);
|
||||
|
||||
|
||||
|
||||
/* Meta Query:
|
||||
*
|
||||
* Fetch items from a collection desc ordered by metadatumA1 and its only in range A to F.
|
||||
*
|
||||
* */
|
||||
|
||||
$meta_query = [
|
||||
'metakey' => $metadatumA1->get_id(),
|
||||
'orderby' => 'meta_value',
|
||||
|
@ -212,16 +203,11 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
];
|
||||
|
||||
$meta_query_request = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items');
|
||||
|
||||
$meta_query_request->set_query_params($meta_query);
|
||||
|
||||
$meta_query_response = $this->server->dispatch($meta_query_request);
|
||||
$data3 = $meta_query_response->get_data()['items'];
|
||||
|
||||
$this->assertCount(2, $data3);
|
||||
|
||||
$metadatumA1_slug = $metadatumA1->get_slug();
|
||||
|
||||
$values = [$data3[0]['metadata'][$metadatumA1_slug]['value'], $data3[1]['metadata'][$metadatumA1_slug]['value']];
|
||||
|
||||
$this->assertNotContains('G', $values);
|
||||
|
@ -230,13 +216,9 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('E', $data3[0]['metadata'][$metadatumA1_slug]['value']);
|
||||
$this->assertEquals('D', $data3[1]['metadata'][$metadatumA1_slug]['value']);
|
||||
|
||||
|
||||
/* Date Query:
|
||||
*
|
||||
* Fetch posts for today
|
||||
*
|
||||
* */
|
||||
|
||||
$today = getdate();
|
||||
|
||||
$date_query = [
|
||||
|
@ -268,11 +250,8 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertCount(0, $data5);
|
||||
|
||||
/* Tax Query
|
||||
*
|
||||
* Fetch items under a taxonomy with a specific term
|
||||
*
|
||||
* */
|
||||
|
||||
$tax_query = [
|
||||
'taxquery' => [
|
||||
[
|
||||
|
@ -300,6 +279,4 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertContains('Item A-2', $itemsA1_A2);
|
||||
$this->assertNotContains('Item A-3', $itemsA1_A2);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
|
@ -7,8 +7,6 @@ namespace Tainacan\Tests;
|
|||
*
|
||||
*/
|
||||
class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
||||
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
// reset WP_Roles object. Possible bug was cleaning database between tests, but not the object
|
||||
|
@ -35,7 +33,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$data = $name_response->get_data();
|
||||
$this->assertArrayHasKey('tainacan-new-role', $data);
|
||||
$this->assertEquals('New role', $data['tainacan-new-role']['name']);
|
||||
|
||||
}
|
||||
|
||||
public function test_create_remove_roles() {
|
||||
|
@ -58,13 +55,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$name_response = $this->server->dispatch($request);
|
||||
$data = $name_response->get_data();
|
||||
$this->assertArrayNotHasKey('tainacan-super-role', $data);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function test_edit_role() {
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/roles');
|
||||
|
||||
$request->set_query_params(['name' => 'New role']);
|
||||
|
@ -92,29 +85,24 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals('Changed name', $role['name']);
|
||||
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role');
|
||||
|
||||
$request->set_query_params(
|
||||
[
|
||||
'add_cap' => 'manage_options'
|
||||
]
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 400, $response->get_status() );
|
||||
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role');
|
||||
|
||||
$request->set_query_params(
|
||||
[
|
||||
'add_cap' => 'manage_tainacan_collection_234'
|
||||
]
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
}
|
||||
|
||||
public function test_edit_role_validation() {
|
||||
|
@ -171,33 +159,27 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
}
|
||||
|
||||
public function test_get_role() {
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/roles/administrator');
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
$this->assertEquals( translate_user_role('Administrator'), $data['name'] );
|
||||
$this->assertArrayHasKey('manage_tainacan', $data['capabilities']);
|
||||
$this->assertTrue($data['capabilities']['manage_tainacan']);
|
||||
|
||||
}
|
||||
|
||||
public function test_get_roles() {
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/roles');
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
$data = $response->get_data();
|
||||
|
||||
foreach (\tainacan_roles()->get_tainacan_roles() as $role => $r) {
|
||||
$this->assertArrayHasKey($role, $data);
|
||||
}
|
||||
|
@ -210,7 +192,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$request->set_query_params(['name' => 'New role']);
|
||||
|
||||
$create = $this->server->dispatch($request);
|
||||
//var_dump($create);
|
||||
$this->assertEquals( 201, $create->get_status() );
|
||||
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role');
|
||||
|
@ -267,7 +248,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
}
|
||||
|
||||
public function test_get_collection_caps() {
|
||||
|
||||
$collection = $this->tainacan_entity_factory->create_entity(
|
||||
'collection',
|
||||
array(
|
||||
|
@ -290,9 +270,7 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$contributor->add_cap( 'tnc_col_all_edit_items' );
|
||||
$contributor->add_cap( 'tnc_col_all_edit_published_items' );
|
||||
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collection->get_id() . '/capabilities');
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
|
@ -308,11 +286,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertArrayHasKey('contributor', $caps['tnc_col_' . $collection->get_id() . '_edit_published_items']['roles_inherited']);
|
||||
|
||||
$this->assertArrayHasKey('administrator', $caps['tnc_col_' . $collection->get_id() . '_delete_published_items']['roles_inherited']);
|
||||
|
||||
}
|
||||
|
||||
function test_get_repo_capabilities() {
|
||||
|
||||
$role = add_role('test', 'test', ['tnc_rep_edit_metadata'=>true]);
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/capabilities');
|
||||
|
@ -329,12 +305,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$this->assertArrayNotHasKey('editor', $caps['manage_tainacan']['roles_inherited']);
|
||||
$this->assertArrayNotHasKey('administrator', $caps['manage_tainacan']['roles_inherited']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_edit_collection_users_permission() {
|
||||
|
||||
global $current_user;
|
||||
$subscriber = $this->factory()->user->create(array( 'role' => 'subscriber' ));
|
||||
|
||||
|
@ -349,7 +322,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
'add_cap' => 'tnc_col_12_edit_items'
|
||||
]
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 403, $response->get_status(), 'should not be permitted');
|
||||
|
@ -358,21 +330,17 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$current_user = $sub_user;
|
||||
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/contributor');
|
||||
|
||||
$request->set_query_params(
|
||||
[
|
||||
'name' => 'Changed name',
|
||||
'add_cap' => 'tnc_col_12_edit_items'
|
||||
]
|
||||
);
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 403, $response->get_status(), 'should still not be permitted because edits name');
|
||||
|
||||
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/contributor');
|
||||
|
||||
$request->set_query_params(
|
||||
[
|
||||
'add_cap' => 'tnc_rep_edit_metadata'
|
||||
|
@ -383,9 +351,7 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$this->assertEquals( 403, $response->get_status(), 'should not be permitted');
|
||||
|
||||
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/contributor');
|
||||
|
||||
$request->set_query_params(
|
||||
[
|
||||
'add_cap' => 'tnc_col_12_edit_items'
|
||||
|
@ -395,13 +361,8 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status(), 'should be permitted');
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group xis
|
||||
*/
|
||||
public function test_create_get_roles_with_caps() {
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/roles');
|
||||
|
@ -418,7 +379,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals( 201, $create->get_status() );
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/roles');
|
||||
|
||||
//$request->set_query_params($name_query);
|
||||
|
||||
$name_response = $this->server->dispatch($request);
|
||||
|
@ -430,13 +390,10 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$this->assertArrayHasKey('tnc_rep_edit_collections', $role['capabilities']);
|
||||
$this->assertTrue($role['capabilities']['tnc_rep_edit_collections']);
|
||||
|
||||
}
|
||||
|
||||
public function test_edit_role_with_caps() {
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/roles');
|
||||
|
||||
$request->set_query_params([
|
||||
'name' => 'New role',
|
||||
'capabilities' => [
|
||||
|
@ -468,8 +425,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertArrayHasKey('manage_tainacan_collection_123', $data['capabilities']);
|
||||
$this->assertTrue($data['capabilities']['manage_tainacan_collection_123']);
|
||||
|
||||
|
||||
|
||||
// EDIT
|
||||
$request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role');
|
||||
|
||||
|
@ -491,7 +446,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
||||
$request = new \WP_REST_Request('GET', $this->namespace . '/roles/tainacan-new-role');
|
||||
|
||||
$response = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 200, $response->get_status() );
|
||||
|
@ -510,27 +464,18 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase {
|
|||
|
||||
$this->assertArrayNotHasKey('tnc_rep_edit_taxonomies', $data['capabilities']);
|
||||
$this->assertArrayNotHasKey('manage_tainacan_collection_123', $data['capabilities']);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function test_new_role_can_read() {
|
||||
|
||||
$request = new \WP_REST_Request('POST', $this->namespace . '/roles');
|
||||
|
||||
$request->set_query_params(['name' => 'New role']);
|
||||
|
||||
$create = $this->server->dispatch($request);
|
||||
|
||||
$this->assertEquals( 201, $create->get_status() );
|
||||
|
||||
$role = get_role('tainacan-new-role');
|
||||
|
||||
$this->assertTrue( $role->has_cap( 'read' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
Loading…
Reference in New Issue