Problem/Motivation

As #3004840: Fix testbot errors is resolved we can fix the tests.

The tests are currently XPath selecting wrong. Please fix them.

Proposed resolution

Fix tests and preferably use CSS Selectors.

Remaining tasks

  1. The form flow is different then tested: no messages, the edit form keeps active
  2. Delete is a link so we cannot post and it has a confirms from.
  3. Counts for number of items changed as Tour UI added tours too
  4. Having separate tests for the List, Edit Tour and Edit Tip would help improving fixing test as TestUI now always fails.

User interface changes

API changes

Data model changes

Comments

clemens.tolboom created an issue. See original summary.

clemens.tolboom’s picture

Status: Active » Needs review
StatusFileSize
new49.19 KB

I'm lost regarding running tests locally so will using the testbot

Testbot result 1.

16:07:47 Fatal error: Uncaught TypeError: Argument 3 passed to Drupal\simpletest\WebTestBase::drupalPost() must be of the type array, object given, called in /var/www/html/modules/contrib/tour_ui/src/Tests/TourUITest.php on line 91 and defined in /var/www/html/core/modules/simpletest/src/WebTestBase.php:1352

16:07:47 Stack trace:
16:07:47 #0 /var/www/html/modules/contrib/tour_ui/src/Tests/TourUITest.php(91): Drupal\simpletest\WebTestBase->drupalPost('admin/config/us...', Array, Object(Drupal\Core\StringTranslation\TranslatableMarkup))
16:07:47 #1 /var/www/html/modules/contrib/tour_ui/src/Tests/TourUITest.php(44): Drupal\tour_ui\Tests\TourUITest->editTest()

This is about CR drupalPost() and drupalPostAJAX() have been renamed

clemens.tolboom’s picture

StatusFileSize
new5.23 KB
clemens.tolboom’s picture

StatusFileSize
new5.35 KB
12:41:15 Fatal error: Uncaught Error: Call to undefined function Drupal\tour_ui\Tests\config() in /var/www/html/modules/contrib/tour_ui/src/Tests/TourUITest.php:97

config() is deprecated and should be replaced by \Drupal::config()

clemens.tolboom’s picture

StatusFileSize
new5.34 KB

clemens.tolboom’s picture

Issue summary: View changes
Status: Needs review » Needs work

I've committed work so far from patch #5.

Bottom line is

- the form flow is different then tested: no messages, the edit form keeps active
- delete is a link so we cannot post and it has a confirms from.
- counts for number of items changed as Tour UI added tours too
- I think having separate tests for the List, Edit Tour and Edit Tip would help improving fixing test as TestUI now always fails.

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom

In #3073427: Run deprecation tests tests where touched too but I was struggling with the test(s)/bot. So we continue here for fixing the last mile.

clemens.tolboom’s picture

Testbot gives (D8 and D9)

1) Drupal\Tests\tour_ui\Functional\TourUITest::testUi
DOMXPath::query(): Invalid expression

/var/www/html/vendor/symfony/dom-crawler/Crawler.php:947
/var/www/html/vendor/symfony/dom-crawler/Crawler.php:676
/var/www/html/vendor/behat/mink-browserkit-driver/src/BrowserKitDriver.php:338
/var/www/html/vendor/behat/mink/src/Driver/CoreDriver.php:101
/var/www/html/vendor/behat/mink/src/Element/Element.php:168
/var/www/html/core/tests/Drupal/Tests/BrowserTestBase.php:636
/var/www/html/modules/contrib/tour_ui/tests/src/Functional/TourUITest.php:77
/var/www/html/modules/contrib/tour_ui/tests/src/Functional/TourUITest.php:49

Local testing

Declaration of Drupal\Tests\BrowserTestBase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /.../d8/web/core/tests/Drupal/Tests/BrowserTestBase.php on line 39

PHP Unit

$ vendor/bin/phpunit --version
PHPUnit 8.5.4 by Sebastian Bergmann and contributors.
clemens.tolboom’s picture

https://www.drupal.org/docs/8/testing/phpunit-in-drupal hints for PHP Unit 6.5

Downgrading to 6.5 then run test locally on http://drupal.d8/admin/config/development/testing gives

PHPunit Test failed to complete; Error: Class "Symfony\Bridge\PhpUnit\SymfonyTestsListener" does not exist

mradcliffe’s picture

I think phpunit.xml would need to be modified if downgrading phpunit, but that may be not remembering something about the listener class exception.

My intuition is that not having double quotes around @class=:class might be causing the issue. Although I was looking in some other code, and I haven't been using xpath method directly, but using

$this->assertSession
  ->elementExists('xpath', '//input[@name="' . $known_safe_variable . '"]');

Hope that helps.

mradcliffe’s picture

Yes, something is going on with the xpath expression using the xpathQueryBuilder.

Doing something like this works, somewhat (although the assertions are failing)

// The first column contains the id.
$this->assertSession()
  ->elementExists('xpath', '//table/tbody/tr[contains(@class, "tour-test")]/td[1]');

