php 8.3: fix call function and fix tests

This commit is contained in:
vnmedeiros 2024-01-23 01:10:20 -03:00
parent 368b8d81a0
commit 475affd462
33 changed files with 150 additions and 107 deletions

View File

@ -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] );

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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 .= " <b> ${imported_file} </b><br/>";
$message .= " <b> $imported_file </b><br/>";
$message .= __('target collections:', 'tainacan');
$message .= " <b>" . implode(", ", $this->get_collections_names() ) . "</b><br/>";
$message .= __('Imported by:', 'tainacan');
$message .= " <b> ${author} </b><br/>";
$message .= " <b> $author </b><br/>";
return $message;
}

View File

@ -5,6 +5,13 @@ use \Tainacan\Entities;
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 = [
[
'name' => 'Create Taxonomies',
@ -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
*/

View File

@ -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();

View File

@ -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 ) ) {

View File

@ -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'] = [];
}

View File

@ -941,6 +941,9 @@ abstract class Repository {
}
protected function sanitize_value($content) {
if( $content == null ) {
return '';
}
if (is_numeric($content) || empty($content ) ) {
return $content;
}

View File

@ -143,6 +143,7 @@ abstract class Filter_Type {
* @param $options
*/
public function set_options( $options ) {
$options = $options ?? '';
$this->options = ( is_array( $options ) ) ? $options : (!is_array(unserialize( $options )) ? [] : unserialize( $options ));
}

View File

@ -175,6 +175,7 @@ abstract class Metadata_Type {
* @param $options
*/
public function set_options( $options ) {
$options = $options ?? '';
$this->options = ( is_array( $options ) ) ? $options : (!is_array(unserialize( $options )) ? [] : unserialize( $options ));
}

View File

@ -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',

View File

@ -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;

View File

@ -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();

View File

@ -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(

View File

@ -6,8 +6,11 @@ namespace Tainacan\Tests;
* @group api
*/
class TAINACAN_REST_Items_Submission extends TAINACAN_UnitApiTestCase {
private $col_user_anonymous;
private $col_user_logged;
private $collections_metadatum;
function setUp() {
function setUp(): void {
parent::setUp();
// collections:

View File

@ -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',

View File

@ -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'] );
}
}

View File

@ -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;

View File

@ -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();

View File

@ -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',

View File

@ -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(

View File

@ -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 = [

View File

@ -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;

View File

@ -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(), '<a ') );
$this->assertIsInt( strpos($meta->get_value_as_html(), '<a ') );
$this->assertFalse( strpos($meta->get_value_as_string(), '<a ') );

View File

@ -14,7 +14,7 @@ namespace Tainacan\Tests;
class TestEntities extends TAINACAN_UnitTestCase {
function setUp() {
function setUp(): void {
parent::setUp();
$this->collection = $this->tainacan_entity_factory->create_entity(
'collection',

View File

@ -79,7 +79,7 @@ class Facets extends TAINACAN_UnitApiTestCase {
*
*/
function setUp() {
function setUp() : void{
parent::setUp();
$collection1 = $this->tainacan_entity_factory->create_entity(
'collection',

View File

@ -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;

View File

@ -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'),

View File

@ -19,7 +19,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
private $item = null;
private $separator = '<span class="multivalue-separator"> | </span>';
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 "<a data-linkto='item' data-id='${id}' href='${URL}'>${title}</a>";
return "<a data-linkto='item' data-id='$id' href='$URL'>$title</a>";
}
function test_multiple_with_cardinality() {

View File

@ -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);