Skip to content

Commit

Permalink
Merge pull request #722 from lucatume/v35-update-includes
Browse files Browse the repository at this point in the history
build(includes) update
  • Loading branch information
lucatume authored May 13, 2024
2 parents ab60b3f + c952556 commit 4c6f2d6
Show file tree
Hide file tree
Showing 13 changed files with 501 additions and 87 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- Updated `sqlite-integration-plugin` and Core PHPUnit suite files.

## [3.5.7] 2024-04-12;

### Changed
Expand Down
2 changes: 1 addition & 1 deletion includes/core-phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ protected function update_post_modified( $post_id, $date ) {
/**
* Touches the given file and its directory if it doesn't already exist.
*
* This can be used to ensure a file that is implictly relied on in a test exists
* This can be used to ensure a file that is implicitly relied on in a test exists
* without it having to be built.
*
* @param string $file The file name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function create_many( $count, $args = array(), $generation_definitions =
* @param array|null $callbacks Optional. Array with callbacks to apply on the fields.
* Default null.
*
* @return array|WP_Error Combined array on success. WP_Error when default value is incorrent.
* @return array|WP_Error Combined array on success. WP_Error when default value is incorrect.
*/
public function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
$callbacks = array();
Expand Down
8 changes: 4 additions & 4 deletions includes/core-phpunit/includes/normalize-xml.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Normalize an XML document to make it easier to compare whether 2 documents will
be seen as "equal" to an XML processor.
The normalization is similiar, in spirit, to {@link https://www.w3.org/TR/xml-c14n11/ Canonical XML},
The normalization is similar, in spirit, to {@link https://www.w3.org/TR/xml-c14n11/ Canonical XML},
but without some aspects of C14N that make the kinds of assertions we need difficult.
For example, the following XML documents will be interpreted the same by an XML processor,
Expand All @@ -23,7 +23,7 @@
>

<!--
Output UTF-8 XML, no indendation and all CDATA sections replaced with their character content.
Output UTF-8 XML, no indentation and all CDATA sections replaced with their character content.
-->
<xsl:output
method='xml'
Expand Down Expand Up @@ -61,12 +61,12 @@
</xsl:template>

<!--
Strip comments.
Strip comments.
-->
<xsl:template match='comment()' priority='10' />

<!--
Pass all other nodes through unchanged.
Pass all other nodes through unchanged.
-->
<xsl:template match='node()'>
<xsl:copy>
Expand Down
4 changes: 2 additions & 2 deletions includes/core-phpunit/includes/testcase-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function set_up_before_class() {
/**
* Sets up the test fixture.
*
* Overrides wp_die(), pretends to be Ajax, and suppresses E_WARNINGs.
* Overrides wp_die(), pretends to be Ajax, and suppresses warnings.
*/
public function set_up() {
parent::set_up();
Expand Down Expand Up @@ -164,7 +164,7 @@ public function tear_down() {
$_GET = array();
unset( $GLOBALS['post'] );
unset( $GLOBALS['comment'] );
remove_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1, 1 );
remove_filter( 'wp_die_ajax_handler', array( $this, 'getDieHandler' ), 1 );
remove_action( 'clear_auth_cookie', array( $this, 'logout' ) );
error_reporting( $this->_error_level );
set_current_screen( 'front' );
Expand Down
22 changes: 17 additions & 5 deletions includes/core-phpunit/includes/testcase-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
namespace lucatume\WPBrowser\TestCase;

abstract class WPRestApiTestCase extends WPTestCase {
protected function assertErrorResponse( $code, $response, $status = null ) {

/**
* Asserts that the REST API response has the specified error.
*
* @since 4.4.0
* @since 6.6.0 Added the `$message` parameter.
*
* @param string|int $code Expected error code.
* @param WP_REST_Response|WP_Error $response REST API response.
* @param int $status Optional. Status code.
* @param string $message Optional. Message to display when the assertion fails.
*/
protected function assertErrorResponse( $code, $response, $status = null, $message = '' ) {

if ( $response instanceof \WP_REST_Response ) {
$response = $response->as_error();
}

$this->assertWPError( $response );
$this->assertSame( $code, $response->get_error_code() );
$this->assertWPError( $response, $message . ' Passed $response is not a WP_Error object.' );
$this->assertSame( $code, $response->get_error_code(), $message . ' The expected error code does not match.' );

if ( null !== $status ) {
$data = $response->get_error_data();
$this->assertArrayHasKey( 'status', $data );
$this->assertSame( $status, $data['status'] );
$this->assertArrayHasKey( 'status', $data, $message . ' Passed $response does not include a status code.' );
$this->assertSame( $status, $data['status'], $message . ' The expected status code does not match.' );
}
}
}
26 changes: 13 additions & 13 deletions includes/sqlite-database-integration/admin-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ function sqlite_integration_admin_screen() {
<?php elseif ( file_exists( WP_CONTENT_DIR . '/db.php' ) && ! defined( 'SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<?php if ( defined( 'PERFLAB_SQLITE_DB_DROPIN_VERSION' ) ) : ?>
<div class="notice notice-warning">
<p>
<p>
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
</div>
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>">
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'An older %s file was detected. Please click the button below to update the file.', 'sqlite-database-integration' ),
esc_html__( 'Update %s file', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</p>
</div>
<a class="button button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=sqlite-integration&confirm-install&upgrade-from-pl' ), 'sqlite-install' ) ); ?>">
<?php
printf(
/* translators: %s: db.php drop-in path */
esc_html__( 'Update %s file', 'sqlite-database-integration' ),
'<code>' . esc_html( basename( WP_CONTENT_DIR ) ) . '/db.php</code>'
);
?>
</a>
</a>
<?php else : ?>
<div class="notice notice-error">
<p>
Expand Down
3 changes: 2 additions & 1 deletion includes/sqlite-database-integration/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: SQLite Database Integration
* Description: SQLite database driver drop-in.
* Author: The WordPress Team
* Version: 2.1.7
* Version: 2.1.10
* Requires PHP: 7.0
* Textdomain: sqlite-database-integration
*
Expand All @@ -16,6 +16,7 @@
define('SQLITE_MAIN_FILE', __FILE__);
}

require_once __DIR__ . '/php-polyfills.php';
require_once __DIR__ . '/admin-page.php';
require_once __DIR__ . '/activate.php';
require_once __DIR__ . '/deactivate.php';
Expand Down
54 changes: 54 additions & 0 deletions includes/sqlite-database-integration/php-polyfills.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Polyfills for php 7 & 8 functions
*
* @package wp-sqlite-integration
*/

if ( ! function_exists( 'str_starts_with' ) ) {
/**
* Check if a string starts with a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-starts-with
*
* @return bool
*/
function str_starts_with( string $haystack, string $needle ) {
return empty( $needle ) || 0 === strpos( $haystack, $needle );
}
}

if ( ! function_exists( 'str_contains' ) ) {
/**
* Check if a string contains a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-contains
*
* @return bool
*/
function str_contains( string $haystack, string $needle ) {
return empty( $needle ) || false !== strpos( $haystack, $needle );
}
}

if ( ! function_exists( 'str_ends_with' ) ) {
/**
* Check if a string ends with a specific substring.
*
* @param string $haystack The string to search in.
* @param string $needle The string to search for.
*
* @see https://www.php.net/manual/en/function.str-ends-with
*
* @return bool
*/
function str_ends_with( string $haystack, string $needle ) {
return empty( $needle ) || substr( $haystack, -strlen( $needle ) === $needle );
}
}
2 changes: 1 addition & 1 deletion includes/sqlite-database-integration/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: wordpressdotorg, aristath
Requires at least: 6.0
Tested up to: 6.4
Requires PHP: 5.6
Stable tag: 2.1.7
Stable tag: 2.1.10
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function __construct( $pdo ) {
'release_lock' => 'release_lock',
'ucase' => 'ucase',
'lcase' => 'lcase',
'unhex' => 'unhex',
'inet_ntoa' => 'inet_ntoa',
'inet_aton' => 'inet_aton',
'datediff' => 'datediff',
Expand Down Expand Up @@ -633,6 +634,21 @@ public function lcase( $content ) {
return "lower($content)";
}

/**
* Method to emulate MySQL UNHEX() function.
*
* For a string argument str, UNHEX(str) interprets each pair of characters
* in the argument as a hexadecimal number and converts it to the byte represented
* by the number. The return value is a binary string.
*
* @param string $number Number to be unhexed.
*
* @return string Binary string
*/
public function unhex( $number ) {
return pack( 'H*', $number );
}

/**
* Method to emulate MySQL INET_NTOA() function.
*
Expand Down
Loading

0 comments on commit 4c6f2d6

Please sign in to comment.