From 475affd4620c1da28629385ed905d96157f7052e Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 23 Jan 2024 01:10:20 -0300 Subject: [PATCH] php 8.3: fix call function and fix tests --- .../class-tainacan-rest-items-controller.php | 15 ++-- .../entities/class-tainacan-collection.php | 4 +- .../entities/class-tainacan-filter.php | 2 +- src/classes/entities/class-tainacan-item.php | 4 +- .../class-tainacan-bulk-edit-process.php | 2 +- src/classes/importer/class-tainacan-csv.php | 8 +- .../importer/class-tainacan-old-tainacan.php | 24 +++--- .../class-tainacan-mappers-handler.php | 3 +- .../class-tainacan-collections.php | 3 + .../repositories/class-tainacan-metadata.php | 13 ++-- .../class-tainacan-repository.php | 5 +- .../class-tainacan-filter-type.php | 3 +- .../class-tainacan-metadata-type.php | 5 +- tests/__test-bulkedit.php | 2 +- tests/tainacan-unit-api-test-case.php | 10 ++- tests/tainacan-unit-test-case.php | 3 +- tests/test-api-compound-metadata.php | 5 +- tests/test-api-items-submission.php | 7 +- tests/test-api-metadatum-mappers.php | 3 + tests/test-api-private-files.php | 8 +- tests/test-api-roles.php | 2 +- tests/test-api-search.php | 2 +- tests/test-api-sequence-edit.php | 5 +- tests/test-api-visibility-objects.php | 2 +- tests/test-bulkedit-bg-process.php | 78 +++++++++---------- tests/test-capabilities.php | 5 +- tests/test-category-metadatum-types.php | 16 ++-- tests/test-entities.php | 2 +- tests/test-facets.php | 2 +- tests/test-html-injection.php | 2 +- tests/test-importer.php | 4 +- tests/test-item-metadata.php | 6 +- tests/test-relationship-metadatum-types.php | 2 +- 33 files changed, 150 insertions(+), 107 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index fa8d6da2d..d25d70d11 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -1025,7 +1025,8 @@ class REST_Items_Controller extends REST_Controller { 'status' => 'draft' ]; - $body = json_decode($request->get_body(), true); + $data_body = $request->get_body() ?? ''; + $body = json_decode($data_body, true); if (!is_array($body)) { $body = []; @@ -1178,7 +1179,7 @@ class REST_Items_Controller extends REST_Controller { } return $new_term; } - return count($split_value) > 1 ? $value : filter_var($value, FILTER_SANITIZE_STRING); + return count($split_value) > 1 ? $value : htmlspecialchars($value); } private function submission_rollback_new_terms () { @@ -1193,7 +1194,7 @@ class REST_Items_Controller extends REST_Controller { $item = json_decode($request->get_body(), true); $metadata = $item['metadata']; foreach ($item as $key => $value) { - $item[$key] = ( is_string($value) && !is_numeric($value) ? filter_var($value, FILTER_SANITIZE_STRING) : $value ); + $item[$key] = ( is_string($value) && !is_numeric($value) ? htmlspecialchars($value) : $value ); } $response_recaptcha = $this->submission_item_check_recaptcha($request); @@ -1236,7 +1237,7 @@ class REST_Items_Controller extends REST_Controller { $child_value = implode(' ', $child_value); } if (is_numeric($value) != true) { - $child_value = filter_var($child_value, FILTER_SANITIZE_STRING); + $child_value = htmlspecialchars($child_value); } $metadatum_child = $this->metadatum_repository->fetch( $child['metadatum_id'] ); $item_metadata_child = new Entities\Item_Metadata_Entity($item, $metadatum_child, null, $parent_meta_id); @@ -1258,7 +1259,7 @@ class REST_Items_Controller extends REST_Controller { $child_value = implode(' ', $child_value); } if (is_numeric($value) != true) { - $child_value = filter_var($child_value, FILTER_SANITIZE_STRING); + $child_value = htmlspecialchars($child_value); } $metadatum_child = $this->metadatum_repository->fetch( $child['metadatum_id'] ); $item_metadata_child = new Entities\Item_Metadata_Entity($item, $metadatum_child, null, $parent_meta_id); @@ -1291,9 +1292,9 @@ class REST_Items_Controller extends REST_Controller { } } else { if (is_array($value) == true) { - $value = array_map( function($v) { return is_numeric($v) ? $v : filter_var($v, FILTER_SANITIZE_STRING); }, $value); + $value = array_map( function($v) { return is_numeric($v) ? $v : htmlspecialchars($v); }, $value); } else if (is_numeric($value) != true) { - $value = filter_var($value, FILTER_SANITIZE_STRING); + $value = htmlspecialchars($value); } if ($item_metadata->is_multiple()) { $item_metadata->set_value( is_array($value) ? $value : [$value] ); diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index ebd55a1ff..f12ad86ee 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -91,8 +91,8 @@ class Collection extends Entity { $array_collection['header_image'] = $this->get_header_image(); $array_collection['author_name'] = $this->get_author_name(); $array_collection['url'] = $this->get_url(); - $array_collection['creation_date'] = $this->get_date_i18n( explode( ' ', $array_collection['creation_date'] )[0] ); - $array_collection['modification_date'] = $this->get_date_i18n( explode( ' ', $array_collection['modification_date'] )[0] ); + $array_collection['creation_date'] = $this->get_date_i18n( explode( ' ', $array_collection['creation_date'] ?? '' )[0] ); + $array_collection['modification_date'] = $this->get_date_i18n( explode( ' ', $array_collection['modification_date'] ?? '' )[0] ); return apply_filters('tainacan-collection-to-array', $array_collection, $this); } diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php index 76894e2b3..069f8f2a1 100644 --- a/src/classes/entities/class-tainacan-filter.php +++ b/src/classes/entities/class-tainacan-filter.php @@ -140,7 +140,7 @@ class Filter extends Entity { function get_filter_type_object(){ $class_name = $this->get_filter_type(); - if( !class_exists( $class_name ) ){ + if( is_null($class_name) || !class_exists( $class_name ) ){ return null; } diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index b53687063..4c01ef24b 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -56,8 +56,8 @@ class Item extends Entity { $array_item['_thumbnail_id'] = $this->get__thumbnail_id(); $array_item['author_name'] = $this->get_author_name(); $array_item['url'] = get_permalink( $this->get_id() ); - $array_item['creation_date'] = $this->get_date_i18n( explode( ' ', $array_item['creation_date'] )[0] ); - $array_item['modification_date'] = $this->get_date_i18n( explode( ' ', $array_item['modification_date'] )[0] ); + $array_item['creation_date'] = $this->get_date_i18n( explode( ' ', $array_item['creation_date'] ?? '' )[0] ); + $array_item['modification_date'] = $this->get_date_i18n( explode( ' ', $array_item['modification_date'] ?? '' )[0] ); $array_item['document_mimetype'] = $this->get_document_mimetype(); return apply_filters('tainacan-item-to-array', $array_item, $this); } diff --git a/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php b/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php index da570025f..ad6359ede 100644 --- a/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php +++ b/src/classes/generic-background-process/class-tainacan-bulk-edit-process.php @@ -273,7 +273,7 @@ class Bulk_Edit_Process extends Generic_Process { $serealize_erro = (object) array('err' => array()); $erro = $item_metadata->get_errors(); - array_walk_recursive($erro, function($v, $k, &$t) {$t->err[] = $v;}, $serealize_erro); + array_walk_recursive($erro, function($v, $k, $t) {$t->err[] = $v;}, $serealize_erro); $this->add_error_log( __('errors: ', 'tainacan') . implode(", ", $serealize_erro->err) ); return false; diff --git a/src/classes/importer/class-tainacan-csv.php b/src/classes/importer/class-tainacan-csv.php index 5f0537967..d31f72503 100644 --- a/src/classes/importer/class-tainacan-csv.php +++ b/src/classes/importer/class-tainacan-csv.php @@ -5,6 +5,8 @@ use Tainacan; use Tainacan\Entities; class CSV extends Importer { + private $items_repo; + public function __construct($attributes = array()) { parent::__construct($attributes); $this->items_repo = \Tainacan\Repositories\Items::get_instance(); @@ -487,7 +489,7 @@ class CSV extends Importer { case 'utf8': return $string; case 'iso88591': - return utf8_encode($string); + return mb_convert_encoding($string, 'UTF-8', 'ISO-8859-1'); default: return $string; } @@ -1089,11 +1091,11 @@ class CSV extends Importer { $author = $current_user->user_login; $message = __('imported file:', 'tainacan'); - $message .= " ${imported_file}
"; + $message .= " $imported_file
"; $message .= __('target collections:', 'tainacan'); $message .= " " . implode(", ", $this->get_collections_names() ) . "
"; $message .= __('Imported by:', 'tainacan'); - $message .= " ${author}
"; + $message .= " $author
"; return $message; } diff --git a/src/classes/importer/class-tainacan-old-tainacan.php b/src/classes/importer/class-tainacan-old-tainacan.php index ee9e56ee4..fbbd62809 100644 --- a/src/classes/importer/class-tainacan-old-tainacan.php +++ b/src/classes/importer/class-tainacan-old-tainacan.php @@ -3,7 +3,14 @@ namespace Tainacan\Importer; use \Tainacan\Entities; -class Old_Tainacan extends Importer{ +class Old_Tainacan extends Importer { + + protected $tax_repo; + protected $col_repo; + protected $items_repo; + protected $metadata_repo; + protected $term_repo; + protected $item_metadata_repo; protected $steps = [ [ @@ -443,7 +450,7 @@ class Old_Tainacan extends Importer{ $info = $this->requester( $this->get_url() . $this->tainacan_api_address . "/collections/".$collection_id."/items", $args ); if( !isset($info['body']) ){ - $this->add_error_log($result->get_error_message()); + $this->add_error_log($info->get_error_message()); $this->add_error_log('Error in fetch remote total items'); $this->abort(); return false; @@ -474,7 +481,7 @@ class Old_Tainacan extends Importer{ $info = wp_remote_get( $this->get_url() . $this->tainacan_api_address . "/collections/".$collection_id."/items?includeMetadata=1&filter[page]=" . $page, $args ); if( !isset($info['body']) ){ - $this->add_error_log($result->get_error_message()); + $this->add_error_log($info->get_error_message()); $this->add_error_log('Error in fetch remote first page item'); $this->abort(); return false; @@ -493,7 +500,7 @@ class Old_Tainacan extends Importer{ $info = json_decode($info['body']); if( !isset($info['body']) ){ - $this->add_error_log($result->get_error_message()); + $this->add_error_log($info->get_error_message()); $this->add_error_log('Error in fetch remote ' . $page . ' page item'); $this->abort(); return false; @@ -613,7 +620,7 @@ class Old_Tainacan extends Importer{ if (is_wp_error($result)) { $this->add_log($result->get_error_message()); - $this->add_log('Error in fetch remote' . $url); + $this->add_log('Error in fetch remote' . $link); $this->add_log('request number ' . $requests); } else if (isset($result['body'])){ @@ -644,7 +651,7 @@ class Old_Tainacan extends Importer{ - $this->add_error_log('Error in fetch remote, expired the 10 requests limit ' . $url); + $this->add_error_log('Error in fetch remote, expired the 10 requests limit ' . $link); $this->abort(); return false; } @@ -713,10 +720,9 @@ class Old_Tainacan extends Importer{ * @return int $metadatum_id */ protected function create_metadata( $node_metadata_old, $collection_id = null){ - $this->add_log('Creating metadata' . $meta->name); - $newMetadatum = new Entities\Metadatum(); $meta = $node_metadata_old; + $this->add_log('Creating metadata' . $meta->name); $name = $meta->name; $type = $this->define_type($meta->type); @@ -856,7 +862,7 @@ class Old_Tainacan extends Importer{ /** * create attachments, document and thumb from old * - * @param string $node_old + * @param Object $node_old * * @return string the class name */ diff --git a/src/classes/mappers/class-tainacan-mappers-handler.php b/src/classes/mappers/class-tainacan-mappers-handler.php index 3868c338c..8a8e8b41b 100644 --- a/src/classes/mappers/class-tainacan-mappers-handler.php +++ b/src/classes/mappers/class-tainacan-mappers-handler.php @@ -137,7 +137,8 @@ class Mappers_Handler { * @return Mappers\Mapper|boolean false */ public static function get_mapper_from_request($request) { - $body = json_decode( $request->get_body(), true ); + $data_body = $request->get_body() ?? ''; + $body = json_decode( $data_body, true ); $Tainacan_Mappers = self::get_instance(); $query_url_params = $request->get_query_params(); diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index f6f35cb75..8a39617cd 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -13,6 +13,9 @@ class Collections extends Repository { public $entities_type = '\Tainacan\Entities\Collection'; private static $instance = null; + private $old_collection; + private $old_core_title; + private $old_core_description; public static function get_instance() { if ( ! isset( self::$instance ) ) { diff --git a/src/classes/repositories/class-tainacan-metadata.php b/src/classes/repositories/class-tainacan-metadata.php index 2ed0969c9..f09c56672 100644 --- a/src/classes/repositories/class-tainacan-metadata.php +++ b/src/classes/repositories/class-tainacan-metadata.php @@ -14,6 +14,7 @@ use \Respect\Validation\Validator as v; class Metadata extends Repository { public $entities_type = '\Tainacan\Entities\Metadatum'; protected $default_metadata = 'default'; + protected $current_taxonomy; public $metadata_types = []; @@ -1384,7 +1385,7 @@ class Metadata extends Repository { } } - $number = ctype_digit($args['number']) && $args['number'] >=1 ? $args['number'] : $total; + $number = ctype_digit((string)$args['number']) && $args['number'] >=1 ? $args['number'] : $total; if( $number < 1){ $pages = 1; } else { @@ -1401,8 +1402,10 @@ class Metadata extends Repository { $total_items = null; if ( $args['count_items'] ) { - $count_items_query = $args['items_filter']; - $count_items_query['posts_per_page'] = 1; + $count_items_query = array( + 'posts_per_page' => 1 + ); + $count_items_query = array_merge($args['items_filter'] != false ? $args['items_filter'] : [], $count_items_query); if ( !isset($count_items_query['tax_query']) ) { $count_items_query['tax_query'] = []; } @@ -1448,7 +1451,7 @@ class Metadata extends Repository { $results = $wpdb->get_col($query); $total = $wpdb->get_var($total_query); - $number = ctype_digit($args['number']) && $args['number'] >=1 ? $args['number'] : $total; + $number = ctype_digit((string)$args['number']) && $args['number'] >=1 ? $args['number'] : $total; if( $number < 1){ $pages = 1; } else { @@ -1485,7 +1488,7 @@ class Metadata extends Repository { if ( $args['count_items'] ) { $count_items_query = $args['items_filter']; - $count_items_query['posts_per_page'] = 1; + $count_items_query['posts_per_page'] = (int)1; if ( !isset($count_items_query['meta_query']) ) { $count_items_query['meta_query'] = []; } diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index 7b732687b..b99e92ba8 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -941,7 +941,10 @@ abstract class Repository { } protected function sanitize_value($content) { - if (is_numeric($content) || empty($content) ) { + if( $content == null ) { + return ''; + } + if (is_numeric($content) || empty($content ) ) { return $content; } diff --git a/src/views/admin/components/filter-types/filter-type/class-tainacan-filter-type.php b/src/views/admin/components/filter-types/filter-type/class-tainacan-filter-type.php index 3d705754e..dcbad26c4 100644 --- a/src/views/admin/components/filter-types/filter-type/class-tainacan-filter-type.php +++ b/src/views/admin/components/filter-types/filter-type/class-tainacan-filter-type.php @@ -142,7 +142,8 @@ abstract class Filter_Type { /** * @param $options */ - public function set_options( $options ){ + public function set_options( $options ) { + $options = $options ?? ''; $this->options = ( is_array( $options ) ) ? $options : (!is_array(unserialize( $options )) ? [] : unserialize( $options )); } diff --git a/src/views/admin/components/metadata-types/metadata-type/class-tainacan-metadata-type.php b/src/views/admin/components/metadata-types/metadata-type/class-tainacan-metadata-type.php index 8bc3925c5..ee3f24cbe 100644 --- a/src/views/admin/components/metadata-types/metadata-type/class-tainacan-metadata-type.php +++ b/src/views/admin/components/metadata-types/metadata-type/class-tainacan-metadata-type.php @@ -174,8 +174,9 @@ abstract class Metadata_Type { /** * @param $options */ - public function set_options( $options ){ - $this->options = ( is_array( $options ) ) ? $options : (!is_array(unserialize( $options )) ? [] : unserialize( $options )); + public function set_options( $options ) { + $options = $options ?? ''; + $this->options = ( is_array( $options ) ) ? $options : (!is_array(unserialize( $options )) ? [] : unserialize( $options )); } public function set_default_options(Array $options) { diff --git a/tests/__test-bulkedit.php b/tests/__test-bulkedit.php index c30e15080..1546b7ff3 100644 --- a/tests/__test-bulkedit.php +++ b/tests/__test-bulkedit.php @@ -20,7 +20,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase { public $items_ids = []; - function setUp() { + function setUp(): void { parent::setUp(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/tainacan-unit-api-test-case.php b/tests/tainacan-unit-api-test-case.php index 31143bea8..b7b3fb2df 100644 --- a/tests/tainacan-unit-api-test-case.php +++ b/tests/tainacan-unit-api-test-case.php @@ -20,7 +20,15 @@ class TAINACAN_UnitApiTestCase extends TAINACAN_UnitTestCase { */ protected $namespace = '/tainacan/v2'; - public function setUp(){ + public $collection; + public $metadatum; + public $item; + public $multiple_meta; + public $taxonomy; + public $category; + public $api_baseroute; + + public function setUp() : void{ parent::setUp(); global $wp_rest_server; diff --git a/tests/tainacan-unit-test-case.php b/tests/tainacan-unit-test-case.php index edfefe085..6fba4b85c 100644 --- a/tests/tainacan-unit-test-case.php +++ b/tests/tainacan-unit-test-case.php @@ -4,6 +4,7 @@ namespace Tainacan\Tests; use Tainacan\Tests\Factories; +#[\AllowDynamicProperties] class TAINACAN_UnitTestCase extends \WP_UnitTestCase { protected $tainacan_entity_factory; protected $tainacan_metadatum_factory; @@ -11,7 +12,7 @@ class TAINACAN_UnitTestCase extends \WP_UnitTestCase { protected $tainacan_item_metadata_factory; protected $user_id; - public function setUp(){ + public function setUp(): void { parent::setUp(); $this->tainacan_entity_factory = new Factories\Entity_Factory(); $this->tainacan_metadatum_factory = new Factories\Metadatum_Factory(); diff --git a/tests/test-api-compound-metadata.php b/tests/test-api-compound-metadata.php index 9aded3980..c12c2a587 100644 --- a/tests/test-api-compound-metadata.php +++ b/tests/test-api-compound-metadata.php @@ -7,7 +7,10 @@ namespace Tainacan\Tests; */ class TAINACAN_REST_Compound_Metadata_Controller extends TAINACAN_UnitApiTestCase { - function setUp() { + public $collection; + public $item; + + function setUp(): void { parent::setUp(); $this->collection = $this->tainacan_entity_factory->create_entity( diff --git a/tests/test-api-items-submission.php b/tests/test-api-items-submission.php index 68ff40911..bb0a660d9 100644 --- a/tests/test-api-items-submission.php +++ b/tests/test-api-items-submission.php @@ -6,8 +6,11 @@ namespace Tainacan\Tests; * @group api */ class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase { - - function setUp() { + private $col_user_anonymous; + private $col_user_logged; + private $collections_metadatum; + + function setUp(): void { parent::setUp(); // collections: diff --git a/tests/test-api-metadatum-mappers.php b/tests/test-api-metadatum-mappers.php index bf1d82a7a..6a5e9cc71 100644 --- a/tests/test-api-metadatum-mappers.php +++ b/tests/test-api-metadatum-mappers.php @@ -7,6 +7,9 @@ namespace Tainacan\Tests; */ class TAINACAN_REST_Metadatum_Mappers_Controller extends TAINACAN_UnitApiTestCase { + private $metadatum2; + private $metadatum3; + protected function create_meta_requirements() { $collection = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/test-api-private-files.php b/tests/test-api-private-files.php index a8b18301b..619314995 100644 --- a/tests/test-api-private-files.php +++ b/tests/test-api-private-files.php @@ -7,6 +7,8 @@ namespace Tainacan\Tests; */ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase { + public $test_file; + public function test_create_item() { $orig_file = './tests/attachment/codeispoetrywp.jpg'; @@ -58,8 +60,7 @@ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase { $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'] ); + $this->assertStringStartsWith( $folder, $attachment_data['file'] ); } function test_internal_api() { @@ -91,8 +92,7 @@ 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'] ); + $this->assertStringStartsWith( $folder, $attachment_data['file'] ); } } diff --git a/tests/test-api-roles.php b/tests/test-api-roles.php index e95ddd2b6..7716e0736 100644 --- a/tests/test-api-roles.php +++ b/tests/test-api-roles.php @@ -7,7 +7,7 @@ namespace Tainacan\Tests; * */ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { - public function setUp() { + public function setUp(): void { parent::setUp(); // reset WP_Roles object. Possible bug was cleaning database between tests, but not the object global $wpdb; diff --git a/tests/test-api-search.php b/tests/test-api-search.php index c48c4a053..ef4e8fccb 100644 --- a/tests/test-api-search.php +++ b/tests/test-api-search.php @@ -6,7 +6,7 @@ namespace Tainacan\Tests; * @group api * **/ class TAINACAN_REST_Search extends TAINACAN_UnitApiTestCase { - function setUp() { + function setUp(): void { parent::setUp(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); diff --git a/tests/test-api-sequence-edit.php b/tests/test-api-sequence-edit.php index 29596b566..cd1c1b298 100644 --- a/tests/test-api-sequence-edit.php +++ b/tests/test-api-sequence-edit.php @@ -10,8 +10,11 @@ use Tainacan\Entities; class SequenceEdit extends TAINACAN_UnitApiTestCase { public $items_ids = []; + public $collection; + public $metadatum; + public $api_baseroute; - function setUp() { + function setUp(): void { parent::setUp(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/test-api-visibility-objects.php b/tests/test-api-visibility-objects.php index 6625e0ba6..5db617875 100644 --- a/tests/test-api-visibility-objects.php +++ b/tests/test-api-visibility-objects.php @@ -31,7 +31,7 @@ class TAINACAN_REST_Visibilility_Controller extends TAINACAN_UnitApiTestCase { public $term_public; public $term_private; - function setUp() { + function setUp(): void { parent::setUp(); $taxonomy_public = $this->tainacan_entity_factory->create_entity( diff --git a/tests/test-bulkedit-bg-process.php b/tests/test-bulkedit-bg-process.php index c814a1468..7de960063 100644 --- a/tests/test-bulkedit-bg-process.php +++ b/tests/test-bulkedit-bg-process.php @@ -17,7 +17,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { public $items_ids = []; - function setUp() { + function setUp(): void { parent::setUp(); $collection = $this->tainacan_entity_factory->create_entity( 'collection', @@ -263,7 +263,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -310,7 +310,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); //$bulk->add_value($this->multiple_meta, 'super'); @@ -383,7 +383,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'tax_query' => [ @@ -431,7 +431,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $query = [ 'meta_query' => [ @@ -456,7 +456,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -500,7 +500,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -570,7 +570,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -632,7 +632,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ]); $this->assertEquals(0, $items->found_posts); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'meta_query' => [ @@ -676,7 +676,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->category->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $process = $this->new_process( [ @@ -690,7 +690,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->category->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); // should add super only to the 20 items that had test $items = $Tainacan_Items->fetch([ @@ -741,7 +741,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->metadatum->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); // should add super only to the 20 items that had even @@ -794,7 +794,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { ] ); // all items selected, search and replace the value of one - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'meta_query' => [ @@ -839,7 +839,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->category->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'tax_query' => [ @@ -910,7 +910,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->metadatum->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'meta_query' => [ @@ -967,7 +967,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1002,7 +1002,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->multiple_meta->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $process = $this->new_process( [ @@ -1015,7 +1015,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->multiple_meta->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $ids = array_slice($this->items_ids, 2, 7); @@ -1032,7 +1032,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->multiple_meta->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); @@ -1095,7 +1095,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $core_title->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $process = $this->new_process( [ @@ -1108,7 +1108,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $core_description->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'meta_query' => [ @@ -1171,7 +1171,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); @@ -1219,7 +1219,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $trashed = $Tainacan_Items->fetch_ids(['post_status' => 'trash', 'posts_per_page' => -1]); $rest = $Tainacan_Items->fetch_ids(['posts_per_page' => -1]); @@ -1238,7 +1238,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $trashed = $Tainacan_Items->fetch_ids(['post_status' => 'trash', 'posts_per_page' => -1]); $private = $Tainacan_Items->fetch_ids(['post_status' => 'private', 'posts_per_page' => -1]); @@ -1272,7 +1272,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch_ids(['posts_per_page' => -1]); $this->assertEquals(40, sizeof($items), 'Items must be on trash to be deleted'); @@ -1288,7 +1288,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $process = $this->new_process( @@ -1302,7 +1302,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $trashed = $Tainacan_Items->fetch_ids(['post_status' => 'trash', 'posts_per_page' => -1]); @@ -1341,7 +1341,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->category->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1369,7 +1369,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->category->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1430,7 +1430,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $category2->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1458,7 +1458,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $category2->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1550,7 +1550,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->category->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1634,7 +1634,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->metadatum->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); // single valued metadatum dont accept array $items = $Tainacan_Items->fetch([ @@ -1672,7 +1672,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => $this->multiple_meta->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ @@ -1730,7 +1730,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $query = [ @@ -1756,7 +1756,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id" => null, ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $items = $Tainacan_Items->fetch([ 'comment_status' => 'closed', @@ -1822,7 +1822,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id_from" => $this->metadatum->get_id(), ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $query = [ 'meta_query' => [ @@ -1847,7 +1847,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id_from" => 'created_by', ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $query = [ 'meta_query' => [ [ @@ -1897,7 +1897,7 @@ class BulkEditBgProcess extends TAINACAN_UnitApiTestCase { "metadatum_id_from" => $this->category->get_id() ] ); - $this->assertInternalType('int', $this->run_process($process)); + $this->assertIsInt($this->run_process($process)); $query = [ diff --git a/tests/test-capabilities.php b/tests/test-capabilities.php index 4f6af23b0..59acbbefa 100644 --- a/tests/test-capabilities.php +++ b/tests/test-capabilities.php @@ -13,9 +13,10 @@ use Tainacan\Entities\Collection; /** * @group permissions */ +#[\AllowDynamicProperties] class Capabilities extends TAINACAN_UnitTestCase { - function setUp() { + function setUp(): void { parent::setUp(); /** @@ -857,7 +858,7 @@ class Capabilities extends TAINACAN_UnitTestCase { } /** - * @group collectionss + * @group collections */ function test_manage_collection_can_edit_collection() { global $current_user; diff --git a/tests/test-category-metadatum-types.php b/tests/test-category-metadatum-types.php index 37c7d7bef..48324bb7d 100644 --- a/tests/test-category-metadatum-types.php +++ b/tests/test-category-metadatum-types.php @@ -127,7 +127,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $this->assertFalse($metadatum2->validate(), 'Taxonomy Metadatum should not validate when using a taxonomy in use by another metadatum in the same collection'); $errors = $metadatum2->get_errors(); - $this->assertInternalType('array', $errors); + $this->assertIsArray($errors); $this->assertArrayHasKey('taxonomy_id', $errors[0]['metadata_type_options']); } @@ -193,7 +193,7 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $checkTax = $Tainacan_Taxonomies->fetch($tax->get_id()); - $this->assertContains($collection->get_id(), $checkTax->get_collections_ids(), 'Collection must be added to taxonomy when metadatum is created'); + $this->assertContains((string)$collection->get_id(), $checkTax->get_collections_ids(), 'Collection must be added to taxonomy when metadatum is created'); $metadatum->set_metadata_type_options([ @@ -206,14 +206,14 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $checkTax = $Tainacan_Taxonomies->fetch($tax->get_id()); $checkTax2 = $Tainacan_Taxonomies->fetch($tax2->get_id()); - $this->assertContains($collection->get_id(), $checkTax2->get_collections_ids(), 'Collection must be added to taxonomy when metadatum is updated'); - $this->assertNotContains($collection->get_id(), $checkTax->get_collections_ids(), 'Collection must be removed from taxonomy when metadatum is updated'); + $this->assertContains((string)$collection->get_id(), $checkTax2->get_collections_ids(), 'Collection must be added to taxonomy when metadatum is updated'); + $this->assertNotContains((string)$collection->get_id(), $checkTax->get_collections_ids(), 'Collection must be removed from taxonomy when metadatum is updated'); $metadatum = $Tainacan_Metadata->trash($metadatum); $checkTax2 = $Tainacan_Taxonomies->fetch($tax2->get_id()); - $this->assertNotContains($collection->get_id(), $checkTax2->get_collections_ids(), 'Collection must be removed from taxonomy when metadatum is deleted'); + $this->assertNotContains((string)$collection->get_id(), $checkTax2->get_collections_ids(), 'Collection must be removed from taxonomy when metadatum is deleted'); $metadatum_repo = $this->tainacan_entity_factory->create_entity( @@ -590,10 +590,10 @@ class TaxonomyMetadatumTypes extends TAINACAN_UnitTestCase { $meta = $Tainacan_ItemMetadata->insert($meta); - $this->assertInternalType( 'string', $meta->get_value_as_html() ); - $this->assertInternalType( 'string', $meta->get_value_as_string() ); + $this->assertIsString( $meta->get_value_as_html() ); + $this->assertIsString( $meta->get_value_as_string() ); - $this->assertInternalType( 'integer', strpos($meta->get_value_as_html(), 'assertIsInt( strpos($meta->get_value_as_html(), 'assertFalse( strpos($meta->get_value_as_string(), 'collection = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/test-facets.php b/tests/test-facets.php index 3c30a9b5d..dc6afc8c4 100644 --- a/tests/test-facets.php +++ b/tests/test-facets.php @@ -79,7 +79,7 @@ class Facets extends TAINACAN_UnitApiTestCase { * */ - function setUp() { + function setUp() : void{ parent::setUp(); $collection1 = $this->tainacan_entity_factory->create_entity( 'collection', diff --git a/tests/test-html-injection.php b/tests/test-html-injection.php index bf0ce6bec..5e6e42c0c 100644 --- a/tests/test-html-injection.php +++ b/tests/test-html-injection.php @@ -35,7 +35,7 @@ class TAINACAN_HTML_Injection extends TAINACAN_UnitTestCase private $taxonomy = null; private $taxonomy_db = null; - public function setUp() + public function setUp(): void { parent::setUp(); $link = $this->link; diff --git a/tests/test-importer.php b/tests/test-importer.php index 98d1230c2..17b147502 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -282,7 +282,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { having multiple lines', 'Data 24', 'Data 25'), - array(get_current_user_id(), 'Data 31', 'Data 32', utf8_decode( 'Data 33||Rééço' ), 'Data 34', 'Data 35'), + array(get_current_user_id(), 'Data 31', 'Data 32', mb_convert_encoding('Data 33||Rééço', 'UTF-8', 'ISO-8859-1'), 'Data 34', 'Data 35'), array(get_current_user_id(), 'Data 41', 'Data 42', 'Data 43||limbbo', 'Data 44', 'Data 45'), array(get_current_user_id(), 'Data 51', 'Data 52', 'Data 53', 'Data 54', 'Data 55>>DATA551') ); @@ -447,7 +447,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { array( 'Data 31', '458', - utf8_decode( 'Data 33||Rééço' ), + mb_convert_encoding( 'Data 33||Rééço', 'ISO-8859-1', 'UTF-8' ), 'https://www.codeproject.com/KB/GDI-plus/ImageProcessing2/img.jpg||https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/58f72418-b5ee-4765-8e80-e463623a921d/01-httparchive-opt-small.png', 'file:https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg'), array('Data 41', '459', 'Data 43||limbbo', 'photos/SamplePNGImage_100kbmb.png||audios/SampleAudio_0.4mb.mp3', 'url:http://www.pdf995.com/samples/pdf.pdf'), diff --git a/tests/test-item-metadata.php b/tests/test-item-metadata.php index 08da5f707..d9bb1eba4 100644 --- a/tests/test-item-metadata.php +++ b/tests/test-item-metadata.php @@ -19,7 +19,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { private $item = null; private $separator = ' | '; - public function setUp() { + public function setUp(): void { parent::setUp(); $c = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'My Collection'], true); $i = $this->tainacan_entity_factory->create_entity( @@ -652,7 +652,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { $relationship_metadata->set_multiple('yes'); $item_metadata_relationship->set_value([ $mystify->get_id(), $disappear->get_id() ]); - $this->assertEquals($item_metadata_relationship->get_value_as_html(), "${expected_return}" . $this->separator . "${expected_return2}"); + $this->assertEquals($item_metadata_relationship->get_value_as_html(), "$expected_return" . $this->separator . "$expected_return2"); } function test_taxonomy_metadata_html() { @@ -760,7 +760,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase { private function relationship_expected_return($id, $title) { $URL = get_permalink($id); - return "${title}"; + return "$title"; } function test_multiple_with_cardinality() { diff --git a/tests/test-relationship-metadatum-types.php b/tests/test-relationship-metadatum-types.php index 296a449e0..8b1912a3b 100644 --- a/tests/test-relationship-metadatum-types.php +++ b/tests/test-relationship-metadatum-types.php @@ -19,7 +19,7 @@ class RelationshipMetadatumTypes extends TAINACAN_UnitTestCase { private $collection_book = null; private $collection_article = null; - public function setUp() { + public function setUp(): void { parent::setUp(); $this->collection_book = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'Book', 'status' => 'publish'], true); $this->collection_author = $this->tainacan_entity_factory->create_entity('collection', ['name' => 'Author', 'status' => 'publish'], true);