Skip to content

Commit

Permalink
Merge pull request #267 from transifex/devel
Browse files Browse the repository at this point in the history
Release 1.3.38
  • Loading branch information
foteinigk authored Jun 11, 2024
2 parents ee3330e + 6b668a7 commit bda7257
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 85 deletions.
27 changes: 27 additions & 0 deletions .github/gists/ci-apache-conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copied from https://gist.github.com/matthewjackowski/b772ab278efb0e6f30ad/raw/travisci-apache
<VirtualHost *:80>
ServerName wptest.localhost
DocumentRoot %TRAVIS_BUILD_DIR%

<Directory "%TRAVIS_BUILD_DIR%">
Options FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order deny,allow
Allow from all
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} ^/usr/lib/cgi-bin/php5-fcgi(.*)
RewriteRule . - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
<IfModule mod_fastcgi.c>
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
</IfModule>

</VirtualHost>
174 changes: 174 additions & 0 deletions .github/gists/install-wp-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#!/usr/bin/env bash
## Copied from https://gist.githubusercontent.com/matthewjackowski/3b26061241545564ae8d/raw/install-wp-tests.sh
# This script installs wordpress for phpunit tests and rspec integration tests
##
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DIR=$(dirname ${DIR})

if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
exit 1
fi

DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}

WP_VERSION=${5-latest}

# Use this for installing wordpress siteurl
WP_TEST_URL=${WP_TEST_URL-http://localhost:80}

# Get port from url
WP_PORT=${WP_TEST_URL##*:}

WP_TESTS_DIR=${WP_TESTS_DIR-$DIR/tmp/wordpress-tests-lib/includes}
WP_CORE_DIR=${WP_CORE_DIR-$DIR/wordpress}

# Use these credentials for installing wordpress
# Default test/test
WP_TEST_USER=${WP_TEST_USER-test}
WP_TEST_USER_PASS=${WP_TEST_USER_PASS-test}

set -ex

download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}

install_wp() {
if [ -d $WP_CORE_DIR ]; then
return;
fi

mkdir -p $WP_CORE_DIR

if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi

download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR

}

install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i .bak'
else
local ioption='-i'
fi

# set up testing suite if it doesn't yet exist
if [ ! "$(ls -A $WP_TESTS_DIR)" ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet http://develop.svn.wordpress.org/trunk/tests/phpunit/includes/ $WP_TESTS_DIR
fi

cd $WP_TESTS_DIR

# Install barebone wp-tests-config.php which is faster for unit tests
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/trunk/wp-tests-config-sample.php $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" $(dirname ${WP_TESTS_DIR})/wp-tests-config.php
fi

cd $WP_CORE_DIR

if [ ! -f wp-config.php ]; then
mv wp-config-sample.php wp-config.php
sed $ioption "s/database_name_here/$DB_NAME/" $WP_CORE_DIR/wp-config.php
sed $ioption "s/username_here/$DB_USER/" $WP_CORE_DIR/wp-config.php
sed $ioption "s/password_here/$DB_PASS/" $WP_CORE_DIR/wp-config.php
sed $ioption "s|localhost|${DB_HOST}|" $WP_CORE_DIR/wp-config.php
# Use different prefix for integration tests
sed $ioption "s|^.*\$table_prefix.*$|\$table_prefix = 'integ_';|" $WP_CORE_DIR/wp-config.php
fi
cd $DIR
}

install_db() {
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""

if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA="--host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA="--socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA="--host=$DB_HOSTNAME --protocol=tcp"
fi
fi

# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS" $EXTRA
}

link_this_project() {
cd $DIR
local FOLDER_PATH=$(dirname $DIR/transifex-live-wordpress/transifex-live-integration.php)
local FOLDER_NAME=$(basename $FOLDER_PATH)
case $WP_PROJECT_TYPE in
'plugin' )
ln -s $FOLDER_PATH $WP_CORE_DIR/wp-content/plugins/$FOLDER_NAME
php wp-cli.phar plugin activate --all --path=$WP_CORE_DIR
;;
'theme' )
ln -s $FOLDER_PATH $WP_CORE_DIR/wp-content/themes/$FOLDER_NAME
php wp-cli.phar theme activate $FOLDER_NAME --path=$WP_CORE_DIR
;;
esac
}

# Install databases with wp-cli
install_real_wp() {
cd $DIR
download https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar wp-cli.phar
echo "$(curl -fsSL https://gist.github.com/matthewjackowski/b20d525757261fb4bc78/raw/wp-cli.yml)" | sudo tee wp-cli.yml > /dev/null
php wp-cli.phar core install --url=$WP_TEST_URL --title='Test' --admin_user=$WP_TEST_USER --admin_password=$WP_TEST_USER_PASS --admin_email="$WP_TEST_USER@wordpress.dev" --path=$WP_CORE_DIR
php wp-cli.phar shell --path="$(pwd)/wordpress" <<< "site_url();"
# php wp-cli.phar rewrite structure "/%year%/%monthnum%/%day%/%postname%/" --path="$(pwd)/wordpress"
# php wp-cli.phar rewrite flush --hard --path="$(pwd)/wordpress"
git clone https://github.com/manovotny/wptest wptest
php wp-cli.phar plugin install wordpress-importer --activate --path=$WP_CORE_DIR
cd $WP_CORE_DIR
curl -OL https://raw.githubusercontent.com/manovotny/wptest/master/wptest.xml
php $DIR/wp-cli.phar import wptest.xml --authors=create
rm wptest.xml
cd $DIR
}

