Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-864: Resolve PHP Deprecations #866

Merged
merged 18 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"scripts": {
"phpcs": "vendor/bin/phpcs",
"phpcbf": "vendor/bin/phpcbf",
"phpunit": "vendor/bin/phpunit"
},
"config": {
Expand Down
4 changes: 3 additions & 1 deletion php/class-fieldmanager-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ public function presave_all( $values, $current_values ) {
function( $value ) {
if ( is_array( $value ) ) {
return ! empty( $value );
} elseif ( null === $value ) {
return $value;
} else {
return strlen( $value );
}
Expand Down Expand Up @@ -1117,7 +1119,7 @@ public function presave( $value, $current_value = array() ) {
);
}
}
return call_user_func( $this->sanitize, $value );
return ( null !== $value ) ? call_user_func( $this->sanitize, $value ) : null;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions php/class-fieldmanager-group.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ public function presave( $values, $current_values = array() ) {
if ( empty( $values[ $element->name ] ) ) {
unset( $values[ $element->name ] );
}
} elseif ( null === $values[ $element->name ] ) {
unset( $values[ $element->name ] );
} elseif ( ! strlen( $values[ $element->name ] ) ) {
unset( $values[ $element->name ] );
}
Expand Down
7 changes: 7 additions & 0 deletions php/class-fieldmanager-richtextarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class Fieldmanager_RichTextArea extends Fieldmanager_Field {
*/
protected $edit_config = false;

/**
* The default value for the field, if unset.
*
* @var mixed Default value
*/
public $default_value = '';

/**
* Construct defaults for this field.
*
Expand Down
7 changes: 7 additions & 0 deletions php/datasource/class-fieldmanager-datasource-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ class Fieldmanager_Datasource_Post extends Fieldmanager_Datasource {
*/
public $only_save_to_post_parent = false;

/**
* Used internally.
*
* @var mixed
*/
private $_fragment; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

/**
* Construct the object.
*
Expand Down
1 change: 0 additions & 1 deletion tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ function _fm_phpunit_is_wp_at_least( $min_version ) {
// Load includes.
require_once __DIR__ . '/includes/class-fieldmanager-assets-unit-test-case.php';
require_once __DIR__ . '/includes/class-fieldmanager-options-mock.php';
require_once __DIR__ . '/includes/class-fieldmanager-deprecation-exception.php';

This file was deleted.

27 changes: 27 additions & 0 deletions tests/php/test-fieldmanager-autocomplete-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@
* @group autocomplete
*/
class Test_Fieldmanager_Autocomplete_Field extends WP_UnitTestCase {
/**
* The post ID of the test post.
*
* @var int
*/
private int $post_id = 0;

/**
* The post object of the test post.
*
* @var WP_Post
*/
private WP_Post $post;

/**
* The data posts array.
*
* @var WP_Post[]
*/
private array $data_posts;

/**
* Custom data source.
*
* @var Fieldmanager_Datasource
*/
private Fieldmanager_Datasource $custom_datasource;

public function set_up() {
parent::set_up();
Expand Down
6 changes: 6 additions & 0 deletions tests/php/test-fieldmanager-checkbox-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
* @group checkbox
*/
class Test_Fieldmanager_Checkbox_Field extends WP_UnitTestCase {
/**
* The post object of the test post.
*
* @var WP_Post
*/
private WP_Post $post;

public function set_up() {
parent::set_up();
Expand Down
30 changes: 27 additions & 3 deletions tests/php/test-fieldmanager-checkboxes-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,33 @@
* @group checkboxes
*/
class Test_Fieldmanager_Checkboxes_Field extends WP_UnitTestCase {
public $post_id;
public $post;
public $custom_datasource;
/**
* The post ID of the test post.
*
* @var int
*/
private int $post_id = 0;
anubisthejackle marked this conversation as resolved.
Show resolved Hide resolved

/**
* The post object of the test post.
*
* @var WP_Post
*/
private WP_Post $post;

/**
* A months array.
*
* @var string[]
*/
private array $months;

/**
* Custom data source.
*
* @var Fieldmanager_Datasource
*/
private Fieldmanager_Datasource $custom_datasource;

public function set_up() {
parent::set_up();
Expand Down
7 changes: 7 additions & 0 deletions tests/php/test-fieldmanager-context-menuitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
* @group menuitem
*/
class Test_Fieldmanager_Context_Menuitem extends WP_UnitTestCase {
/**
* The post object of the test post.
*
* @var WP_Post
*/
private WP_Post $post;

public function set_up() {
parent::set_up();
Fieldmanager_Field::$debug = true;
Expand Down
52 changes: 23 additions & 29 deletions tests/php/test-fieldmanager-context-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@
* @group post
*/
class Test_Fieldmanager_Context_Post extends WP_UnitTestCase {
/**
* The post ID of the test post.
*
* @var int
*/
private int $post_id = 0;

/**
* The post object of the test post.
*
* @var WP_Post
*/
private WP_Post $post;

public function set_up() {
parent::set_up();
Fieldmanager_Field::$debug = true;

$this->post = array(
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
// Create a post and capture it.
$this->post = $this->factory->post->create_and_get(
[
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
]
);

// insert a post
$this->post_id = wp_insert_post( $this->post );

// reload as proper object
$this->post = get_post( $this->post_id );
// Store the post ID.
$this->post_id = $this->post->ID;
}

/**
Expand Down Expand Up @@ -131,24 +145,4 @@ public function test_context_save() {
$this->assertEquals( $saved_value['test_extended'][1]['extext'], array( 'second1', 'second2', 'second3' ) );
$this->assertEquals( $saved_value['test_extended'][3]['extext'][0], 'fourth' );
}

public function test_programmatic_save_posts() {
$base = $this->_get_elements();
$base->add_meta_box( 'test meta box', 'post' );

$post_id = wp_insert_post(
array(
'post_type' => 'post',
'post_name' => 'test-post',
'post_title' => 'Test Post',
'post_date' => '2012-10-25 12:34:56',
)
);
wp_update_post(
array(
'ID' => $post_id,
'post_content' => 'Lorem ipsum dolor sit amet.',
)
);
}
}
32 changes: 23 additions & 9 deletions tests/php/test-fieldmanager-context-quickedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@
* @group quickedit
*/
class Test_Fieldmanager_Context_Quickedit extends WP_UnitTestCase {
/**
* The post object.
*
* @var WP_Post
*/
private WP_Post $post;

/**
* The post ID.
*
* @var int
*/
private int $post_id;

public function set_up() {
parent::set_up();
Fieldmanager_Field::$debug = true;

$this->post = array(
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
// Create a post and capture it.
$this->post = $this->factory->post->create_and_get(
[
'post_status' => 'publish',
'post_content' => rand_str(),
'post_title' => rand_str(),
]
);

// insert a post
$this->post_id = wp_insert_post( $this->post );

// reload as proper object
$this->post = get_post( $this->post_id );
// Store the post ID.
$this->post_id = $this->post->ID;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/test-fieldmanager-context-submenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function test_urls() {
// Test with a parent slug
$name_4 = rand_str();
$parent = rand_str();
add_submenu_page( null, 'Test parent', 'Test parent', 'manage_options', $parent );
add_submenu_page( 'options.php', 'Test parent', 'Test parent', 'manage_options', $parent );
fm_register_submenu_page( $name_4, $parent, 'Testing URLs' );
$context_4 = $this->get_context( $name_4 );

Expand Down
28 changes: 28 additions & 0 deletions tests/php/test-fieldmanager-context-term-fm-term-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@
class Test_Fieldmanager_Context_Term_FM_Term_Meta extends WP_UnitTestCase {
public $current_user;

/**
* Taxonomy name.
*
* @var string
*/
private string $taxonomy;

/**
* Term ID
*
* @var int
*/
private int $term_id;

/**
* Term Taxonomy ID.
*
* @var int
*/
private int $tt_id;

/**
* The term.
*
* @var WP_Term
*/
private WP_Term $term;

public function set_up() {
parent::set_up();
Fieldmanager_Field::$debug = true;
Expand Down
28 changes: 28 additions & 0 deletions tests/php/test-fieldmanager-context-term.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@
class Test_Fieldmanager_Context_Term extends WP_UnitTestCase {
public $current_user;

/**
* Taxonomy name.
*
* @var string
*/
private string $taxonomy;

/**
* Term ID
*
* @var int
*/
private int $term_id;

/**
* Term Taxonomy ID.
*
* @var int
*/
private int $tt_id;

/**
* The term.
*
* @var WP_Term
*/
private WP_Term $term;

public function set_up() {
parent::set_up();
Fieldmanager_Field::$debug = true;
Expand Down
14 changes: 14 additions & 0 deletions tests/php/test-fieldmanager-context-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
* @group user
*/
class Test_Fieldmanager_Context_User extends WP_UnitTestCase {
/**
* The user ID.
*
* @var int
*/
private int $user_id;

/**
* The user object.
*
* @var WP_User
*/
private WP_User $user;

public function set_up() {
parent::set_up();
Fieldmanager_Field::$debug = true;
Expand Down
Loading
Loading