|
| 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