fix: indentations

This commit is contained in:
vnmedeiros 2021-02-18 10:29:57 -03:00
parent 2ad1489d99
commit b071dd05e2
1 changed files with 269 additions and 269 deletions

View File

@ -20,7 +20,7 @@ class Items extends TAINACAN_UnitTestCase {
*/ */
public function test_permissions () { public function test_permissions () {
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
'name' => 'testePerm', 'name' => 'testePerm',
@ -39,202 +39,202 @@ class Items extends TAINACAN_UnitTestCase {
$this->assertTrue($item->can_read(), 'Administrator cannot read the Item'); $this->assertTrue($item->can_read(), 'Administrator cannot read the Item');
$this->assertTrue($item->can_edit(), 'Administrator cannot edit the Item'); $this->assertTrue($item->can_edit(), 'Administrator cannot edit the Item');
// another administrator should be able to edit items // another administrator should be able to edit items
$new_admin = $this->factory()->user->create(array( 'role' => 'administrator' )); $new_admin = $this->factory()->user->create(array( 'role' => 'administrator' ));
wp_set_current_user($new_admin); wp_set_current_user($new_admin);
$this->assertTrue($item->can_read(), 'Administrator cannot read the Item'); $this->assertTrue($item->can_read(), 'Administrator cannot read the Item');
$this->assertTrue($item->can_edit(), 'Administrator cannot edit the Item'); $this->assertTrue($item->can_edit(), 'Administrator cannot edit the Item');
$this->assertTrue(current_user_can($collection->get_items_capabilities()->edit_post, $item->get_id()), 'Administrator cannot edit an item!'); $this->assertTrue(current_user_can($collection->get_items_capabilities()->edit_post, $item->get_id()), 'Administrator cannot edit an item!');
} }
function teste_query(){ function teste_query(){
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
'name' => 'teste', 'name' => 'teste',
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$collection2 = $this->tainacan_entity_factory->create_entity( $collection2 = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
'name' => 'teste2', 'name' => 'teste2',
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$metadatum = $this->tainacan_entity_factory->create_entity( $metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'metadado', 'name' => 'metadado',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
), ),
true true
); );
$metadatum2 = $this->tainacan_entity_factory->create_entity( $metadatum2 = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'metadado2', 'name' => 'metadado2',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
), ),
true true
); );
$metadatum3 = $this->tainacan_entity_factory->create_entity( $metadatum3 = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'metadado3', 'name' => 'metadado3',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
), ),
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'orange', 'title' => 'orange',
'collection' => $collection, 'collection' => $collection,
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_1'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_1');
$item = $Tainacan_Items->fetch($i->get_id()); $item = $Tainacan_Items->fetch($i->get_id());
$meta_test = new Entities\Item_Metadata_Entity($item, $metadatum); $meta_test = new Entities\Item_Metadata_Entity($item, $metadatum);
$this->assertTrue( $meta_test instanceof Entities\Item_Metadata_Entity ); $this->assertTrue( $meta_test instanceof Entities\Item_Metadata_Entity );
$this->assertEquals( $metadatum->get_id(), $meta_test->get_metadatum()->get_id() ); $this->assertEquals( $metadatum->get_id(), $meta_test->get_metadatum()->get_id() );
$this->assertEquals( 'value_1', $meta_test->get_value()); $this->assertEquals( 'value_1', $meta_test->get_value());
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'apple', 'title' => 'apple',
'collection' => $collection2, 'collection' => $collection2,
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_2'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_2');
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'lemon', 'title' => 'lemon',
'collection' => $collection2, 'collection' => $collection2,
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum2, 'value_2'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum2, 'value_2');
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum2, 'value_3'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum2, 'value_3');
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_3'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_3');
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'pineapple', 'title' => 'pineapple',
'collection' => $collection2, 'collection' => $collection2,
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum2, 'value_3'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum2, 'value_3');
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_6'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_6');
// should return all 4 items // should return all 4 items
$test_query = $Tainacan_Items->fetch([]); $test_query = $Tainacan_Items->fetch([]);
$this->assertEquals(4, $test_query->post_count ); $this->assertEquals(4, $test_query->post_count );
// should also return all 4 items // should also return all 4 items
$test_query = $Tainacan_Items->fetch([], [$collection, $collection2]); $test_query = $Tainacan_Items->fetch([], [$collection, $collection2]);
$this->assertEquals(4, $test_query->post_count); $this->assertEquals(4, $test_query->post_count);
// should return 2 items // should return 2 items
$test_query = $Tainacan_Items->fetch(['posts_per_page' => 2], [$collection, $collection2]); $test_query = $Tainacan_Items->fetch(['posts_per_page' => 2], [$collection, $collection2]);
$this->assertEquals(2, $test_query->post_count); $this->assertEquals(2, $test_query->post_count);
// should return only the first item // should return only the first item
$test_query = $Tainacan_Items->fetch([], $collection); $test_query = $Tainacan_Items->fetch([], $collection);
$this->assertEquals(1,$test_query->post_count); $this->assertEquals(1,$test_query->post_count);
$test_query->the_post(); $test_query->the_post();
$item1 = new Entities\Item( get_the_ID() ); $item1 = new Entities\Item( get_the_ID() );
$this->assertEquals('orange', $item1->get_title() ); $this->assertEquals('orange', $item1->get_title() );
$test_query = $Tainacan_Items->fetch(['title' => 'orange']); $test_query = $Tainacan_Items->fetch(['title' => 'orange']);
$test_query->the_post(); $test_query->the_post();
$item2 = new Entities\Item( get_the_ID() ); $item2 = new Entities\Item( get_the_ID() );
$this->assertEquals(1, $test_query->post_count); $this->assertEquals(1, $test_query->post_count);
$this->assertEquals('orange', $item2->get_title()); $this->assertEquals('orange', $item2->get_title());
// should return the other 3 items // should return the other 3 items
$test_query = $Tainacan_Items->fetch([], $collection2); $test_query = $Tainacan_Items->fetch([], $collection2);
$this->assertEquals(3,$test_query->post_count); $this->assertEquals(3,$test_query->post_count);
$test_query = $Tainacan_Items->fetch(['title' => 'apple']); $test_query = $Tainacan_Items->fetch(['title' => 'apple']);
$test_query->the_post(); $test_query->the_post();
$item3 = new Entities\Item( get_the_ID() ); $item3 = new Entities\Item( get_the_ID() );
$this->assertEquals(1, $test_query->post_count); $this->assertEquals(1, $test_query->post_count);
$this->assertEquals('apple', $item3->get_title()); $this->assertEquals('apple', $item3->get_title());
// should return 1 item // should return 1 item
$test_query = $Tainacan_Items->fetch([ $test_query = $Tainacan_Items->fetch([
'meta_query' => [ 'meta_query' => [
[ [
'key' => $metadatum2->get_id(), 'key' => $metadatum2->get_id(),
'value' => 'value_3' 'value' => 'value_3'
] ]
] ]
], $collection2); ], $collection2);
$this->assertEquals(2, $test_query->post_count); $this->assertEquals(2, $test_query->post_count);
// should return 2 items // should return 2 items
$test_query = $Tainacan_Items->fetch([ $test_query = $Tainacan_Items->fetch([
'meta_query' => [ 'meta_query' => [
[ [
'key' => $metadatum2->get_id(), 'key' => $metadatum2->get_id(),
'value' => 'value_3' 'value' => 'value_3'
] ]
] ]
], $collection2); ], $collection2);
$this->assertEquals(2, $test_query->post_count); $this->assertEquals(2, $test_query->post_count);
// should return 2 items // should return 2 items
$test_query = $Tainacan_Items->fetch([ $test_query = $Tainacan_Items->fetch([
'meta_query' => [ 'meta_query' => [
[ [
'key' => $metadatum3->get_id(), 'key' => $metadatum3->get_id(),
'value' => 'value_2', 'value' => 'value_2',
'compare' => '>' 'compare' => '>'
] ]
] ]
], $collection2); ], $collection2);
$this->assertEquals(2, $test_query->post_count); $this->assertEquals(2, $test_query->post_count);
// test fetch ids // test fetch ids
$test_query = $Tainacan_Items->fetch_ids([]); $test_query = $Tainacan_Items->fetch_ids([]);
$this->assertTrue( is_array($test_query) ); $this->assertTrue( is_array($test_query) );
$this->assertEquals(4, sizeof($test_query) ); $this->assertEquals(4, sizeof($test_query) );
$this->assertTrue( is_int($test_query[0]) ); $this->assertTrue( is_int($test_query[0]) );
$this->assertTrue( is_int($test_query[1]) ); $this->assertTrue( is_int($test_query[1]) );
$this->assertTrue( is_int($test_query[2]) ); $this->assertTrue( is_int($test_query[2]) );
@ -244,138 +244,138 @@ class Items extends TAINACAN_UnitTestCase {
$this->assertTrue( is_array($test_query) ); $this->assertTrue( is_array($test_query) );
$this->assertEquals(0, sizeof($test_query) ); $this->assertEquals(0, sizeof($test_query) );
} }
function teste_meta_query_in(){ function teste_meta_query_in(){
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
'name' => 'teste', 'name' => 'teste',
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$metadatum = $this->tainacan_entity_factory->create_entity( $metadatum = $this->tainacan_entity_factory->create_entity(
'metadatum', 'metadatum',
array( array(
'name' => 'metadado', 'name' => 'metadado',
'status' => 'publish', 'status' => 'publish',
'collection' => $collection, 'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Text', 'metadata_type' => 'Tainacan\Metadata_Types\Text',
), ),
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'teste10',
'collection' => $collection,
'status' => 'publish'
),
true
);
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_10');
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'test100', 'title' => 'teste10',
'collection' => $collection, 'collection' => $collection,
'status' => 'publish' 'status' => 'publish'
), ),
true true
); );
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_100'); $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_10');
$i = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'test100',
'collection' => $collection,
'status' => 'publish'
),
true
);
$this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum, 'value_100');
// should return 1 items // should return 1 items
$test_query = $Tainacan_Items->fetch([ $test_query = $Tainacan_Items->fetch([
'meta_query' => [ 'meta_query' => [
[ [
'key' => $metadatum->get_id(), 'key' => $metadatum->get_id(),
'value' => ['value_10'], 'value' => ['value_10'],
'compare' => 'IN' 'compare' => 'IN'
] ]
] ]
], $collection); ], $collection);
$this->assertEquals(1, $test_query->post_count); $this->assertEquals(1, $test_query->post_count);
} }
/** /**
* @group comments * @group comments
*/ */
public function test_items_comment() { public function test_items_comment() {
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
'name' => 'collectionComments', 'name' => 'collectionComments',
'allow_comments' => 'closed' 'allow_comments' => 'closed'
), ),
true, true,
true true
); );
$item = $this->tainacan_entity_factory->create_entity( $item = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'itemComments1', 'title' => 'itemComments1',
'collection' => $collection, 'collection' => $collection,
'comment_status' => 'open' 'comment_status' => 'open'
), ),
true, true,
true true
); );
global $wp_query; global $wp_query;
$wp_query = new \WP_Query(); $wp_query = new \WP_Query();
$this->assertTrue(setup_postdata($item->WP_Post)); $this->assertTrue(setup_postdata($item->WP_Post));
$this->assertFalse(comments_open($item->get_id())); $this->assertFalse(comments_open($item->get_id()));
$collections = \Tainacan\Repositories\Collections::get_instance(); $collections = \Tainacan\Repositories\Collections::get_instance();
$collection->set('allow_comments', 'open'); $collection->set('allow_comments', 'open');
$this->assertTrue($collection->validate()); $this->assertTrue($collection->validate());
$collections->update($collection); $collections->update($collection);
$this->assertTrue(comments_open($item->get_id())); $this->assertTrue(comments_open($item->get_id()));
$items = \Tainacan\Repositories\Items::get_instance(); $items = \Tainacan\Repositories\Items::get_instance();
$item->set('comment_status', 'closed'); $item->set('comment_status', 'closed');
$this->assertTrue($item->validate()); $this->assertTrue($item->validate());
$items->update($item); $items->update($item);
$this->assertFalse(comments_open($item->get_id())); $this->assertFalse(comments_open($item->get_id()));
} }
public function test_delete_item() { public function test_delete_item() {
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
array( array(
'name' => 'collectionComments', 'name' => 'collectionComments',
'allow_comments' => 'closed' 'allow_comments' => 'closed'
), ),
true, true,
true true
); );
$item = $this->tainacan_entity_factory->create_entity( $item = $this->tainacan_entity_factory->create_entity(
'item', 'item',
array( array(
'title' => 'itemComments1', 'title' => 'itemComments1',
'collection' => $collection, 'collection' => $collection,
'comment_status' => 'open' 'comment_status' => 'open'
), ),
true, true,
true true
); );
$item_id = $item->get_id(); $item_id = $item->get_id();