Welcome to mirror list, hosted at ThFree Co, Russian Federation.

README.MD « tests - github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b40b8813e45821664e85adea3a8e65df64246e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Testing the Gallery app

Read more about automated testing in [the wiki](https://github.com/owncloud/gallery/wiki/Behavioural%2C-functional-and-unit-testing-suite/)

## Requirements

* PHP tidy enabled
* PHP imagick extension
* `core` cloned via git
* `core` submodule initialised
* `core` has to be installed
* Gallery app enabled (`sudo -u<myuser> ./occ app:enable gallery`)
* composer installed (see below)
* vendor folder and composer.lock file removed

## PHP

This repository is using [Codeception](http://codeception.com/) which makes it possible to use a single tool for behavioural, api, integration and unit testing.
If you're a PHPUnit veteran, don't fret! You can write unit and integration tests using the syntax you love and they will be executed just fine.

### Installing Codeception

There are several methods to install Codeception, depending on the test suites you want to run.
If using the phar, you'll be limited to unit and integration testing because it doesn't come with an integrated web server for the api and acceptance tests to connect to.


#### Using the phar package

Go to Gallery's root directory and type:

`# wget http://codeception.com/codecept.phar .`

That's it. You can check that it's properly "installed" by typing:

`# php codecept.phar --version`

#### Installing via Composer

If you intend on adding and running more than the unit tests, then it's best to install all the required packages via composer.
The first step is to [install composer](https://getcomposer.org/doc/00-intro.md)

This usually works well:

As root

`# curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer`

Next you'll need to add a Github token to composer so that you can easily download as many dependencies as you need.

1. Generate a personal token in your Github profile. You don't need to associate any Github permissions to this token.

2. Type the following command: `# composer config --global github-oauth.github.com <your-token> `

As the www user

You can now install all the packages needed to test the app:

`# php -dmemory_limit=1G /usr/local/bin/composer install --prefer-source -o`

Test your installation using the following command:

`# php vendor/bin/codecept -- version`

*Note: The binary is located in a different location than if you're using the phar*

And remember to **not** push your `vendor` folder if submitting pull requests.

Refer to the Codeception [quick guide](http://codeception.com/quickstart) if you need to customise your installation.

#### Webdriver

In order to be able to test the Javascript in acceptance tests, we need to install one more component: PhantomJS. Use your distribution installer to get it or download a binary for Windows or Mac from the [official website](http://phantomjs.org/download.html).

*Note: It's also required for Javascript tests in `core`, so this is not specific to this repository.*

### Running tests

**WARNING - RUNNING TESTS WILL DELETE ALL YOUR DATA**

#### Unit

Let's create a unit test class compatible with the PHPUnit syntax:

`# php vendor/bin/codecept g:phpunit unit service/MyServiceTest`

*Note: g stands for generate*

You can now add your tests with your favourite editor The file is located in `tests/unit/service/MyServiceTest.php`

To run it, simply do:

`# php vendor/bin/codecept run tests/unit/service/MyServiceTest.php`

If you want to run all the unit tests, it's:

`# php vendor/bin/codecept run unit`

#### Integration

You can use the same commands to generate your files, but your class needs to extend `GalleryIntegrationTest` in order to have access to the variables which are set at initialisation time. Things like the userId, shared folder, token, etc.

`# php vendor/bin/codecept g:phpunit integration service/MyServiceTest`

You can then run all tests using:

`# php vendor/bin/codecept run integration`

#### API and acceptance

Those suites use a different, scenario based syntax, but don't worry, it's easy to grasp.

Files storing unique scenarios are called **Cepts**

**Generating a Cept**

`# php vendor/bin/codecept g:cept acceptance SignIn`

An example of a sign in test:

```
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('sign in');
$I->amOnPage('/login');
$I->fillField('username', 'davert');
$I->fillField('password', 'qwerty');
$I->click('LOGIN');
$I->see('Welcome, Davert!');
?>
```

It's possible to group scenarios in a **Cest** which organises them in a class.

**Generating a Cest**

`# php vendor/bin/codecept g:cest acceptance PageCrud`

It's structure:

```
<?php
class PageCrudCest
{
    function _before(AcceptanceTester $I)
    {
        // will be executed at the beginning of each test
        $I->amOnPage('/');
    }

    function createPage(AcceptanceTester $I)
    {
       // todo: write test
    }

    function viewPage(AcceptanceTester $I)
    {
       // todo: write test
    }    

    function updatePage(AcceptanceTester $I)
    {
        // todo: write test
    }
    
    function deletePage(AcceptanceTester $I)
    {
       // todo: write test
    }
}
?>
```

I invite you to read the official documentation in order to understand the BDD style syntax used by Codeception and to discover all the useful commands you're going to be able to fire in order to test Gallery:

* [Testing WebServices](http://codeception.com/docs/10-WebServices)
* [Acceptance Testing](http://codeception.com/docs/03-AcceptanceTests)

Before running acceptance tests, you need to start PhantomJS manually

`# phantomjs --webdriver=4444 &`

then you simply do:

`# php vendor/bin/codecept run acceptance`

Don't forget to kill the phantomjs when you're done.

*Note: A web server is also automatically launched on port 8000 for the duration of the tests so that you can test the behaviour of the API and the app.*

### Notes

If you want to get more details about what is going on during your tests, simply add `-vvv` or `--debug` at the end of the command line

### Troubleshooting

#### Files can't be deleted during API test

If you start getting some strange errors about files which can't be deleted when running the API tests or if some the responses don't match what is expected, it could be because there is already an instance of the phpbuiltinserver running.
This can happen when a fatal error has happened during a previous run and Codeception wasn't able to shut down the server.

Get the process ID

`# ps aux | grep phpbuiltinserver`

Kill the process

`# kill -9 <process id>`

#### Accessing the built in server's logs

Look for them in the `tests/_output` folder, along with a summary of the failed tests