// The second column contains the title.
$this->assertSession()
  ->elementExists('xpath', '//table/tbody/tr[contains(@class, "tour-test")]/td[2]');

// The third column contains the routes.
// This seems to fail, the element is found, but "tour_test.1" text is not found.
$this->assertSession()
  ->elementTextContains('xpath', '//table/tbody/tr[contains(@class, "tour-test")]/td[3]/div[contains(@class, "tour-routes")]', 'tour_test.1');

// The fourth column contains the number of  tips.
// Seems to fail because expected count is 1, but actual is 4.
$elements = $this->getSession()
  ->getPage()
  ->findAll('xpath', '//table/tbody/tr[contains(@class, "tour-test")]/td/[4]');
$this->assertIdentical($elements[0]->getText(), '1', 'Core tour_test/config/tour-test-2 has 1 tip');

It really doesn't like using #tour-routes in an xpath expression.

clemens.tolboom’s picture

@mradcliffe thanks for chiming in.

I am testing locally through the Drupal UI and did nothing in particular with phpunit.xml assuming Drupal will complain for wrong stuff :-/. There is ls web/core/phpunit.xml.dist.

As D9 testbot complains maybe we shorten the path to

77:    $elements = $this->xpath('#tour-routes');

Checking with https://www.php.net/manual/en/domxpath.query.php and web/core/tests/Drupal/Tests/BrowserTestBase.php:630 did not help supporting that.

But I give it a try by committing yet another snippet :-(

clemens.tolboom’s picture

Status: Needs work » Needs review
StatusFileSize
new779 bytes
clemens.tolboom’s picture

Status: Needs review » Needs work
StatusFileSize
new36.11 KB
new24.8 KB
new39.14 KB

Why is it waiting for branch ... we all know that will fail :-/

Here just some images from the https://www.drupal.org/node/1933602/qa page driving me mad

4 items / 2 configured

This is probably old versus new running tests.

4 items

2 configured

2 failed items

Waiting for branch test

Waiting for branch

clemens.tolboom’s picture

StatusFileSize
new32.6 KB

I clicked the link 'Waiting for branch to pass' then could skip this. Now got

Queueing by skipping branch

clemens.tolboom’s picture

Status: Needs work » Needs review
StatusFileSize
new912 bytes

There is NO id '#tour-routes' ONLY a class.

<tr class="tip-edit odd">
  <td>tip-edit</td>
  <td>Edit tip</td>
  <td><div class="tour-routes">tour_ui.tip.edit</div></td>
  <td>4</td>
  <td>Operations column (emptied for brevity)</td>
</tr>

As I cannot test locally hope this will do?

Status: Needs review » Needs work

The last submitted patch, 17: tour_ui-3009733-15.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

clemens.tolboom’s picture

StatusFileSize
new1.88 KB

Added code sniffer fixes and changed some stuff

> index 0717d90..7ce84a3 100755
5c5,21
< @@ -74,7 +74,7 @@ class TourUITest extends BrowserTestBase {
---
> @@ -37,14 +37,11 @@ class TourUITest extends BrowserTestBase {
>    }
>  
> -  private $randomUser;
> -
>    /**
>     * Tests the listing and editing of a tour.
>     */
>    public function testUi() {
> -    $this->randomUser = $this->drupalCreateUser(['administer tour']);
> -    $this->drupalLogin($this->randomUser);
> +    $this->drupalLogin($this->drupalCreateUser(['administer tour']));
>  
>      $this->listTest();
>      $this->editTest();
> @@ -74,14 +71,15 @@ class TourUITest extends BrowserTestBase {
10c26,27
< +    $elements = $this->xpath('#tour-routes');
---
> +    // FIX ME: trying to solve this failed. See #3009733 for further information
> +    $elements = $this->xpath('//table/tbody/tr[contains(@class, :class)]/td/div[contains(@class, :class-routes)]', [':class' => 'tour-test-1', ':class-routes' => 'tour-routes']);
13a31,38
>      // The fourth column contains the number of tips.
>      $elements = $this->xpath('//table/tbody/tr[contains(@class, :class)]/td[4]', [':class' => 'tour-test']);
>      $this->assertIdentical($elements[0]->getText(), '1', 'Core tour_test/config/tour-test-2 has 1 tip');
> -    $this->assertIdentical( $elements[1]->getText(), '3', 'Core tour_test/config/tour-test-1 has 3 tips');
> +    $this->assertIdentical($elements[1]->getText(), '3', 'Core tour_test/config/tour-test-1 has 3 tips');
>    }
>  
>    /**

clemens.tolboom’s picture

Status: Needs work » Needs review
clemens.tolboom’s picture

Status: Needs review » Needs work

The last submitted patch, 19: tour_ui-3009733-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

clemens.tolboom’s picture

Status: Needs work » Needs review
Related issues: +#3139157: Fix tests NG

I stop trying to fix this ... will make a new issue #3139157: Fix tests NG with my findings.

clemens.tolboom’s picture

Status: Needs review » Fixed

Set status to fixed (which it is not but added some fixes reported by testbot / @mradcliffe
/ @clemens.tolboom

tbc through #3139157: Fix tests NG

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.