Fix pixel event tracking by isolating JS execution context #1306
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Integration Tests | |
| on: | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| integration-tests: | |
| name: Integration Tests | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| services: | |
| mysql: | |
| image: mysql:5.7 | |
| env: | |
| MYSQL_ROOT_PASSWORD: root | |
| MYSQL_DATABASE: wordpress_test | |
| MYSQL_USER: wp_user | |
| MYSQL_PASSWORD: wp_pass | |
| ports: | |
| - 3306:3306 | |
| options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
| steps: | |
| - name: Install SVN | |
| run: sudo apt-get install subversion -y | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '7.4' | |
| coverage: xdebug | |
| ini-values: memory_limit=-1 | |
| - name: Get Composer Cache Directory | |
| id: composer-cache | |
| run: | | |
| echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-composer- | |
| - name: Install System Dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y subversion | |
| - name: Install Composer dependencies | |
| id: install-composer | |
| continue-on-error: true | |
| run: | | |
| composer install --prefer-dist --no-progress --no-suggest || composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs || echo "::warning::Composer installation failed, tests may be skipped" | |
| # Check if vendor directory exists and has content | |
| if [ -d "vendor" ] && [ "$(ls -A vendor)" ]; then | |
| echo "composer_installed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "composer_installed=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup WordPress Test Environment | |
| if: steps.install-composer.outputs.composer_installed == 'true' | |
| id: setup-wp | |
| continue-on-error: true | |
| run: | | |
| # Install WordPress test suite with WooCommerce and Polylang for localization tests | |
| # Parameters: db-name db-user db-pass db-host wp-version wc-version polylang-version skip-db-creation | |
| bash bin/install-wp-tests.sh wordpress_test wp_user wp_pass 127.0.0.1:3306 latest latest latest || echo "::warning::WordPress test suite installation failed" | |
| # Install Facebook for WooCommerce plugin | |
| cp -r . /tmp/wordpress/wp-content/plugins/facebook-for-woocommerce | |
| # Check if setup was successful | |
| if [ -d "/tmp/wordpress" ] && [ -d "/tmp/wordpress/wp-content/plugins/woocommerce" ]; then | |
| echo "wp_setup_success=true" >> $GITHUB_OUTPUT | |
| # Check if Polylang was installed for localization tests | |
| if [ -d "/tmp/wordpress/wp-content/plugins/polylang" ]; then | |
| echo "Polylang installed - localization integration tests will run" >> $GITHUB_STEP_SUMMARY | |
| echo "polylang_available=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "Polylang not installed - localization tests will be skipped" >> $GITHUB_STEP_SUMMARY | |
| echo "polylang_available=false" >> $GITHUB_OUTPUT | |
| fi | |
| else | |
| echo "wp_setup_success=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Verify Test Environment | |
| if: steps.setup-wp.outputs.wp_setup_success == 'true' | |
| run: | | |
| php --version | |
| composer --version | |
| # Verify WordPress installation | |
| ls -la /tmp/wordpress/ || echo "::warning::WordPress directory not found" | |
| ls -la /tmp/wordpress/wp-content/plugins/ || echo "::warning::Plugins directory not found" | |
| # Verify database connection | |
| mysql -h 127.0.0.1 -P 3306 -u wp_user -pwp_pass -e "SHOW DATABASES;" || echo "::warning::Database connection failed" | |
| - name: Run Integration Tests | |
| if: steps.setup-wp.outputs.wp_setup_success == 'true' | |
| id: run-tests | |
| continue-on-error: true | |
| env: | |
| WP_TESTS_DIR: /tmp/wordpress-tests-lib | |
| WP_CORE_DIR: /tmp/wordpress | |
| WC_DIR: /tmp/wordpress/wp-content/plugins/woocommerce | |
| FB_TEST_PLUGIN: ${{ steps.setup-wp.outputs.polylang_available == 'true' && 'polylang' || '' }} | |
| run: | | |
| # Set environment variable for localization tests | |
| if [[ "${{ steps.setup-wp.outputs.polylang_available }}" == "true" ]]; then | |
| echo "Running integration tests with Polylang support..." | |
| export FB_TEST_PLUGIN=polylang | |
| else | |
| echo "Running integration tests without localization plugin..." | |
| fi | |
| # Run integration tests with verbose output | |
| if ./vendor/bin/phpunit --testsuite=integration --verbose --debug; then | |
| echo "tests_passed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "tests_passed=false" >> $GITHUB_OUTPUT | |
| echo "::warning::Integration tests failed" | |
| fi | |
| - name: Run Integration Tests with Coverage | |
| if: steps.setup-wp.outputs.wp_setup_success == 'true' | |
| continue-on-error: true | |
| env: | |
| WP_TESTS_DIR: /tmp/wordpress-tests-lib | |
| WP_CORE_DIR: /tmp/wordpress | |
| WC_DIR: /tmp/wordpress/wp-content/plugins/woocommerce | |
| run: | | |
| ./vendor/bin/phpunit --testsuite=integration --coverage-clover=coverage.xml --coverage-html=coverage-html || echo "::warning::Coverage generation failed" | |
| - name: Upload Coverage to Codecov | |
| if: success() | |
| uses: codecov/codecov-action@v3 | |
| with: | |
| file: ./coverage.xml | |
| flags: integration | |
| name: integration-tests | |
| fail_ci_if_error: false | |
| - name: Create Test Summary | |
| if: always() | |
| run: | | |
| echo "## Integration Test Results" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**PHP Version:** 7.4" >> $GITHUB_STEP_SUMMARY | |
| echo "**WordPress:** Latest Stable" >> $GITHUB_STEP_SUMMARY | |
| echo "**WooCommerce:** Latest Stable" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| if [[ "${{ steps.install-composer.outputs.composer_installed }}" == "true" ]]; then | |
| echo "✅ Composer dependencies installed" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Composer dependencies failed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [[ "${{ steps.setup-wp.outputs.wp_setup_success }}" == "true" ]]; then | |
| echo "✅ WordPress test environment setup" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ WordPress test environment failed" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| if [[ "${{ steps.run-tests.outputs.tests_passed }}" == "true" ]]; then | |
| echo "✅ Integration tests passed" >> $GITHUB_STEP_SUMMARY | |
| elif [[ "${{ steps.run-tests.outputs.tests_passed }}" == "false" ]]; then | |
| echo "❌ Integration tests failed" >> $GITHUB_STEP_SUMMARY | |
| exit 1 | |
| else | |
| echo "⏭️ Integration tests skipped" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Archive Test Results | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: | | |
| tests/ | |
| coverage-html/ | |
| /tmp/wordpress/wp-content/debug.log | |
| retention-days: 7 | |
| - name: Archive Error Logs | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: error-logs | |
| path: | | |
| /tmp/wordpress/wp-content/debug.log | |
| /var/log/ | |
| retention-days: 7 |