phpmyadmin/test
Kamil Tekiela 51f4017b32
Refactor destroy controller (#17194)
* Remove redundant conditions

They were always true. First, the variable is set to -1.
If the variable is -1, then set it to Message.
If the variable is Message then set the JSON array. All of this is
redundant.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* $sqlQuery is not used anywhere

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Enforce $selected to be an array

I can't remove it as it is a global. Previously, it was set to a POST
variable. Since we validate that the variable is set and is not null,
we can use the value from $params. If we validate that it's also an
array we can replace for loop with foreach.
There is no passing by reference, so this change should be safe.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Replace $rebuildDatabaseList with input validation

The validation message says 'No databases selected.' so I assume that
we should check that we actually got at least one entry in the list.
If that is true, then the $rebuildDatabaseList is not needed and the
condition redundant.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* drop_selected_dbs is always set and is redundant

I am not sure if this is necessary. The AJAX request sends a value of "1"
but the code doesn't really do anything with it other than checking if
it is actually set. Is there some other path possible?

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Flatten the array with a single element

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Remove redundant isset

The variable is set, so !isset === is_null. Why check for null if we can
check just for !is_array.

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Update psalm-baseline.xml

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>

* Adhere to the coding standard

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
2021-11-19 14:26:04 -03:00
..
classes Refactor destroy controller (#17194) 2021-11-19 14:26:04 -03:00
javascript Bump Jest version to 27.3.1 2021-11-02 15:08:19 -03:00
jest Add Jest Unit Testing compatibility 2021-01-24 00:33:42 +01:00
selenium Fix ChangePasswordTest failing Selenium test 2021-11-03 13:50:20 -03:00
test_data Add tests for #16920 - Uncaught TypeError: PhpMyAdmin\Import::detectType(): Argument #2 ($cell) must be of type ?string, float given 2021-05-28 21:36:39 +02:00
bootstrap-dist.php Fix #16951 - Daily build failing because autoload is not loaded on some phpunit setups 2021-06-09 22:03:06 +02:00
bootstrap-static.php Get default config values from Config\Settings classes 2021-09-30 12:04:47 -03:00
ci-phplint Move to GitHub actions 2021-01-19 21:43:23 +01:00
config.e2e.inc.php Fix server login and documentation 2021-02-08 22:26:21 +01:00
doctum-config.php Upgrade Doctum to ^5.3.0 2020-12-21 15:10:30 +01:00
nginx.conf Fix logs system and temp dir for tests 2021-02-09 02:01:23 +01:00
php-fpm.conf Fix logs system and temp dir for tests 2021-02-09 02:01:23 +01:00
php.ini Remove all references to deprecated extension mcrypt 2020-04-05 20:57:07 +02:00
phpstan-constants.php Remove PhpMyAdmin\Config::enableBc method 2021-07-09 13:59:04 -03:00
phpunit-php-nightly.xml Fix some tests with PHP 8.1 2021-06-11 18:14:40 -03:00
README.rst Fix server login and documentation 2021-02-08 22:26:21 +01:00
start-local-server Fix logs system and temp dir for tests 2021-02-09 02:01:23 +01:00
stop-local-server Fix logs system and temp dir for tests 2021-02-09 02:01:23 +01:00

PhpMyAdmin test suite
=====================

This directory is protected from web visitors by a .htaccess file.

For more information on allowing http access to this directory see:
https://httpd.apache.org/docs/current/mod/mod_authz_host.html#allow

Please visit the wiki for more information on unit testing:
https://wiki.phpmyadmin.net/pma/Unit_Testing

Selenium tests
--------------

To be able to run Selenium tests, you need to have webserver, database
and Selenium running. Following environment variables configure where
testsuite connects:

TESTSUITE_USER
    Username to connect on the interface located at TESTSUITE_URL
TESTSUITE_PASSWORD
    Password to connect on the interface located at TESTSUITE_URL
TESTSUITE_DATABASE_PREFIX
    Database prefix to use for testing (Avoid database grouping characters like _).
TESTSUITE_URL
    URL where tested phpMyAdmin is available.

Additionally you need to configure link to Selenium and browsers. You
can either setup Selenium locally or use BrowserStack automated testing.

For local setup, define following:

TESTSUITE_SELENIUM_HOST
    Host where Selenium is running.
TESTSUITE_SELENIUM_PORT
    Port where to connect.
TESTSUITE_SELENIUM_BROWSER
    Browser to use for testing inside Selenium.

With BrowserStack, set following:

TESTSUITE_BROWSERSTACK_USER
    BrowserStack username.
TESTSUITE_BROWSERSTACK_KEY
    BrowserStack access key.

For example you can use following setup in ``phpunit.xml``::

    <php>
        <env name="TESTSUITE_USER" value="root"/>
        <env name="TESTSUITE_PASSWORD" value="root"/>
        <env name="TESTSUITE_DATABASE_PREFIX" value="test"/>
        <env name="TESTSUITE_URL" value="http://localhost/phpmyadmin/" />
        <env name="TESTSUITE_SELENIUM_HOST" value="127.0.0.1" />
        <env name="TESTSUITE_SELENIUM_PORT" value="4444" />
    </php>

Using BrowserStack
------------------

We're using our selenium tests on the GitHub CI.

To run tests locally, you need to install BrowserStack tool to enable local
testing, see their website for instructions:

https://www.browserstack.com/local-testing#command-line

Following instructions use PHP's built in server for the testing::

    # Export BrowserStack credentials in the environment:
    export TESTSUITE_BROWSERSTACK_USER=your_username
    export TESTSUITE_BROWSERSTACK_KEY=your_key

    # Port where tests will be running
    export TESTSUITE_PORT=9000
    export TESTSUITE_URL=http://127.0.0.1:$TESTSUITE_PORT/

    # Start PHP built in server
    php --server 127.0.0.1:$TESTSUITE_PORT > php.log &

    # Start BrowserStack Local client to forward the traffic
    ~/browserstack/BrowserStackLocal -localIdentifier Manual "$TESTSUITE_BROWSERSTACK_KEY" 127.0.0.1,$TESTSUITE_PORT,0 &

    # Stop BrowserStack Local
    ~/browserstack/BrowserStackLocal --daemon stop