wp-browser: [BUG] Cannot parse original site URL when running Acceptance test

Environment OS: MacOS 10.15.5 PHP version: 7.3.18 Installed Codeception version: 4.1.5 Installed wp-browser version: dev-feat/wptestcase-isolation WordPress version: 5.4.1. Local development environment: VVV WordPress structure and management: default

Can you perform the test manually? Site works when I go to the URL fine, I can log in and all

Codeception configuration file
Paste, in a fenced YAML block, the content of your Codeception configuration file; remove any sensitive data!

paths:
    tests: tests
    output: tests/_output
    data: tests/_data
    support: tests/_support
    envs: tests/_envs
actor_suffix: Tester
extensions:
    enabled:
        - Codeception\Extension\RunFailed
    commands:
        - Codeception\Command\GenerateWPUnit
        - Codeception\Command\GenerateWPRestApi
        - Codeception\Command\GenerateWPRestController
        - Codeception\Command\GenerateWPRestPostTypeController
        - Codeception\Command\GenerateWPAjax
        - Codeception\Command\GenerateWPCanonical
        - Codeception\Command\GenerateWPXMLRPC
params:
    - .env.testing
coverage:
    enabled: true
    include:
        - src/*
    exclude:
        - src/Core/CompiledContainer.php
        - src/Old/*
    low_limit: 30
    high_limit: 75
settings:
    colors: true
    memory_limit: 2048M

Suite configuration file Paste, in a fenced YAML block, the content of the suite configuration file; remove any sensitive data!

# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WPWebDriver or WPBrowser.
# Use WPDb to set up your initial database fixture.
# If you need both WPWebDriver and WPBrowser tests - create a separate suite.

actor: AcceptanceTester
modules:
    enabled:
        - WPDb
        - WPWebDriver
        - \Helper\Acceptance
    config:
        WPDb:
            dsn: 'mysql:host=%TEST_SITE_DB_HOST%;dbname=%TEST_SITE_DB_NAME%'
            user: '%TEST_SITE_DB_USER%'
            password: '%TEST_SITE_DB_PASSWORD%'
            dump: 'tests/_data/dump.sql'
            #import the dump before the tests; this means the test site database will be repopulated before the tests.
            populate: true
            # re-import the dump between tests; this means the test site database will be repopulated between the tests.
            cleanup: true
            waitlock: 10
            url: '%TEST_SITE_WP_URL%'
#            originalUrl: '%TEST_SITE_WP_URL%'
            urlReplacement: true #replace the hardcoded dump URL with the one above
            tablePrefix: '%TEST_SITE_TABLE_PREFIX%'
        WPWebDriver:
            originalUrl: '%TEST_SITE_WP_URL%'
            url: '%TEST_SITE_WP_URL%'
            adminUsername: '%TEST_SITE_ADMIN_USERNAME%'
            adminPassword: '%TEST_SITE_ADMIN_PASSWORD%'
            adminPath: '%TEST_SITE_WP_ADMIN_PATH%'
            browser: chrome
            host: localhost
            port: 9515
            window_size: false #disabled for Chrome driver
            capabilities:
                # Used in more recent releases of Selenium.
                "goog:chromeOptions":
                    args: ["--no-sandbox", "--headless", "--disable-gpu", "--user-agent=wp-browser"]
                # Support the old format for back-compatibility purposes.
                "chromeOptions":
                    args: ["--no-sandbox", "--headless", "--disable-gpu", "--user-agent=wp-browser"]

Describe the bug When I uncomment the originalUrl config in the WPDb module I get

In DbDump.php line 99:

  [Symfony\Component\Yaml\Exception\DumpException]
  Could not find, or could not parse, the original site URL; you can set the
  "originalUrl" parameter in the module configuration to skip this step and f
  ix this error.

Output If applicable paste here the output of the command that’s causing the issue.

Running /vendor/bin/codecept run Acceptance -vvv gives this:

Reading ./composer.json
Loading config file /Users/denis.zoljom/.composer/config.json
Loading config file /Users/denis.zoljom/.composer/auth.json
Loading config file ./composer.json
Checked CA file /usr/local/etc/openssl/cert.pem: valid
Executing command (/Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin): git branch --no-color --no-abbrev -v
Reading /Users/denis.zoljom/.composer/composer.json
Loading config file /Users/denis.zoljom/.composer/config.json
Loading config file /Users/denis.zoljom/.composer/auth.json
Loading config file /Users/denis.zoljom/.composer/composer.json
Loading config file /Users/denis.zoljom/.composer/auth.json
Reading /Users/denis.zoljom/.composer/auth.json
Reading /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/composer/installed.json
Reading /Users/denis.zoljom/.composer/vendor/composer/installed.json
Loading plugin Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin
Loading plugin cweagans\Composer\Patches
Running 1.10.6 (2020-05-06 10:28:10) with PHP 7.3.18 on Darwin / 19.5.0
> test:acceptance: @php ./vendor/bin/codecept run Acceptance --ansi '-vvv'
Executing command (CWD): '/usr/local/Cellar/valet-php@7.3/7.3.18_1/bin/php' -d allow_url_fopen='1' -d disable_functions='' -d memory_limit='1536M' ./vendor/bin/codecept run Acceptance --ansi '-vvv'
Codeception PHP Testing Framework v4.1.5
Powered by PHPUnit 8.5.5 by Sebastian Bergmann and contributors.
Running with seed:


  [Connecting To Db] {"config":{"tablePrefix":"wp_","populate":true,"cleanup":true,"reconnect":false,"dump":"tests/_data/dump.sql","populator":null,"urlReplacement":true,"originalUrl":null,"waitlock":10,"dsn":"mysql:host=vvv.test;dbname=wordpresstest","user":"external","password":"external","url":"https://myproject.byinfinum.test/"},"options":[]}
  [Db] Connected to default wordpresstest

In DbDump.php line 99:

  [Symfony\Component\Yaml\Exception\DumpException]
  Could not find, or could not parse, the original site URL; you can set the
  "originalUrl" parameter in the module configuration to skip this step and f
  ix this error.


Exception trace:
  at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/lucatume/wp-browser/src/tad/WPBrowser/Module/Support/DbDump.php:99
 tad\WPBrowser\Module\Support\DbDump->replaceSiteDomainInSqlString() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/lucatume/wp-browser/src/tad/WPBrowser/Module/Support/DbDump.php:51
 tad\WPBrowser\Module\Support\DbDump->replaceSiteDomainInSqlArray() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/lucatume/wp-browser/src/Codeception/Module/WPDb.php:3951
 Codeception\Module\WPDb->_replaceUrlInDump() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/lucatume/wp-browser/src/Codeception/Module/WPDb.php:3988
 Codeception\Module\WPDb->loadDumpUsingDriver() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/module-db/src/Codeception/Module/Db.php:682
 Codeception\Module\Db->_loadDump() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/lucatume/wp-browser/src/Codeception/Module/WPDb.php:3996
 Codeception\Module\WPDb->_loadDump() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/module-db/src/Codeception/Module/Db.php:297
 Codeception\Module\Db->populateDatabases() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/module-db/src/Codeception/Module/Db.php:449
 Codeception\Module\Db->_beforeSuite() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/lucatume/wp-browser/src/Codeception/Module/WPDb.php:4062
 Codeception\Module\WPDb->_beforeSuite() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php:38
 Codeception\Subscriber\Module->beforeSuite() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/symfony/event-dispatcher/EventDispatcher.php:230
 Symfony\Component\EventDispatcher\EventDispatcher->callListeners() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/symfony/event-dispatcher/EventDispatcher.php:59
 Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Event/DispatcherWrapper.php:22
 Codeception\SuiteManager->dispatch() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/SuiteManager.php:159
 Codeception\SuiteManager->run() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Codecept.php:196
 Codeception\Codecept->runSuite() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Codecept.php:163
 Codeception\Codecept->run() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Command/Run.php:503
 Codeception\Command\Run->runSuites() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Command/Run.php:397
 Codeception\Command\Run->execute() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/symfony/console/Command/Command.php:258



COMMAND DID NOT FINISH PROPERLY.
  [Db] Disconnected from default
 Symfony\Component\Console\Command\Command->run() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/symfony/console/Application.php:911
 Symfony\Component\Console\Application->doRunCommand() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/symfony/console/Application.php:264
 Symfony\Component\Console\Application->doRun() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/symfony/console/Application.php:140
 Symfony\Component\Console\Application->run() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/src/Codeception/Application.php:117
 Codeception\Application->run() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/app.php:46
 {closure}() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/app.php:47
 require() at /Users/denis.zoljom/vagrant-local/www/infinum/my-project/public_html/wp-content/plugins/my-plugin/vendor/codeception/codeception/codecept:7

run [-o|--override OVERRIDE] [-e|--ext EXT] [--report] [--html [HTML]] [--xml [XML]] [--phpunit-xml [PHPUNIT-XML]] [--tap [TAP]] [--json [JSON]] [--colors] [--no-colors] [--silent] [--steps] [-d|--debug] [--bootstrap [BOOTSTRAP]] [--no-redirect] [--coverage [COVERAGE]] [--coverage-html [COVERAGE-HTML]] [--coverage-xml [COVERAGE-XML]] [--coverage-text [COVERAGE-TEXT]] [--coverage-crap4j [COVERAGE-CRAP4J]] [--coverage-phpunit [COVERAGE-PHPUNIT]] [--no-exit] [-g|--group GROUP] [-s|--skip SKIP] [-x|--skip-group SKIP-GROUP] [--env ENV] [-f|--fail-fast] [--no-rebuild] [--seed SEED] [--no-artifacts] [--] [<suite> [<test>]]

When I put the urlReplacement then I don’t have that issue, but the test will timeout when I try to log in as admin $I->loginAsAdmin(). I tried doing

$I->amOnPage( '/wp-admin/' );
$I->makeScreenshot();

but the screenshot is blank. Which is weird.

The timeout error is :

Test  tests/Acceptance/Activation/PluginActivationCest.php:activatePluginSuccessfully

  [Facebook\WebDriver\Exception\TimeoutException]

Weird thing is that, on another plugin with 99% same setup, everything is working just fine. My acceptance tests pass, and on failure I can see the wp-admin page. So I’m not sure what am I missing or doing wrong 🤷‍♂️

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 29 (15 by maintainers)

Most upvoted comments

I ran into the same issue today, and after adding a few debug outputs to DbDump.php I found the problem:

The regular expression in function getOriginalUrlFromSqlString() due to so-called “catastrophic backtracking”.

The problematic regex:

/INSERT\s+INTO\s+`wp_options`.*'(home|siteurl)'\s*,\s*'(?<url>[^']+)'/uis

The problem is caused by the .* part before (home|siteurl):

When the dump file contains the term ‘home’ somewhere after the wp_options data, then the regular expression will evaluate all possible matches and finally give up due to the number of characters between both ‘home’ terms;

I have a page called “Home” in my DB. Also, there could be all kind of other cases where ‘home’ occurs somewhere in posts, post_meta, terms, or user_meta (or any other table that comes after wp_options)

Note

I’ve used the Regex debugger here to process the regex step by step and the problem was very obvious 😃
https://regex101.com/ → paste the regex and the entire wp_options table dump. Then click on “Regex Debugger” in the left sidebar to simulate each step of the regex engine.

TLDR

After adjusting the regex to be ungreedy, the problem is perfectly solved:

/INSERT\s+INTO\s+`wp_options`.*'(home|siteurl)'\s*,\s*'(?<url>[^']+)'/Uuis ← added /U

The effect of the /U flag is clearly visible in the regex debugger.

That’s great to hear @dingo-d,

thanks for writing down what issues you found and reporting them back: this will help others with the same issues to debug them.

I’ll try to dig deeper into it. But the timeout started to occur with another plugin with a smaller dump. So it could be something system-related 🤷‍♂️