install_rspec_requirements() {
gem install bundler
bundle install --gemfile=$DIR/spec/Gemfile
}

start_server() {
mv $DIR/lib/router.php $WP_CORE_DIR/router.php
cd $WP_CORE_DIR
# Start it in background
php -S 0.0.0.0:$WP_PORT router.php &
}

install_wp
install_test_suite
install_db
install_real_wp
link_this_project
94 changes: 94 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: CI

on:
push:
branches:
- master
pull_request:

jobs:
build:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
php: [7.2]
continue-on-error: false

services:
mariadb:
image: mariadb:10.0
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping"
env:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"

env:
PLUGIN_VERSION: 1.3.38
WP_PROJECT_TYPE: plugin
WP_VERSION: latest
WP_MULTISITE: 0
WP_TEST_URL: http://localhost:80
WP_TEST_USER: test
WP_TEST_USER_PASS: test


steps:
- uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.2
extensions: mbstring, xml, ctype, iconv, intl, mysql
ini-values: post_max_size=256M, short_open_tag=On
tools: composer:v2

- name: Install system packages
run: |
sudo apt-get update
sudo apt-get install -y apache2 libapache2-mod-fcgid nodejs php-fpm
sudo a2enmod rewrite actions fcgid alias proxy_fcgi setenvif
sudo a2enconf php7.2-fpm
- name: Composer Global Packages
run: |
composer self-update
COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/module-asserts"
COMPOSER_MEMORY_LIMIT=-1 composer global require "codeception/codeception"
- name: Configure PHP and Apache
run: |
echo "cgi.fix_pathinfo = 1" | sudo tee -a /etc/php/7.2/fpm/php.ini
# Apache configuration steps
cd ..
echo "$(curl -fsSL https://gist.github.com/matthewjackowski/b772ab278efb0e6f30ad/raw/travisci-apache)" | sed -e "s,%TRAVIS_BUILD_DIR%,`pwd`/wordpress,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
cd transifex-live-wordpress
git clone https://github.com/Seravo/wordpress-test-template wordpress-test-template
echo "$(curl -fsSL https://gist.githubusercontent.com/matthewjackowski/3b26061241545564ae8d/raw/install-wp-tests.sh)" | sed -e "s@/home/travis/build/transifex/@/home/runner/work/transifex-live-wordpress/@g" |sudo tee ./install-wp-tests.sh > /dev/null
bash ./install-wp-tests.sh test root '' 127.0.0.1 $WP_VERSION
sudo service apache2 restart
sudo service php7.2-fpm restart
- name: Run tests
run: |
codecept run
- name: Deploy
if: github.ref == 'refs/heads/master'
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
sudo chmod +x ./wp-plugin-deploy.sh
./wp-plugin-deploy.sh
- name: Log failure
if: failure()
run: |
sudo cat /var/log/apache2/error.log
cat ./tests/_output/ConfigurePluginCept.fail.html
cat ./tests/_output/CheckLiveSnippetCept.fail.html
59 changes: 0 additions & 59 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions includes/lib/transifex-live-integration-hreflang.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public function render_hreflang() {
<link rel="alternate" href="$href_attr" hreflang="$hreflang_attr"/>\n
HREFLANG;
}
$hreflang_out .= <<<XDEFAULT
<link rel="alternate" href="$source_url" hreflang="x-default"/>\n
XDEFAULT;
echo $hreflang_out;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/transifex-live-integration-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function render() {
$lang = get_query_var( 'lang' );
$home_url = home_url( $wp->request );
$url_path = add_query_arg( array(), $wp->request );
$source_url_path = (substr( $url_path, 0, strlen( $lang ) ) === $lang) ? substr( $url_path, strlen( $lang ), strlen( $url_path ) ) : $url_path;
$source_url_path = (substr($url_path, 0, strlen($lang) + 1) === $lang . '/') ? substr($url_path, strlen($lang) + 1) : $url_path;
$url_map = Transifex_Live_Integration_Common::generate_language_url_map( $source_url_path, $this->tokenized_url, $this->language_map );
$site_url_slash_maybe = (new Transifex_Live_Integration_WP_Services())->get_site_url($this->is_subdirectory_install);
$site_url = rtrim( $site_url_slash_maybe, '/' ) . '/';
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/transifex-live-integration-subdirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function custom_slug_rewrite_rules_hook() {
} elseif ($post_type === 'page') {
$rules['%lang%/' . $path . '?$'] = 'index.php?lang=$matches[1]&pagename=' . $post->post_name;
} else {
$rules['%lang%/' . $path . '?$'] = 'index.php?lang=$matches[1]&' . $post_type . '=' . $post->post_name;
$rules['%lang%/' . $path . '?$'] = 'index.php?lang=$matches[1]&post_type=' . $post->post_type . '&p=' . $post->ID;
}
}
}
Expand Down
Loading

0 comments on commit bda7257

Please sign in to comment.