Skip to content

Commit b51437e

Browse files
committed
Temporarily restore dependencies of the legacy driver
1 parent e6cadfa commit b51437e

6 files changed

Lines changed: 1309 additions & 1 deletion

File tree

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<phpunit
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/9.2/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
backupGlobals="false"
6+
colors="true"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
8+
beStrictAboutOutputDuringTests="true"
9+
convertErrorsToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertDeprecationsToExceptions="true"
13+
>
14+
<testsuites>
15+
<!-- Default test suite to run all tests. -->
16+
<testsuite name="default">
17+
<directory suffix="_Tests.php">tests/</directory>
18+
<directory suffix="_Tests.php">tests/e2e/</directory>
19+
<exclude>packages/</exclude>
20+
<exclude>wordpress/</exclude>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

tests/WP_SQLite_Translator_Tests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function setUp(): void {
1818
// Skip all old driver tests when running on legacy SQLite version.
1919
// The old driver is to be removed in favor of the new AST driver,
2020
// so this is just a temporary measure to pass all CI combinations.
21-
$is_legacy_sqlite = version_compare( $this->engine->get_sqlite_version(), WP_PDO_MySQL_On_SQLite::MINIMUM_SQLITE_VERSION, '<' );
21+
$is_legacy_sqlite = version_compare( $this->engine->get_sqlite_version(), '3.37.0', '<' );
2222
if ( $is_legacy_sqlite ) {
2323
$this->markTestSkipped( "The old SQLite driver doesn't pass some test on legacy SQLite versions" );
2424
return;

tests/bootstrap.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
3+
require_once __DIR__ . '/wp-sqlite-schema.php';
4+
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-query-rewriter.php';
5+
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-lexer.php';
6+
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-token.php';
7+
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php';
8+
require_once __DIR__ . '/../wp-includes/sqlite/class-wp-sqlite-translator.php';
9+
10+
// Configure the test environment.
11+
error_reporting( E_ALL );
12+
define( 'FQDB', ':memory:' );
13+
define( 'FQDBDIR', __DIR__ . '/../testdb' );
14+
15+
// Polyfill WPDB globals.
16+
$GLOBALS['table_prefix'] = 'wptests_';
17+
$GLOBALS['wpdb'] = new class() {
18+
public function set_prefix( string $prefix ): void {}
19+
};
20+
21+
/**
22+
* Polyfills for WordPress functions
23+
*/
24+
if ( ! function_exists( 'do_action' ) ) {
25+
/**
26+
* Polyfill the do_action function.
27+
*/
28+
function do_action() {}
29+
}
30+
31+
if ( ! function_exists( 'apply_filters' ) ) {
32+
/**
33+
* Polyfill the apply_filters function.
34+
*
35+
* @param string $tag The filter name.
36+
* @param mixed $value The value to filter.
37+
* @param mixed ...$args Additional arguments to pass to the filter.
38+
*
39+
* @return mixed Returns $value.
40+
*/
41+
function apply_filters( $tag, $value, ...$args ) {
42+
return $value;
43+
}
44+
}
45+
46+
/**
47+
* Polyfills for php 7 & 8 functions
48+
*/
49+
50+
if ( ! function_exists( 'str_starts_with' ) ) {
51+
/**
52+
* Check if a string starts with a specific substring.
53+
*
54+
* @param string $haystack The string to search in.
55+
* @param string $needle The string to search for.
56+
*
57+
* @see https://www.php.net/manual/en/function.str-starts-with
58+
*
59+
* @return bool
60+
*/
61+
function str_starts_with( string $haystack, string $needle ) {
62+
return empty( $needle ) || 0 === strpos( $haystack, $needle );
63+
}
64+
}
65+
66+
if ( ! function_exists( 'str_contains' ) ) {
67+
/**
68+
* Check if a string contains a specific substring.
69+
*
70+
* @param string $haystack The string to search in.
71+
* @param string $needle The string to search for.
72+
*
73+
* @see https://www.php.net/manual/en/function.str-contains
74+
*
75+
* @return bool
76+
*/
77+
function str_contains( string $haystack, string $needle ) {
78+
return empty( $needle ) || false !== strpos( $haystack, $needle );
79+
}
80+
}
81+
82+
if ( ! function_exists( 'str_ends_with' ) ) {
83+
/**
84+
* Check if a string ends with a specific substring.
85+
*
86+
* @param string $haystack The string to search in.
87+
* @param string $needle The string to search for.
88+
*
89+
* @see https://www.php.net/manual/en/function.str-ends-with
90+
*
91+
* @return bool
92+
*/
93+
function str_ends_with( string $haystack, string $needle ) {
94+
return empty( $needle ) || substr( $haystack, -strlen( $needle ) ) === $needle;
95+
}
96+
}
97+
if ( extension_loaded( 'mbstring' ) ) {
98+
99+
if ( ! function_exists( 'mb_str_starts_with' ) ) {
100+
/**
101+
* Polyfill for mb_str_starts_with.
102+
*
103+
* @param string $haystack The string to search in.
104+
* @param string $needle The string to search for.
105+
*
106+
* @return bool
107+
*/
108+
function mb_str_starts_with( string $haystack, string $needle ) {
109+
return empty( $needle ) || 0 === mb_strpos( $haystack, $needle );
110+
}
111+
}
112+
113+
if ( ! function_exists( 'mb_str_contains' ) ) {
114+
/**
115+
* Polyfill for mb_str_contains.
116+
*
117+
* @param string $haystack The string to search in.
118+
* @param string $needle The string to search for.
119+
*
120+
* @return bool
121+
*/
122+
function mb_str_contains( string $haystack, string $needle ) {
123+
return empty( $needle ) || false !== mb_strpos( $haystack, $needle );
124+
}
125+
}
126+
127+
if ( ! function_exists( 'mb_str_ends_with' ) ) {
128+
/**
129+
* Polyfill for mb_str_ends_with.
130+
*
131+
* @param string $haystack The string to search in.
132+
* @param string $needle The string to search for.
133+
*
134+
* @return bool
135+
*/
136+
function mb_str_ends_with( string $haystack, string $needle ) {
137+
// phpcs:ignore Squiz.PHP.DisallowMultipleAssignments.Found
138+
return empty( $needle ) || $needle = mb_substr( $haystack, - mb_strlen( $needle ) );
139+
}
140+
}
141+
}

tests/wp-sqlite-schema.php

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php
2+
/**
3+
* WordPress schema for unit tests for the SQLite database integration project.
4+
*
5+
* This is hardcoded to SQLite DDL.
6+
*/
7+
8+
global $blog_tables;
9+
10+
$blog_tables = "
11+
CREATE TABLE IF NOT EXISTS \"wp_users\"(
12+
\"ID\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
13+
\"user_login\" text NOT NULL DEFAULT '' COLLATE NOCASE,
14+
\"user_pass\" text NOT NULL DEFAULT '' COLLATE NOCASE,
15+
\"user_nicename\" text NOT NULL DEFAULT '' COLLATE NOCASE,
16+
\"user_email\" text NOT NULL DEFAULT '' COLLATE NOCASE,
17+
\"user_url\" text NOT NULL DEFAULT '' COLLATE NOCASE,
18+
\"user_registered\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
19+
\"user_activation_key\" text NOT NULL DEFAULT '' COLLATE NOCASE,
20+
\"user_status\" integer NOT NULL DEFAULT '0',
21+
\"display_name\" text NOT NULL DEFAULT '' COLLATE NOCASE
22+
);
23+
CREATE TABLE IF NOT EXISTS \"wp_usermeta\"(
24+
\"umeta_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
25+
\"user_id\" integer NOT NULL DEFAULT '0',
26+
\"meta_key\" text DEFAULT NULL COLLATE NOCASE,
27+
\"meta_value\" text COLLATE NOCASE
28+
);
29+
CREATE TABLE IF NOT EXISTS \"wp_termmeta\"(
30+
\"meta_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
31+
\"term_id\" integer NOT NULL DEFAULT '0',
32+
\"meta_key\" text DEFAULT NULL COLLATE NOCASE,
33+
\"meta_value\" text COLLATE NOCASE
34+
);
35+
CREATE TABLE IF NOT EXISTS \"wp_terms\"(
36+
\"term_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
37+
\"name\" text NOT NULL DEFAULT '' COLLATE NOCASE,
38+
\"slug\" text NOT NULL DEFAULT '' COLLATE NOCASE,
39+
\"term_group\" integer NOT NULL DEFAULT 0
40+
);
41+
CREATE TABLE IF NOT EXISTS \"wp_term_taxonomy\"(
42+
\"term_taxonomy_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
43+
\"term_id\" integer NOT NULL DEFAULT 0,
44+
\"taxonomy\" text NOT NULL DEFAULT '' COLLATE NOCASE,
45+
\"description\" text NOT NULL COLLATE NOCASE,
46+
\"parent\" integer NOT NULL DEFAULT 0,
47+
\"count\" integer NOT NULL DEFAULT 0
48+
);
49+
CREATE TABLE IF NOT EXISTS \"wp_term_relationships\"(
50+
\"object_id\" integer NOT NULL DEFAULT 0,
51+
\"term_taxonomy_id\" integer NOT NULL DEFAULT 0,
52+
\"term_order\" integer NOT NULL DEFAULT 0,
53+
PRIMARY KEY(\"object_id\", \"term_taxonomy_id\")
54+
);
55+
CREATE TABLE IF NOT EXISTS \"wp_commentmeta\"(
56+
\"meta_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
57+
\"comment_id\" integer NOT NULL DEFAULT '0',
58+
\"meta_key\" text DEFAULT NULL COLLATE NOCASE,
59+
\"meta_value\" text COLLATE NOCASE
60+
);
61+
CREATE TABLE IF NOT EXISTS \"wp_comments\"(
62+
\"comment_ID\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
63+
\"comment_post_ID\" integer NOT NULL DEFAULT '0',
64+
\"comment_author\" text NOT NULL COLLATE NOCASE,
65+
\"comment_author_email\" text NOT NULL DEFAULT '' COLLATE NOCASE,
66+
\"comment_author_url\" text NOT NULL DEFAULT '' COLLATE NOCASE,
67+
\"comment_author_IP\" text NOT NULL DEFAULT '' COLLATE NOCASE,
68+
\"comment_date\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
69+
\"comment_date_gmt\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
70+
\"comment_content\" text NOT NULL COLLATE NOCASE,
71+
\"comment_karma\" integer NOT NULL DEFAULT '0',
72+
\"comment_approved\" text NOT NULL DEFAULT '1' COLLATE NOCASE,
73+
\"comment_agent\" text NOT NULL DEFAULT '' COLLATE NOCASE,
74+
\"comment_type\" text NOT NULL DEFAULT 'comment' COLLATE NOCASE,
75+
\"comment_parent\" integer NOT NULL DEFAULT '0',
76+
\"user_id\" integer NOT NULL DEFAULT '0'
77+
);
78+
CREATE TABLE IF NOT EXISTS \"wp_links\"(
79+
\"link_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
80+
\"link_url\" text NOT NULL DEFAULT '' COLLATE NOCASE,
81+
\"link_name\" text NOT NULL DEFAULT '' COLLATE NOCASE,
82+
\"link_image\" text NOT NULL DEFAULT '' COLLATE NOCASE,
83+
\"link_target\" text NOT NULL DEFAULT '' COLLATE NOCASE,
84+
\"link_description\" text NOT NULL DEFAULT '' COLLATE NOCASE,
85+
\"link_visible\" text NOT NULL DEFAULT 'Y' COLLATE NOCASE,
86+
\"link_owner\" integer NOT NULL DEFAULT '1',
87+
\"link_rating\" integer NOT NULL DEFAULT '0',
88+
\"link_updated\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
89+
\"link_rel\" text NOT NULL DEFAULT '' COLLATE NOCASE,
90+
\"link_notes\" text NOT NULL COLLATE NOCASE,
91+
\"link_rss\" text NOT NULL DEFAULT '' COLLATE NOCASE
92+
);
93+
CREATE TABLE IF NOT EXISTS \"wp_options\"(
94+
\"option_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
95+
\"option_name\" text NOT NULL DEFAULT '' COLLATE NOCASE,
96+
\"option_value\" text NOT NULL COLLATE NOCASE,
97+
\"autoload\" text NOT NULL DEFAULT 'yes' COLLATE NOCASE
98+
);
99+
CREATE TABLE IF NOT EXISTS \"wp_postmeta\"(
100+
\"meta_id\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
101+
\"post_id\" integer NOT NULL DEFAULT '0',
102+
\"meta_key\" text DEFAULT NULL COLLATE NOCASE,
103+
\"meta_value\" text COLLATE NOCASE
104+
);
105+
CREATE TABLE IF NOT EXISTS \"wp_posts\"(
106+
\"ID\" integer PRIMARY KEY AUTOINCREMENT NOT NULL,
107+
\"post_author\" integer NOT NULL DEFAULT '0',
108+
\"post_date\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
109+
\"post_date_gmt\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
110+
\"post_content\" text NOT NULL COLLATE NOCASE,
111+
\"post_title\" text NOT NULL COLLATE NOCASE,
112+
\"post_excerpt\" text NOT NULL COLLATE NOCASE,
113+
\"post_status\" text NOT NULL DEFAULT 'publish' COLLATE NOCASE,
114+
\"comment_status\" text NOT NULL DEFAULT 'open' COLLATE NOCASE,
115+
\"ping_status\" text NOT NULL DEFAULT 'open' COLLATE NOCASE,
116+
\"post_password\" text NOT NULL DEFAULT '' COLLATE NOCASE,
117+
\"post_name\" text NOT NULL DEFAULT '' COLLATE NOCASE,
118+
\"to_ping\" text NOT NULL COLLATE NOCASE,
119+
\"pinged\" text NOT NULL COLLATE NOCASE,
120+
\"post_modified\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
121+
\"post_modified_gmt\" text NOT NULL DEFAULT '0000-00-00 00:00:00' COLLATE NOCASE,
122+
\"post_content_filtered\" text NOT NULL COLLATE NOCASE,
123+
\"post_parent\" integer NOT NULL DEFAULT '0',
124+
\"guid\" text NOT NULL DEFAULT '' COLLATE NOCASE,
125+
\"menu_order\" integer NOT NULL DEFAULT '0',
126+
\"post_type\" text NOT NULL DEFAULT 'post' COLLATE NOCASE,
127+
\"post_mime_type\" text NOT NULL DEFAULT '' COLLATE NOCASE,
128+
\"comment_count\" integer NOT NULL DEFAULT '0'
129+
);
130+
CREATE INDEX \"wp_users__user_login_key\" ON \"wp_users\"(\"user_login\");
131+
CREATE INDEX \"wp_users__user_nicename\" ON \"wp_users\"(\"user_nicename\");
132+
CREATE INDEX \"wp_users__user_email\" ON \"wp_users\"(\"user_email\");
133+
CREATE INDEX \"wp_usermeta__user_id\" ON \"wp_usermeta\"(\"user_id\");
134+
CREATE INDEX \"wp_usermeta__meta_key\" ON \"wp_usermeta\"(\"meta_key\");
135+
CREATE INDEX \"wp_termmeta__term_id\" ON \"wp_termmeta\"(\"term_id\");
136+
CREATE INDEX \"wp_termmeta__meta_key\" ON \"wp_termmeta\"(\"meta_key\");
137+
CREATE INDEX \"wp_terms__slug\" ON \"wp_terms\"(\"slug\");
138+
CREATE INDEX \"wp_terms__name\" ON \"wp_terms\"(\"name\");
139+
CREATE UNIQUE INDEX \"wp_term_taxonomy__term_id_taxonomy\" ON \"wp_term_taxonomy\"(
140+
\"term_id\",
141+
\"taxonomy\"
142+
);
143+
CREATE INDEX \"wp_term_taxonomy__taxonomy\" ON \"wp_term_taxonomy\"(\"taxonomy\");
144+
CREATE INDEX \"wp_term_relationships__term_taxonomy_id\" ON \"wp_term_relationships\"(
145+
\"term_taxonomy_id\"
146+
);
147+
CREATE INDEX \"wp_commentmeta__comment_id\" ON \"wp_commentmeta\"(\"comment_id\");
148+
CREATE INDEX \"wp_commentmeta__meta_key\" ON \"wp_commentmeta\"(\"meta_key\");
149+
CREATE INDEX \"wp_comments__comment_post_ID\" ON \"wp_comments\"(
150+
\"comment_post_ID\"
151+
);
152+
CREATE INDEX \"wp_comments__comment_approved_date_gmt\" ON \"wp_comments\"(
153+
\"comment_approved\",
154+
\"comment_date_gmt\"
155+
);
156+
CREATE INDEX \"wp_comments__comment_date_gmt\" ON \"wp_comments\"(
157+
\"comment_date_gmt\"
158+
);
159+
CREATE INDEX \"wp_comments__comment_parent\" ON \"wp_comments\"(\"comment_parent\");
160+
CREATE INDEX \"wp_comments__comment_author_email\" ON \"wp_comments\"(
161+
\"comment_author_email\"
162+
);
163+
CREATE INDEX \"wp_links__link_visible\" ON \"wp_links\"(\"link_visible\");
164+
CREATE UNIQUE INDEX \"wp_options__option_name\" ON \"wp_options\"(\"option_name\");
165+
CREATE INDEX \"wp_options__autoload\" ON \"wp_options\"(\"autoload\");
166+
CREATE INDEX \"wp_postmeta__post_id\" ON \"wp_postmeta\"(\"post_id\");
167+
CREATE INDEX \"wp_postmeta__meta_key\" ON \"wp_postmeta\"(\"meta_key\");
168+
CREATE INDEX \"wp_posts__post_name\" ON \"wp_posts\"(\"post_name\");
169+
CREATE INDEX \"wp_posts__type_status_date\" ON \"wp_posts\"(
170+
\"post_type\",
171+
\"post_status\",
172+
\"post_date\",
173+
\"ID\"
174+
);
175+
CREATE INDEX \"wp_posts__post_parent\" ON \"wp_posts\"(\"post_parent\");
176+
CREATE INDEX \"wp_posts__post_author\" ON \"wp_posts\"(\"post_author\");
177+
";

0 commit comments

Comments
 (0)