Skip to content

Commit c981193

Browse files
committed
Try a UI test
1 parent 68db2e6 commit c981193

3 files changed

Lines changed: 122 additions & 3 deletions

File tree

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ matrix:
2424
env: DB=mysqli
2525
- php: 7.1
2626
env: DB=mysqli
27-
- php: nightly
27+
- php: 7.2
2828
env: DB=mysqli
29-
- php: hhvm
29+
- php: nightly
3030
env: DB=mysqli
3131
allow_failures:
3232
- php: nightly
33-
- php: hhvm
3433
fast_finish: true
3534

3635
env:
@@ -55,6 +54,7 @@ install:
5554

5655
before_script:
5756
- travis/setup-database.sh $DB $TRAVIS_PHP_VERSION $NOTESTS
57+
- phantomjs --webdriver=8910 > /dev/null &
5858

5959
script:
6060
- sh -c "if [ '$SNIFF' != '0' ]; then travis/ext-sniff.sh $DB $TRAVIS_PHP_VERSION $EXTNAME $NOTESTS; fi"

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
<testsuite name="Extension Test Suite">
1717
<directory suffix="_test.php">./tests</directory>
1818
<exclude>./tests/functional</exclude>
19+
<exclude>./tests/ui</exclude>
1920
</testsuite>
2021
<testsuite name="Extension Functional Tests">
2122
<directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">./tests/functional/</directory>
2223
</testsuite>
24+
<testsuite name="Extension UI Tests">
25+
<directory suffix="_test.php" phpVersion="5.3.19" phpVersionOperator=">=">./tests/ui/</directory>
26+
</testsuite>
2327
</testsuites>
2428

2529
<filter>

tests/ui/ideas_test.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ideas\tests\ui;
12+
13+
use Facebook\WebDriver\WebDriverKeys;
14+
15+
/**
16+
* @group ui
17+
*/
18+
class ideas_test extends \phpbb_ui_test_case
19+
{
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public static function setUpBeforeClass()
24+
{
25+
// Set these properties to true so we can use the same board created for functional tests
26+
// instead of having to create and set up a whole new board.
27+
self::$already_installed = true;
28+
self::$install_success = true;
29+
parent::setUpBeforeClass();
30+
}
31+
32+
/**
33+
* Test JavaScript user interactions
34+
*
35+
* @throws \Facebook\WebDriver\Exception\NoSuchElementException
36+
* @throws \Facebook\WebDriver\Exception\TimeOutException
37+
*/
38+
public function test_js_actions()
39+
{
40+
$this->login();
41+
$this->admin_login();
42+
43+
$this->visit('app.php/idea/1');
44+
45+
// test showing the list of voters
46+
$votes = $this->find_element('className', 'voteslist');
47+
$this->assertEquals('none', $votes->getCSSValue('display'));
48+
$this->find_element('className', 'votes')->click();
49+
$this->assertEquals('block', $votes->getCSSValue('display'));
50+
51+
// test voting
52+
$votedown = $this->find_element('className', 'minivotedown');
53+
$this->assertEquals('0', $votedown->getText());
54+
$votedown->click();
55+
$this->waitForAjax();
56+
$this->assertEquals('1', $this->find_element('className', 'minivotedown')->getText());
57+
58+
// test changing the status
59+
$this->assertEquals('New', $this->find_element('className', 'status-badge')->getText());
60+
$elements = $this->find_element('cssSelector', 'select#status')
61+
->findElements(\Facebook\WebDriver\WebDriverBy::tagName('option'));
62+
foreach ($elements as $element)
63+
{
64+
if ($element->getText() === 'In Progress')
65+
{
66+
$element->click();
67+
}
68+
}
69+
$this->waitForAjax();
70+
$this->assertEquals('In Progress', $this->find_element('className', 'status-badge')->getText());
71+
72+
// test showing the edit ticket input and entering text into it
73+
$test = 'PHPBB3-123';
74+
$input = $this->find_element('cssSelector', '#ticketeditinput');
75+
$this->assertFalse($input->isDisplayed());
76+
$this->find_element('cssSelector', '#ticketedit')->click();
77+
$this->assertTrue($input->isDisplayed());
78+
$input->sendKeys([$test, WebDriverKeys::ENTER]);
79+
$this->waitForAjax();
80+
$this->assertEquals($test, $this->find_element('cssSelector', '#ticketlink')->getText());
81+
}
82+
83+
/**
84+
* Wait for AJAX, this should be added to the framework.
85+
*
86+
* @param string $framework javascript frameworks jquery|prototype|dojo
87+
* @throws \Facebook\WebDriver\Exception\NoSuchElementException
88+
* @throws \Facebook\WebDriver\Exception\TimeOutException
89+
*/
90+
public function waitForAjax($framework = 'jquery')
91+
{
92+
switch ($framework)
93+
{
94+
case 'jquery':
95+
$code = 'return jQuery.active;';
96+
break;
97+
case 'prototype':
98+
$code = 'return Ajax.activeRequestCount;';
99+
break;
100+
case 'dojo':
101+
$code = 'return dojo.io.XMLHTTPTransport.inFlight.length;';
102+
break;
103+
default:
104+
throw new \RuntimeException('Unsupported framework');
105+
break;
106+
}
107+
// wait for at most 30s, retry every 2000ms (2s)
108+
$driver = $this->getDriver();
109+
$driver->wait(30, 2000)->until(
110+
function () use ($driver, $code) {
111+
return !$driver->executeScript($code);
112+
}
113+
);
114+
}
115+
}

0 commit comments

Comments
 (0)