Skip to content
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
126 changes: 126 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Test

on:
push:
branches:
- master
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- php: '7.4'
env:
PHPCS: '1'
name: 'PHP 7.4 Lint'
- php: '8.2'
env:
PHPUNIT_VERSION: '9.6.7'
WP: 'latest'
name: 'PHP 8.2 / WP latest'
- php: '8.1'
env:
PHPUNIT_VERSION: '9.6.7'
WP: 'latest'
name: 'PHP 8.1 / WP latest'
- php: '8.0'
env:
PHPUNIT_VERSION: '9.6.7'
WP: 'latest'
name: 'PHP 8.0 / WP latest'
- php: '7.4'
env:
PHPUNIT_VERSION: '7.5.20'
WP: 'latest'
name: 'PHP 7.4 / WP latest'
- php: '7.3'
env:
PHPUNIT_VERSION: '7.5.20'
WP: 'latest'
name: 'PHP 7.3 / WP latest'
- php: '7.2'
env:
PHPUNIT_VERSION: '7.5.20'
WP: 'latest'
name: 'PHP 7.2 / WP latest'
- php: '7.1'
env:
PHPUNIT_VERSION: '7.5.20'
WP: '6.5.5'
name: 'PHP 7.1 / WP 6.5.5'
- php: '7.0'
env:
PHPUNIT_VERSION: '6.5.14'
WP: '6.5.5'
name: 'PHP 7.0 / WP 6.5.5'
- php: '5.6'
env:
PHPUNIT_VERSION: '5.7.27'
WP: '6.2.2'
name: 'PHP 5.6 / WP 6.2.2'

name: ${{ matrix.name }}

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Comment on lines +74 to +76
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CRITICAL_BUG] Mapping the MySQL service to host port 3306:3306 can cause port conflicts on the runner and is unnecessary for service containers in GitHub Actions. Remove the ports: mapping and rely on the service network (use localhost or the service hostname provided by Actions). Also confirm the --health-cmd works for the image used; if you need stricter health checks prefer --health-cmd='mysqladmin ping -p$MYSQL_ROOT_PASSWORD' or rely on built-in images' defaults.

# Remove the ports mapping
services:
  mysql:
    image: mysql:5.7
    env:
      MYSQL_ROOT_PASSWORD: root
    options: --health-cmd="mysqladmin ping -p$MYSQL_ROOT_PASSWORD" --health-interval=10s --health-timeout=5s --health-retries=3


steps:
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4

- name: Setup PHP
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
with:
php-version: ${{ matrix.php }}
extensions: mysql, mysqli, pdo, pdo_mysql, zip, libonig5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CRITICAL_BUG] The extensions list contains invalid or inappropriate entries for shivammathur/setup-php: mysql doesn’t exist in modern PHP, pdo is not a valid extension token for the action, and libonig5 is a Debian package name (not the PHP extension). Replace with actual PHP extension names supported by the action (for example: mysqli, pdo_mysql, zip, mbstring) and remove mysql/pdo and libonig5.

extensions: mysqli, pdo_mysql, zip, mbstring

coverage: none
tools: composer:v2

- name: Install subversion
run: |
sudo apt-get update
sudo apt-get install -y subversion

- name: Install dependencies (PHPCS)
if: matrix.env.PHPCS == '1'
run: |
cd tests
composer install

- name: Run PHPCS
if: matrix.env.PHPCS == '1'
run: tests/vendor/bin/phpcs

- name: Setup Test Environment
if: matrix.env.PHPCS != '1'
env:
PHPUNIT_VERSION: ${{ matrix.env.PHPUNIT_VERSION }}
WP_VERSION: ${{ matrix.env.WP }}
run: |
# Install WP Tests
bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:$((3306)) $WP_VERSION
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[VALIDATION] The call to bin/install-wp-tests.sh uses 127.0.0.1:$((3306))$((3306)) is an unnecessary arithmetic expansion and looks odd. Use 127.0.0.1:3306 or pass host and port in the format the script expects. Confirm the script expects a single host:port argument and adjust accordingly.

bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1:3306 $WP_VERSION


# Install PHPUnit
wget -q https://phar.phpunit.de/phpunit-$PHPUNIT_VERSION.phar -O /tmp/phpunit
chmod +x /tmp/phpunit

Comment on lines +114 to +117
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[REFACTORING] Downloading phpunit via wget without verification can cause non-reproducible builds and security risks. Prefer installing PHPUnit via composer (commit the lockfile) or use a maintained action/setup-php tool integration that provides phpunit. If you must download the PHAR, verify the checksum/signature for the version you download and ensure the phpunit version is compatible with the current PHP matrix entry.

- name: Install Polyfills
if: matrix.env.PHPCS != '1'
run: composer require yoast/phpunit-polyfills

Comment on lines +118 to +121
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CRITICAL_BUG] Running composer require yoast/phpunit-polyfills in CI will attempt to modify composer.json/composer.lock in the workspace and may fail on older PHP versions or with missing composer setup. Instead: (1) Add yoast/phpunit-polyfills to your dev dependencies in composer.json and commit the lockfile, then run composer install --no-interaction --prefer-dist in CI; or (2) run composer install to pull dependencies from composer.lock before tests. Avoid composer require during the job.

- name: Run Tests
if: matrix.env.PHPCS != '1'
run: |
/tmp/phpunit
WP_MULTISITE=1 /tmp/phpunit
104 changes: 0 additions & 104 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ https://core.trac.wordpress.org/ticket/44043

# Travis CI Status

[![Build Status](https://travis-ci.com/CybotAS/CookiebotWP.svg?branch=master)](https://app.travis-ci.com/github/CybotAS/CookiebotWP)
[![Test](https://github.com/CybotAS/CookiebotWP/actions/workflows/test.yml/badge.svg)](https://github.com/CybotAS/CookiebotWP/actions/workflows/test.yml)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NITPICK] You replaced the Travis badge with a generic GitHub Actions badge titled Test. Consider using a clearer badge text or updating the workflow name to something descriptive (e.g., CI / Tests) so the badge conveys what it represents.

[![CI / Tests](https://github.com/CybotAS/CookiebotWP/actions/workflows/test.yml/badge.svg)](https://github.com/CybotAS/CookiebotWP/actions/workflows/test.yml)

Or, update the workflow name in .github/workflows/test.yml to a more descriptive name like CI / Tests:

name: CI / Tests


# Sonarcloud status

Expand Down
14 changes: 12 additions & 2 deletions src/addons/controller/addons/Base_Cookiebot_Addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,17 @@ private static function get_svn_url( $path = '' ) {
*/
final public static function get_svn_file_content( $path = '' ) {
$url = self::get_svn_url( $path );
$response = wp_remote_get( $url );
return wp_remote_retrieve_body( $response );
$args = array(
'user-agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
);
$response = wp_remote_get( $url, $args );
$body = wp_remote_retrieve_body( $response );

if ( ! $body || 200 !== wp_remote_retrieve_response_code( $response ) ) {
// Fallback to svn cat if wp_remote_get fails (e.g. 403 Forbidden)
$body = shell_exec( 'svn cat ' . escapeshellarg( $url ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec
}

return $body;
}
}