From b071dd05e2f99158737af1d6f96224825b016d13 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Thu, 18 Feb 2021 10:29:57 -0300 Subject: [PATCH] fix: indentations --- tests/test-items.php | 538 +++++++++++++++++++++---------------------- 1 file changed, 269 insertions(+), 269 deletions(-) diff --git a/tests/test-items.php b/tests/test-items.php index 8ba6367a2..109d2c695 100644 --- a/tests/test-items.php +++ b/tests/test-items.php @@ -20,7 +20,7 @@ class Items extends TAINACAN_UnitTestCase { */ public function test_permissions () { - $collection = $this->tainacan_entity_factory->create_entity( + $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( '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_edit(), 'Administrator cannot edit the Item'); - // another administrator should be able to edit items - $new_admin = $this->factory()->user->create(array( 'role' => 'administrator' )); + // another administrator should be able to edit items + $new_admin = $this->factory()->user->create(array( 'role' => 'administrator' )); 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(current_user_can($collection->get_items_capabilities()->edit_post, $item->get_id()), 'Administrator cannot edit an item!'); } - function teste_query(){ - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste', - 'status' => 'publish' - ), - true - ); + function teste_query(){ + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste', + 'status' => 'publish' + ), + true + ); - $collection2 = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste2', - 'status' => 'publish' - ), - true - ); + $collection2 = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste2', + 'status' => 'publish' + ), + true + ); - $metadatum = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'status' => 'publish', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado', + 'status' => 'publish', + 'collection' => $collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - $metadatum2 = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado2', - 'status' => 'publish', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum2 = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado2', + 'status' => 'publish', + 'collection' => $collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - $metadatum3 = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado3', - 'status' => 'publish', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum3 = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado3', + 'status' => 'publish', + 'collection' => $collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + 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' => 'orange', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'orange', + 'collection' => $collection, + 'status' => 'publish' + ), + 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()); - $meta_test = new Entities\Item_Metadata_Entity($item, $metadatum); - $this->assertTrue( $meta_test instanceof Entities\Item_Metadata_Entity ); - $this->assertEquals( $metadatum->get_id(), $meta_test->get_metadatum()->get_id() ); - $this->assertEquals( 'value_1', $meta_test->get_value()); + $item = $Tainacan_Items->fetch($i->get_id()); + $meta_test = new Entities\Item_Metadata_Entity($item, $metadatum); + $this->assertTrue( $meta_test instanceof Entities\Item_Metadata_Entity ); + $this->assertEquals( $metadatum->get_id(), $meta_test->get_metadatum()->get_id() ); + $this->assertEquals( 'value_1', $meta_test->get_value()); - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'apple', - 'collection' => $collection2, - 'status' => 'publish' - ), - true - ); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'apple', + 'collection' => $collection2, + 'status' => 'publish' + ), + 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( - 'item', - array( - 'title' => 'lemon', - 'collection' => $collection2, - 'status' => 'publish' - ), - true - ); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'lemon', + 'collection' => $collection2, + 'status' => 'publish' + ), + true + ); - $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, $metadatum3, 'value_3'); + $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, $metadatum3, 'value_3'); - $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'pineapple', - 'collection' => $collection2, - 'status' => 'publish' - ), - true - ); + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'pineapple', + 'collection' => $collection2, + 'status' => 'publish' + ), + true + ); - $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, $metadatum2, 'value_3'); + $this->tainacan_item_metadata_factory->create_item_metadata($i, $metadatum3, 'value_6'); - // should return all 4 items - $test_query = $Tainacan_Items->fetch([]); - $this->assertEquals(4, $test_query->post_count ); + // should return all 4 items + $test_query = $Tainacan_Items->fetch([]); + $this->assertEquals(4, $test_query->post_count ); - // should also return all 4 items - $test_query = $Tainacan_Items->fetch([], [$collection, $collection2]); - $this->assertEquals(4, $test_query->post_count); + // should also return all 4 items + $test_query = $Tainacan_Items->fetch([], [$collection, $collection2]); + $this->assertEquals(4, $test_query->post_count); - // should return 2 items - $test_query = $Tainacan_Items->fetch(['posts_per_page' => 2], [$collection, $collection2]); - $this->assertEquals(2, $test_query->post_count); + // should return 2 items + $test_query = $Tainacan_Items->fetch(['posts_per_page' => 2], [$collection, $collection2]); + $this->assertEquals(2, $test_query->post_count); - // should return only the first item - $test_query = $Tainacan_Items->fetch([], $collection); - $this->assertEquals(1,$test_query->post_count); + // should return only the first item + $test_query = $Tainacan_Items->fetch([], $collection); + $this->assertEquals(1,$test_query->post_count); - $test_query->the_post(); - $item1 = new Entities\Item( get_the_ID() ); - $this->assertEquals('orange', $item1->get_title() ); + $test_query->the_post(); + $item1 = new Entities\Item( get_the_ID() ); + $this->assertEquals('orange', $item1->get_title() ); - $test_query = $Tainacan_Items->fetch(['title' => 'orange']); - $test_query->the_post(); - $item2 = new Entities\Item( get_the_ID() ); + $test_query = $Tainacan_Items->fetch(['title' => 'orange']); + $test_query->the_post(); + $item2 = new Entities\Item( get_the_ID() ); - $this->assertEquals(1, $test_query->post_count); - $this->assertEquals('orange', $item2->get_title()); + $this->assertEquals(1, $test_query->post_count); + $this->assertEquals('orange', $item2->get_title()); - // should return the other 3 items - $test_query = $Tainacan_Items->fetch([], $collection2); - $this->assertEquals(3,$test_query->post_count); + // should return the other 3 items + $test_query = $Tainacan_Items->fetch([], $collection2); + $this->assertEquals(3,$test_query->post_count); - $test_query = $Tainacan_Items->fetch(['title' => 'apple']); - $test_query->the_post(); - $item3 = new Entities\Item( get_the_ID() ); + $test_query = $Tainacan_Items->fetch(['title' => 'apple']); + $test_query->the_post(); + $item3 = new Entities\Item( get_the_ID() ); - $this->assertEquals(1, $test_query->post_count); - $this->assertEquals('apple', $item3->get_title()); + $this->assertEquals(1, $test_query->post_count); + $this->assertEquals('apple', $item3->get_title()); - // should return 1 item - $test_query = $Tainacan_Items->fetch([ - 'meta_query' => [ - [ - 'key' => $metadatum2->get_id(), - 'value' => 'value_3' - ] - ] - ], $collection2); - $this->assertEquals(2, $test_query->post_count); + // should return 1 item + $test_query = $Tainacan_Items->fetch([ + 'meta_query' => [ + [ + 'key' => $metadatum2->get_id(), + 'value' => 'value_3' + ] + ] + ], $collection2); + $this->assertEquals(2, $test_query->post_count); - // should return 2 items - $test_query = $Tainacan_Items->fetch([ - 'meta_query' => [ - [ - 'key' => $metadatum2->get_id(), - 'value' => 'value_3' - ] - ] - ], $collection2); - $this->assertEquals(2, $test_query->post_count); + // should return 2 items + $test_query = $Tainacan_Items->fetch([ + 'meta_query' => [ + [ + 'key' => $metadatum2->get_id(), + 'value' => 'value_3' + ] + ] + ], $collection2); + $this->assertEquals(2, $test_query->post_count); - // should return 2 items - $test_query = $Tainacan_Items->fetch([ - 'meta_query' => [ - [ - 'key' => $metadatum3->get_id(), - 'value' => 'value_2', - 'compare' => '>' - ] - ] - ], $collection2); - $this->assertEquals(2, $test_query->post_count); + // should return 2 items + $test_query = $Tainacan_Items->fetch([ + 'meta_query' => [ + [ + 'key' => $metadatum3->get_id(), + 'value' => 'value_2', + 'compare' => '>' + ] + ] + ], $collection2); + $this->assertEquals(2, $test_query->post_count); // test fetch ids $test_query = $Tainacan_Items->fetch_ids([]); - $this->assertTrue( is_array($test_query) ); - $this->assertEquals(4, sizeof($test_query) ); + $this->assertTrue( is_array($test_query) ); + $this->assertEquals(4, sizeof($test_query) ); $this->assertTrue( is_int($test_query[0]) ); $this->assertTrue( is_int($test_query[1]) ); $this->assertTrue( is_int($test_query[2]) ); @@ -244,138 +244,138 @@ class Items extends TAINACAN_UnitTestCase { $this->assertTrue( is_array($test_query) ); $this->assertEquals(0, sizeof($test_query) ); - } + } function teste_meta_query_in(){ - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'teste', - 'status' => 'publish' - ), - true - ); + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'teste', + 'status' => 'publish' + ), + true + ); - $metadatum = $this->tainacan_entity_factory->create_entity( - 'metadatum', - array( - 'name' => 'metadado', - 'status' => 'publish', - 'collection' => $collection, - 'metadata_type' => 'Tainacan\Metadata_Types\Text', - ), - true - ); + $metadatum = $this->tainacan_entity_factory->create_entity( + 'metadatum', + array( + 'name' => 'metadado', + 'status' => 'publish', + 'collection' => $collection, + 'metadata_type' => 'Tainacan\Metadata_Types\Text', + ), + true + ); - $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'); + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $i = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'test100', - 'collection' => $collection, - 'status' => 'publish' - ), - true - ); + 'item', + array( + 'title' => 'teste10', + 'collection' => $collection, + 'status' => 'publish' + ), + 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 - $test_query = $Tainacan_Items->fetch([ - 'meta_query' => [ - [ - 'key' => $metadatum->get_id(), - 'value' => ['value_10'], - 'compare' => 'IN' - ] - ] - ], $collection); - $this->assertEquals(1, $test_query->post_count); + $test_query = $Tainacan_Items->fetch([ + 'meta_query' => [ + [ + 'key' => $metadatum->get_id(), + 'value' => ['value_10'], + 'compare' => 'IN' + ] + ] + ], $collection); + $this->assertEquals(1, $test_query->post_count); - } + } - /** - * @group comments - */ - public function test_items_comment() { - $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'collectionComments', - 'allow_comments' => 'closed' - ), - true, - true - ); - $item = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'itemComments1', - 'collection' => $collection, - 'comment_status' => 'open' - ), - true, - true - ); - global $wp_query; + /** + * @group comments + */ + public function test_items_comment() { + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'collectionComments', + 'allow_comments' => 'closed' + ), + true, + true + ); + $item = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'itemComments1', + 'collection' => $collection, + 'comment_status' => 'open' + ), + true, + true + ); + 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(); - $collection->set('allow_comments', 'open'); - $this->assertTrue($collection->validate()); - $collections->update($collection); + $collections = \Tainacan\Repositories\Collections::get_instance(); + $collection->set('allow_comments', 'open'); + $this->assertTrue($collection->validate()); + $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'); - $this->assertTrue($item->validate()); - $items->update($item); + $item->set('comment_status', 'closed'); + $this->assertTrue($item->validate()); + $items->update($item); - $this->assertFalse(comments_open($item->get_id())); - } + $this->assertFalse(comments_open($item->get_id())); + } public function test_delete_item() { $collection = $this->tainacan_entity_factory->create_entity( - 'collection', - array( - 'name' => 'collectionComments', - 'allow_comments' => 'closed' - ), - true, - true - ); - $item = $this->tainacan_entity_factory->create_entity( - 'item', - array( - 'title' => 'itemComments1', - 'collection' => $collection, - 'comment_status' => 'open' - ), - true, - true - ); + 'collection', + array( + 'name' => 'collectionComments', + 'allow_comments' => 'closed' + ), + true, + true + ); + $item = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'title' => 'itemComments1', + 'collection' => $collection, + 'comment_status' => 'open' + ), + true, + true + ); $item_id = $item->get_id();