Repository navigation
Expand file tree
/
Copy pathwp-setup.sh
More file actions
executable file
·100 lines (83 loc) · 4.46 KB
/
Copy pathwp-setup.sh
File metadata and controls
executable file
·100 lines (83 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
##
# This script prepares the WordPress repository for tests and development.
# It clones the WordPress repository and makes sure that the SQLite plugin
# is used in the development and testing environment instead of MySQL.
##
set -e
WP_VERSION="7.1"
DIR="$(dirname "$0")"
WP_DIR="$DIR/wordpress"
# 1. Ensure that Git is installed.
echo "Checking if Git is installed..."
if ! command -v git &> /dev/null; then
echo 'Error: Git is not installed.' >&2
exit 1
fi
# 2. Clone the WordPress repository, if it doesn't exist.
echo "Cleaning up the WordPress repository..."
rm -rf "$WP_DIR"
echo "Cloning the WordPress repository..."
git clone --depth 1 --branch "$WP_VERSION" https://github.com/WordPress/wordpress-develop.git "$WP_DIR"
# 3. Add "docker-compose.override.yml" to the WordPress repository.
echo "Adding 'docker-compose.override.yml' to the WordPress repository..."
cat << EOF > "$WP_DIR/docker-compose.override.yml"
services:
wordpress-develop:
volumes:
- ../packages/plugin-sqlite-database-integration:/var/www/src/wp-content/plugins/sqlite-database-integration
- ../packages/mysql-on-sqlite/src:/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database
php:
# PHP temporarily pinned to 8.3.10, see: https://github.com/WordPress/wordpress-develop/pull/9602
image: wordpressdevelop/php@sha256:c0ba85936a9d1ac2c98bf3da2d62ceb0e5787a6b11e383630df0c5a5bf2534b5
volumes:
- ../packages/plugin-sqlite-database-integration:/var/www/src/wp-content/plugins/sqlite-database-integration
- ../packages/mysql-on-sqlite/src:/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database
- ../tests/phpunit:/var/www/tests-sqlite-database-integration/phpunit
cli:
# PHP temporarily pinned to 8.3.10, see: https://github.com/WordPress/wordpress-develop/pull/9602
image: wordpressdevelop/cli@sha256:85ad7d7a9c3bd9a8775fc83aea7f7dfc0aad25b2bc4f7d740696b28cd2a0ef89
volumes:
- ../packages/plugin-sqlite-database-integration:/var/www/src/wp-content/plugins/sqlite-database-integration
- ../packages/mysql-on-sqlite/src:/var/www/src/wp-content/plugins/sqlite-database-integration/wp-includes/database
EOF
# 4. Add "db.php" to the "wp-content" directory.
echo "Adding 'db.php' to the 'wp-content' directory..."
rm -f "$WP_DIR"/src/wp-content/db.php
cp "$DIR"/packages/plugin-sqlite-database-integration/db.copy "$WP_DIR"/src/wp-content/db.php
sed -i.bak "s#'{SQLITE_IMPLEMENTATION_FOLDER_PATH}'#__DIR__.'/plugins/sqlite-database-integration'#g" "$WP_DIR"/src/wp-content/db.php
sed -i.bak "s#{SQLITE_PLUGIN}#sqlite-database-integration/load.php#g" "$WP_DIR"/src/wp-content/db.php
# 5. Rewrite helper class WpdbExposedMethodsForTesting to extend WP_SQLite_DB.
echo "Rewriting helper class 'WpdbExposedMethodsForTesting' to extend WP_SQLite_DB..."
sed -i.bak "s#class WpdbExposedMethodsForTesting extends wpdb {#class WpdbExposedMethodsForTesting extends WP_SQLite_DB {#g" "$WP_DIR"/tests/phpunit/includes/utils.php
# 6. Use the low bcrypt cost of the test suite in class fixtures as well.
# WP_UnitTestCase::set_up() sets it for each test, which is too late for wpSetUpBeforeClass().
echo "Lowering the bcrypt cost for test fixtures..."
cat << 'EOF' >> "$WP_DIR/tests/phpunit/includes/functions.php"
function _sqlite_tests_lower_bcrypt_cost( $options, $algorithm ) {
if ( PASSWORD_BCRYPT === $algorithm ) {
$options['cost'] = 5;
}
return $options;
}
tests_add_filter( 'wp_hash_password_options', '_sqlite_tests_lower_bcrypt_cost', 1, 2 );
EOF
# 7. Make wp-config.php changes immediately visible to E2E tests.
echo "Disabling the PHP OPcache revalidation delay..."
printf '\nopcache.revalidate_freq = 0\n' >> "$WP_DIR/tools/local-env/php-config.ini"
# 8. Create the ".env" file early, so that Docker commands before "env:start" use it too.
echo "Creating the '.env' file..."
cp "$WP_DIR/.env.example" "$WP_DIR/.env"
# 9. Install dependencies.
echo "Installing dependencies..."
npm --prefix "$WP_DIR" install
npm --prefix "$WP_DIR" run build:dev
# 10. Create "wp-tests-config.php" like "tools/local-env/scripts/install.js" does, so PHPUnit doesn't need "env:install".
echo "Creating the 'wp-tests-config.php' file..."
sed \
-e "s/youremptytestdbnamehere/wordpress_develop_tests/" \
-e "s/yourusernamehere/root/" \
-e "s/yourpasswordhere/password/" \
-e "s/localhost/mysql/" \
"$WP_DIR/wp-tests-config-sample.php" > "$WP_DIR/wp-tests-config.php"
printf "\ndefine( 'FS_METHOD', 'direct' );\n" >> "$WP_DIR/wp-tests-config.php"