From a3a239a4350e408f76a1ed05e972656ee67eeac2 Mon Sep 17 00:00:00 2001 From: weryques Date: Wed, 4 Apr 2018 10:47:31 -0300 Subject: [PATCH] Fixes enabled of fields and fetch of logs --- .../class-tainacan-collections.php | 38 +++++++++---------- .../repositories/class-tainacan-fields.php | 4 +- .../repositories/class-tainacan-logs.php | 4 +- tests/test-api-logs.php | 5 ++- tests/test-fields.php | 6 +-- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index df2b32165..0c9302b57 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -12,25 +12,23 @@ use Tainacan\Entities\Collection; class Collections extends Repository { public $entities_type = '\Tainacan\Entities\Collection'; - private static $instance = null; + private static $instance = null; - public static function getInstance() - { - if(!isset(self::$instance)) - { - self::$instance = new self(); - } + public static function getInstance() { + if ( ! isset( self::$instance ) ) { + self::$instance = new self(); + } - return self::$instance; - } + return self::$instance; + } - /** - * Collections constructor. - */ - protected function __construct() { - parent::__construct(); - add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 10, 4 ); - } + /** + * Collections constructor. + */ + protected function __construct() { + parent::__construct(); + add_filter( 'map_meta_cap', array( $this, 'map_meta_cap' ), 10, 4 ); + } /** * {@inheritDoc} @@ -138,16 +136,16 @@ class Collections extends Repository { 'fields_order' => [ 'map' => 'meta', 'title' => __( 'Ordination fields', 'tainacan' ), - 'type' => 'array/object/string', - 'items' => ['type' => 'array/string/integer/object'], + 'type' => 'array/object/string', + 'items' => [ 'type' => 'array/string/integer/object' ], 'description' => __( 'Collection fields ordination', 'tainacan' ), //'validation' => v::stringType(), ], 'filters_order' => [ 'map' => 'meta', 'title' => __( 'Ordination filters', 'tainacan' ), - 'type' => 'array/object/string', - 'items' => ['type' => 'array/string/integer/object'], + 'type' => 'array/object/string', + 'items' => [ 'type' => 'array/string/integer/object' ], 'description' => __( 'Collection filters ordination', 'tainacan' ), //'validation' => v::stringType(), ], diff --git a/src/classes/repositories/class-tainacan-fields.php b/src/classes/repositories/class-tainacan-fields.php index 18f1ad4f8..002ea54ad 100644 --- a/src/classes/repositories/class-tainacan-fields.php +++ b/src/classes/repositories/class-tainacan-fields.php @@ -386,11 +386,11 @@ class Fields extends Repository { if( $index !== false ) { // skipping fields disabled if the arg is set - if( !$include_disabled && isset( $order[$index]['enable'] ) && !$order[$index]['enable'] ) { + if( !$include_disabled && isset( $order[$index]['enabled'] ) && !$order[$index]['enabled'] ) { continue; } - $enable = ( isset( $order[$index]['enable'] )) ? $order[$index]['enable'] : true; + $enable = ( isset( $order[$index]['enabled'] )) ? $order[$index]['enabled'] : true; $item->set_enabled_for_collection($enable); $result_ordinate[$index] = $item; diff --git a/src/classes/repositories/class-tainacan-logs.php b/src/classes/repositories/class-tainacan-logs.php index b4fce08e6..1686880da 100644 --- a/src/classes/repositories/class-tainacan-logs.php +++ b/src/classes/repositories/class-tainacan-logs.php @@ -186,7 +186,7 @@ class Logs extends Repository { } elseif ( is_array( $args ) ) { $args = array_merge( [ - 'posts_per_page' => 1, + 'posts_per_page' => -1, ], $args ); $args = $this->parse_fetch_args( $args ); @@ -210,7 +210,7 @@ class Logs extends Repository { public function fetch_last() { $args = [ 'post_type' => Entities\Log::get_post_type(), - 'posts_per_page' => 1, + 'posts_per_page' => -1, ]; $logs = $this->fetch( $args, 'OBJECT' ); diff --git a/tests/test-api-logs.php b/tests/test-api-logs.php index 5dfdbfb46..0fd20684c 100644 --- a/tests/test-api-logs.php +++ b/tests/test-api-logs.php @@ -36,8 +36,9 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_UnitApiTestCase { $data = $response->get_data(); - $this->assertEquals('Log 1', $data[1]['title']); - $this->assertEquals('Log 2', $data[0]['title']); + $log_titles = [$data[1]['title'], $data[0]['title']]; + $this->assertContains('Log 1', $log_titles); + $this->assertContains('Log 2', $log_titles); } public function test_get_a_log(){ diff --git a/tests/test-fields.php b/tests/test-fields.php index 7d947ab44..a6e2abfb2 100644 --- a/tests/test-fields.php +++ b/tests/test-fields.php @@ -252,9 +252,9 @@ class Fields extends TAINACAN_UnitTestCase { $collection->set_fields_order( [ - array( 'id' => $field3->get_id(), 'enable' => false ), - array( 'id' => $field2->get_id(), 'enable' => true ), - array( 'id' => $field1->get_id(), 'enable' => true ) + array( 'id' => $field3->get_id(), 'enabled' => false ), + array( 'id' => $field2->get_id(), 'enabled' => true ), + array( 'id' => $field1->get_id(), 'enabled' => true ) ]); $update_collection = $Tainacan_Collections->update( $collection );