forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.xml
307 lines (279 loc) · 13.7 KB
/
tests.xml
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<project name="tests" default="tests:all">
<target name="tests" depends="tests:all" description="Runs all tests, including Behat, PHPUnit, and Security Update check."/>
<target name="test" depends="tests" hidden="true"/>
<target name="tests:all" depends="tests:security-updates, tests:phpunit, tests:behat" hidden="true"/>
<!-- If you experience 'Maximum function nesting level' errors in your PHP
error log, set 'xdebug.max_nesting_level=1000' in php.ini. -->
<target name="tests:behat" depends="test:behat:check, tests:run-server" description="Executes Behat all behat tests in behat.paths.">
<phingcall target="tests:selenium:kill"/>
<phingcall target="tests:phantomjs:kill"/>
<if>
<equals arg1="${behat.launch-phantomjs}" arg2="true"/>
<then>
<phingcall target="tests:phantomjs:launch"/>
</then>
</if>
<if>
<equals arg1="${behat.launch-selenium}" arg2="true"/>
<then>
<phingcall target="tests:selenium:launch"/>
</then>
</if>
<mkdir dir="${reports.localDir}/behat"/>
<foreach list="${behat.paths}" target="tests:behat:execute" param="behat.path"/>
<phingcall target="tests:selenium:kill"/>
<phingcall target="tests:phantomjs:kill"/>
</target>
<target name="test:behat:check" description="Checks Behat configuration" hidden="true" depends="setup:behat">
<property file="${repo.root}/tests/behat/local.yml" prefix="behatConfig"/>
<if>
<or>
<not><available file="${behatConfig.local.extensions.Drupal\DrupalExtension.drupal.drupal_root}"/></not>
<not><available file="${behatConfig.local.suites.default.paths.features}"/></not>
<not><available file="${behatConfig.local.suites.default.paths.bootstrap}"/></not>
</or>
<then>
<echo></echo>
<echo level="warning">One or more values in tests/behat/local.yml reference file paths that do not exist on this system.</echo>
<echo level="warning">This is typically related to using a virtual machine.</echo>
<echo level="warning"></echo>
<echo level="warning">Try one of the following solution:</echo>
<echo level="warning">1) Execute the tests on the correct system.</echo>
<echo level="warning">2) Correct the value(s).</echo>
<echo level="warning">3) Remove tests/behat/local.yml so that it can be regenerated automatically from example.local.yml.</echo>
<echo level="warning"></echo>
<echo level="warning">Values are:</echo>
<echo level="warning">drupal_root: ${behatConfig.local.extensions.Drupal\DrupalExtension.drupal.drupal_root}"</echo>
<echo level="warning">features: ${behatConfig.local.suites.default.paths.features}"</echo>
<echo level="warning">bootstrap: ${behatConfig.local.suites.default.paths.bootstrap}</echo>
<echo level="warning"></echo>
<propertyprompt promptText="Do you want to re-generate Behat configuration? [y/n]" propertyName="behat.regenerate" defaultValue="y"/>
<if>
<equals arg1="${behat.regenerate}" arg2="y" casesensitive="false"/>
<then>
<delete file="${repo.root}/tests/behat/local.yml"/>
<phingcall target="setup:behat"/>
</then>
<else>
<fail>Cannot execute behat tests because Behat configuration is invalid.</fail>
</else>
</if>
</then>
</if>
<echo>Executing Behat tests with configuratoin:</echo>
<echo>drupal_root: ${behatConfig.local.extensions.Drupal\DrupalExtension.drupal.drupal_root}"</echo>
<echo>base_url: ${behatConfig.local.extensions.Behat\MinkExtension.base_url}"</echo>
</target>
<target name="tests:behat:execute" description="Executes behat tests against specific path." hidden="true">
<!-- Check to see if any behat tests exist in this directory. If not,
behat will throw fatal error. -->
<if>
<not><contains string="${behat.path}" substring=".feature"/></not>
<then>
<exec command="find ${behat.path} -name *.feature -print -quit" logoutput="true" outputProperty="behat.tests.found" level="${blt.exec_level}"/>
</then>
</if>
<if>
<istrue value="${behat.tests.found}"/>
<then>
<!-- Run behat. Any settings in behat.yml or local.yml will be used. -->
<behat executable="${composer.bin}/behat"
config="${behat.config}"
profile="${behat.profile}"
verbose="${behat.verbose}"
strict="${behat.strict}"
haltonerror="${behat.haltonerror}"
returnProperty="behatPass"
out="std,${reports.localDir}"
format="pretty,junit"
path="${behat.path}"
tags="${behat.tags}"
/>
<if>
<!-- A non-zero returns status indicates failure. -->
<not><equals arg1="${behatPass}" arg2="0"/></not>
<then>
<phingcall target="tests:selenium:kill"/>
<phingcall target="tests:phantomjs:kill"/>
<fail message="One or more Behat tests failed." />
</then>
<else>
<echo>All Behat tests in ${behat.path} have passed.</echo>
</else>
</if>
</then>
<else>
<echo message="No Behat tests were found in ${behat.path}"/>
</else>
</if>
</target>
<target name="tests:selenium:launch"
description="Launches Selenium standalone server."
hidden="true">
<if>
<equals arg1="${behat.launch-selenium}" arg2="true"/>
<then>
<phingcall target="tests:selenium:kill"/>
<echo message="Launching Selenium standalone server." />
<touch file="${repo.root}/reports/selenium2.log"/>
<property name="reports.selenium2" value="${reports.localDir}/selenium2.log"/>
<exec command="${composer.bin}/selenium-server-standalone -port 4444 -log ${reports.selenium2}"
dir="${repo.root}"
passthru="true"
spawn="true"
checkreturn="true"
level="${blt.exec_level}"
logoutput="false"/>
<echo>Selenium2 logs are being written to ${reports.selenium2}.</echo>
<echo message="Waiting 15 seconds for Selenium standalone server (http://127.0.0.1:4444) to become available."/>
<waitfor maxwait="15" maxwaitunit="second" checkevery="1" checkeveryunit="second" timeoutproperty="selenium.timedout">
<http url="http://127.0.0.1:4444/wd/hub"/>
</waitfor>
<if>
<equals arg1="${selenium.timedout}" arg2="true"/>
<then>
<fail>Unable to start Selenium2 standalone server on http://127.0.0.1:4444/wd/hub.</fail>
</then>
</if>
</then>
<else>
<echo>Not starting Selenium2 standalone server. Hope that you have something else setup!</echo>
</else>
</if>
</target>
<target name="tests:selenium:kill"
description="Kills Selenium standalone server process and any process running on port 4444." hidden="true">
<echo>Killing any selenium processes that are already running.</echo>
<exec command="lsof -ti tcp:4444 | xargs kill 2>/dev/null" logoutput="false" level="${blt.exec_level}" passthru="false" checkreturn="false" />
<exec command="pgrep selenium | xargs kill 2>/dev/null" logoutput="false" level="${blt.exec_level}" passthru="false" checkreturn="false" />
</target>
<target name="tests:phantomjs:launch"
description="Launches a GhostDriver."
depends="tests:phantomjs:configure"
hidden="true">
<echo message="Launching PhantomJS GhostDriver." />
<phingcall target="tests:phantomjs:kill"/>
<exec command="${composer.bin}/phantomjs --webdriver=4444"
passthru="true"
spawn="true"
checkreturn="true"
level="${blt.exec_level}"/>
<echo message="Waiting 10 seconds for PhantomJS (http://127.0.0.1:4444) to become available."/>
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second">
<http url="http://127.0.0.1:4444/wd/hub"/>
</waitfor>
</target>
<target name="tests:phantomjs:configure" description="Checks and corrects PhantomJS configuration">
<exec dir="${repo.root}" command="grep 'jakoch/phantomjs-installer' composer.json" logoutput="false" level="${blt.exec_level}" passthru="false" returnProperty="phantom.required"/>
<if>
<isfailure code="${phantom.required}"/>
<then>
<echo level="Warning">jakoch/phantomjs-installer is not required in composer.json.</echo>
<propertyprompt promptText="Do you want to require jakoch/phantomjs-installer via Composer?" propertyName="phantom.do-require" defaultValue="y"/>
<if>
<equals arg1="${phantom.do-require}" arg2="y" casesensitive="false"/>
<then>
<exec dir="${repo.root}" command="composer require jakoch/phantomjs-installer --dev" logoutput="true" level="${blt.exec_level}" passthru="true" />
</then>
<else>
<fail>Cannot launch PhantomJS it is not installed.</fail>
</else>
</if>
</then>
</if>
<exec dir="${repo.root}" command="grep installPhantomJS composer.json" logoutput="false" level="${blt.exec_level}" passthru="false" returnProperty="phantom.scripts"/>
<if>
<isfailure code="${phantom.scripts}"/>
<then>
<echo level="warning">behat.launch-phantomjs is true, but the install-phantomjs script is not defined in composer.json.</echo>
<propertyprompt promptText="Do you want to add an 'install-phantomjs' script to your composer.json?" propertyName="phantom.do-add-script" defaultValue="y"/>
<if>
<equals arg1="${phantom.do-add-script}" arg2="y" casesensitive="false"/>
<then>
<exec command="${composer.bin}/blt-console configure:phantomjs ${repo.root}" logoutput="true" level="${blt.exec_level}" passthru="false" checkreturn="true"/>
</then>
<else>
<fail>Cannot launch PhantomJS because the install-phantomjs script is not present in composer.json. Add it, or use Selenium instead.</fail>
</else>
</if>
</then>
</if>
<if>
<not><available file="${composer.bin}/phantomjs"/></not>
<then>
<exec dir="${repo.root}" command="composer install-phantom" checkreturn="true" logoutput="true" passthru="true" level="${blt.exec_level}"/>
</then>
</if>
</target>
<target name="tests:phantomjs:kill"
description="Launches a GhostDriver." hidden="true">
<echo>Killing any PhantomJS processes that are already running.</echo>
<exec command="lsof -ti tcp:4444 | xargs kill 2>/dev/null" logoutput="false" level="${blt.exec_level}" passthru="false" checkreturn="false" />
<exec command="pgrep phantomjs | xargs kill 2>/dev/null" logoutput="true" level="${blt.exec_level}" passthru="true" />
</target>
<!-- Execute PHPUnit tests. -->
<target name="tests:phpunit" description="Executes PHPUnit tests against custom code.">
<delete dir="${reports.localDir}/phpunit" quiet="true"/>
<mkdir dir="${reports.localDir}/phpunit"/>
<phpunit printsummary="true" failureproperty="phpunit.failures" errorproperty="phpunit.errors">
<formatter type="plain" usefile="false"/>
<formatter type="xml" todir="${reports.localDir}/phpunit"/>
<batchtest>
<fileset dir="${repo.root}/tests/phpunit">
<include name="**/*Test*.php"/>
</fileset>
<fileset dir="${blt.root}/tests/phpunit/BltProject"/>
</batchtest>
</phpunit>
<phpunitreport infile="${reports.localDir}/phpunit/testsuites.xml" format="noframes" todir="${reports.localDir}/phpunit" />
<property name="reports.phpunit.file" value="${reports.localDir}/phpunit/phpunit-noframes.html"/>
<echo>PHPUnit Report is available at ${reports.phpunit.file}</echo>
<if>
<or>
<equals arg1="${phpunit.failures}" arg2="true"/>
<equals arg1="${phpunit.errors}" arg2="true"/>
</or>
<then>
<fail message="PHPUnit Failed. See report for details."/>
</then>
</if>
</target>
<!-- Optionally run tests against internal PHP server. -->
<target name="tests:run-server" hidden="true">
<if>
<equals arg1="${behat.run-server}" arg2="true"/>
<then>
<echo message="Using 'drush runserver' for tests." />
<echo message="Running server at ${behat.server-url}"/>
<exec command="pkill -f runserver" logoutput="true" level="${blt.exec_level}" passthru="true"/>
<exec executable="${drush.bin}" dir="${docroot}" spawn="true" level="${blt.exec_level}">
<arg line="runserver ${behat.server-url} -l ${multisite.name}"/>
</exec>
<echo message="Waiting 10 seconds for ${behat.server-url} to become available."/>
<waitfor maxwait="10" maxwaitunit="second" checkevery="1" checkeveryunit="second">
<http url="${behat.server-url}"/>
</waitfor>
</then>
<else>
<echo message="NOT using `drush runserver' for tests." />
</else>
</if>
</target>
<!-- Ensure Drupal doesn't have any modules requiring security updates. -->
<target name="tests:security-updates"
description="Check local Drupal installation for security updates.">
<exec dir="${docroot}"
command="! ${drush.cmd} -n ups --check-disabled --security-only 2>/dev/null | grep 'SECURITY UPDATE'"
checkreturn="true" level="${blt.exec_level}"
logoutput="true"
returnProperty="securityPass"
passthru="true"/>
<!-- Output message on failure. -->
<if>
<not><equals arg1="${securityPass}" arg2="0"/></not>
<then>
<echo>One or more of your dependency has an outstanding security update. Please apply update(s) immediately. Failing build.</echo>
</then>
</if>
</target>
</project>