Automatic testing/changes

description

Automatic testing in Streber
============================
We use simpletest's web_tester module for testing. This emulates a browser and simulates real clickflows and checks the results. You can login, change a users password, logout and test if the new password is working. So this is more integration testing than unit testing. This is nice for:

1. Tests are very easy to write.
2. Since pixtur added sql fixtures you can test complex setup involving several users and projects.
3. You can easily valid html structure, user data escaping and much more.

It fails on:
1. Javascript
2. Internal structures

Running the tests
=================
The tests are executed when requesting `http://localhost/streber/tests/testsuite_pages.php`. There are about 600 tests which take about 30 seconds on pixtur's notebook. Right now the tests uses database snapshots as sql-dumps as fixtures. These dumps are located at `tests/fixtures/*.sql`. The testing sql tables get the prefix `test_` so your userdata will not be resetted all the time. Initialization is done with the new class "TestEnvironment"

Creating new fixtures
---------------------
Creating a new fixture is done with `install/db_backup.php`. It writes a dump of all existing tables, so you have to remove the `test_*`-tables before calling this.
Automatic testing in Streber
============================
We use simpletest's web_tester module for testing. This emulates a browser and simulates real clickflows and checks the results. You can login, change a users password, logout and test if the new password is working. So this is more integration testing than unit testing. This is nice for:

1. Tests are very easy to write.
2. Since pixtur added sql fixtures you can test complex setup involving several users and projects.
3. You can easily valid html structure, user data escaping and much more.

It fails on:
1. Javascript
2. Internal structures

Running the tests
=================
The tests are executed when requesting `http://localhost/streber/tests/testsuite_pages.php`. There are about 600 tests which take about 30 seconds on pixtur's notebook. Right now the tests uses database snapshots as sql-dumps as fixtures. These dumps are located at `tests/fixtures/*.sql`. The testing sql tables get the prefix `test_` so your userdata will not be resetted all the time. Initialization is done with the new class "TestEnvironment"

Creating new fixtures
---------------------
Creating a new fixture is done with `install/db_backup.php`. It writes a dump of all existing tables, so you have to remove the `test_*`-tables before calling this.
Updating fixtures database
---------------------
The fixtures need to be updated every time, the database scheme (e.I. the database version) changes. If you don't do this, you will get errors like this:

[[image:8300|maxsize=320]]
Implementation details
======================

Test and development database
-----------------------------
To distinguish between the two databases, we overwrite the `USER_AGENT` before running the web_tester:
[code from="tests/test_item_visibility.php"]
$this->addHeader('USER_AGENT: streber_unit_tester'); # will result in HTTP_USER_AGENT
[/code]

In `index.php` we check for this user_agent and add the prefix `test_` to `DB_TABLE_PREFIX`. Before each test_case the test-database is completely recreated. After running all tests, the tables with `tests_*` will be dropped from the database by executing a long sql-statement:

[code from="tests/testsuite_pages"]TestEnvironment::prepare('fixtures/remove_tables.sql');
[/code]

Todo
=====
Although the current setting already provides a lot of features, it's still pretty hackish. Following this should be adjusted:

1. Streber should detect the web_tester user_agent and automatically use the `test_`-tables.
2. ~~TestEnvironment should provide a method the clean up test tables.~~
3. Setup [[#7291|basic project environment as fixture for testing]].

Things that urgently need to be tested
======================================
1. Form submitting esp for complex things like Tasks and People.
2. Correct escaping of all user data.
3. Item visibility in project environments.

Todo
=====
Although the current setting already provides a lot of features, it's still pretty hackish. Following this should be adjusted:

1. Streber should detect the web_tester user_agent and automatically use the `test_`-tables.
2. ~~TestEnvironment should provide a method the clean up test tables.~~
3. Setup [[#7291|basic project environment as fixture for testing]].

Things that urgently need to be tested
======================================
1. Form submitting esp for complex things like Tasks and People.
2. Correct escaping of all user data.
3. Item visibility in project environments.
______________
also see:
- #7291

for_milestone

0

parent_task

2427