Skip to content

Commit d329140

Browse files
authored
Merge pull request #104 from VSEphpbb/updates
Minor updates and testing
2 parents 2e90f10 + c981193 commit d329140

5 files changed

Lines changed: 140 additions & 11 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"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"name": "Matt Friedman",
27-
"homepage": "http://mattfriedman.me",
27+
"homepage": "http://vsephpbb.github.io",
2828
"role": "Contributor"
2929
},
3030
{

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/controller/idea_controller_test.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public function controller_test_data()
2828
array(2, 'delete', 'delete', true, true, 'trigger_error', 200), // ajax delete success (confirm true)
2929
array(3, 'duplicate', 'set_duplicate', true, true, 'true', 200), // ajax set duplicate success
3030
array(3, 'duplicate', '', true, false, 'false', 200), // ajax set duplicate fail
31-
array(4, 'removevote', 'remove_vote', true, true, 'true', 200), // ajax set title success
32-
array(4, 'removevote', '', true, false, '"You do not have the necessary permissions to complete this operation."', 200), // ajax set title fail
31+
array(4, 'removevote', 'remove_vote', true, true, 'true', 200), // ajax remove vote success
32+
array(4, 'removevote', 'remove_vote', true, true, 'false', 200, ['idea_status' => \phpbb\ideas\factory\ideas::$statuses['DUPLICATE']]), // ajax remove vote not allowed
33+
array(4, 'removevote', 'remove_vote', true, true, 'false', 200, ['idea_status' => \phpbb\ideas\factory\ideas::$statuses['IMPLEMENTED']]), // ajax remove vote not allowed
34+
array(4, 'removevote', '', true, false, '"You do not have the necessary permissions to complete this operation."', 200), // ajax remove vote fail
3335
array(5, 'rfc', 'set_rfc', true, true, 'true', 200), // ajax set rfc success
3436
array(5, 'rfc', '', true, false, 'false', 200), // ajax set rfc fail
3537
array(6, 'status', 'change_status', true, true, 'true', 200), // ajax set status success
@@ -38,8 +40,10 @@ public function controller_test_data()
3840
array(7, 'ticket', '', true, false, 'false', 200), // ajax set ticket fail
3941
array(8, 'title', 'set_title', true, true, 'true', 200), // ajax set title success
4042
array(8, 'title', '', true, false, 'false', 200), // ajax set title fail
41-
array(9, 'vote', 'vote', true, true, 'true', 200), // ajax set title success
42-
array(9, 'vote', '', true, false, '"You do not have the necessary permissions to complete this operation."', 200), // ajax set title fail
43+
array(9, 'vote', 'vote', true, true, 'true', 200), // ajax vote success
44+
array(9, 'vote', 'vote', true, true, 'false', 200, ['idea_status' => \phpbb\ideas\factory\ideas::$statuses['DUPLICATE']]), // ajax vote not allowed
45+
array(9, 'vote', 'vote', true, true, 'false', 200, ['idea_status' => \phpbb\ideas\factory\ideas::$statuses['IMPLEMENTED']]), // ajax vote not allowed
46+
array(9, 'vote', '', true, false, '"You do not have the necessary permissions to complete this operation."', 200), // ajax vote fail
4347
array(10, 'implemented', 'set_implemented', true, true, 'true', 200), // ajax set implemented success
4448
array(10, 'implemented', '', true, false, 'false', 200), // ajax set implemented fail
4549
);
@@ -50,15 +54,21 @@ public function controller_test_data()
5054
*
5155
* @dataProvider controller_test_data
5256
*/
53-
public function test_controller($idea_id, $mode, $callback, $is_ajax, $authorised, $expected, $status_code)
57+
public function test_controller($idea_id, $mode, $callback, $is_ajax, $authorised, $expected, $status_code, $additional_data = [])
5458
{
5559
// mock some basic idea data
5660
$this->ideas->expects($this->any())
5761
->method('get_idea')
58-
->will($this->returnValue(array('idea_id' => $idea_id, 'idea_author' => 2)));
62+
->will($this->returnValue(
63+
array_merge(array(
64+
'idea_id' => $idea_id,
65+
'idea_author' => 2,
66+
'idea_status' => \phpbb\ideas\factory\ideas::$statuses['NEW']
67+
), $additional_data))
68+
);
5969

6070
// mock a result from each method called by the idea controller
61-
if ($callback !== '')
71+
if ($expected === 'true')
6272
{
6373
$this->ideas->expects($this->once())
6474
->method(($callback))

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)