Problem/Motivation

Currently, SelectTableSortDefaultTest is the only test in core that explicitly covers tablesort and also does a ->drupalGet() in the test to cover rendered output.

tablesort_header() will add titles to the links in the header row, but SelectTableSortDefaultTest does not check for these.

Proposed resolution

Add a new test to check the rendered output for the link title.

Remaining tasks

  • Write / update the test.
  • Review the test.

User interface changes

None.

API changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Unfrozen changes Unfrozen because it only changes test code.
Prioritized changes The main goal of this issue is increased test coverage.
Disruption None
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpdonadio’s picture

Issue tags: +Novice
mpdonadio’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
1.11 KB

First pass at a test.

cilefen’s picture

+++ b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php
@@ -81,4 +81,22 @@ function testTableSortDefaultSort() {
+    // Verify that the links in the header row are correct.
+    // 1. Look for a link with the expected text.
+    // 2. Make sure the href is the page we just requested.
+    // 3. Make sure the link title is there, and correct.
+

These comments are unnecessary as a block. Either remove them or put each respective one above the actual check.

mpdonadio’s picture

Assigned: mpdonadio » Unassigned
FileSize
907 bytes
925 bytes

Removed unnecessary comments.

star-szr’s picture

Category: Feature request » Task

I think adding test coverage should be a task per https://www.drupal.org/core/issue-category.

johndtaylor’s picture

Status: Needs review » Reviewed & tested by the community

Restest passed. Analysis of test code made sense.

mpdonadio’s picture

Issue summary: View changes

I'm not sure if I did the beta phase eval properly. This just adds a test where we didn't have test coverage before. So it reduces fragility w/o any disruption.

alexpott’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php
@@ -81,4 +81,17 @@ function testTableSortDefaultSort() {
+  function testTableSortHeaderLinks() {

Let's merge this into testTableSortDefaultSort since having two test methods do assertions against the same page seems wasteful.

I've completed the beta evaluation properly.

alexpott’s picture

Issue summary: View changes
mpdonadio’s picture

Status: Needs work » Needs review
FileSize
1.13 KB
1.38 KB

Merged code into the other test method.

cilefen’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php
@@ -71,7 +71,8 @@ function testTableSortQueryFirst() {
+   * Confirms that no error is thrown if no sort is set in a tableselect, and
+   * that header links are correct.
    */

The first line must be one sentence, alone.

martin107’s picture

Status: Needs work » Needs review
FileSize
1.18 KB
799 bytes

Tweaked the comments.

cdanik’s picture

Here at drupalcon LA sprints. I'll take a look at this.

cdanik’s picture

Matches drupal code standards. https://www.drupal.org/coding-standards

I applied the patch, seems OK. I ran the database tests locally, and they passed.

connorwk’s picture

Here at the LA sprints. Going to remove some extra white-space from the previous patch and see if I can break the code, this is to see if the test actually works.

lauriii’s picture

Status: Needs review » Needs work

Thanks for working on this issue. With this patch we can make the test coverage of Drupal 8 again better! I did still find one nitpick from the patch:

+++ b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php
@@ -71,7 +71,10 @@ function testTableSortQueryFirst() {
+   *  Specifically that no sort is set in a tableselect, and that header links
+   *  are correct.

Indentation is wrong

martin107’s picture

Status: Needs work » Needs review
FileSize
1.18 KB
773 bytes

thank you fixed.

connorwk’s picture

I see martin107 already submitted the patch for the indentation but I broke code in-order to be sure the test fails in a local dev and it did fail.
So the test seems to be working as intended.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: add_test_coverage_for-2357997-18.patch, failed testing.

The last submitted patch, 18: add_test_coverage_for-2357997-18.patch, failed testing.

lauriii’s picture

Status: Needs work » Reviewed & tested by the community
xjm’s picture

Issue summary: View changes

Thanks everyone for your work here.

Whenever a patch fails tests like that, please always document what the fail was before clicking retest. Seeing two fails and retests in a row like that raises a red flag that the patch might be introducing a random test failure. Especially in a patch like this that is specifically expanding test coverage.

There are no typical gotchas like random value generation, but I'm currently running the specific test from the patch locally 100 times to ensure that there's not some random failure with the assertion.

+++ b/core/modules/system/src/Tests/Database/SelectTableSortDefaultTest.php
@@ -80,5 +83,10 @@ function testTableSortDefaultSort() {
+    $this->assertPattern('/\<a.*title\=\"' . t('sort by Username') . '\".*\>/');

An xpath assertion might be better here? There are a handful of uses of assertPattern() in core for markup, though, so I can't think of a reason to actually block the patch on that. I wondered if this could introduce a random fail in circumstances when something with the markup output changed, but also couldn't think of a way that could happen.

Leaving at RTBC while my laptop warms the house. :P

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Alrighty, no fails, so I'm at least confident this isn't introducing some high-frequency random fail. :)

This issue only changes test code, so per https://www.drupal.org/core/beta-changes, this can be completed any time during the Drupal 8 beta phase. Committed and pushed to 8.0.x. Thanks!

  • xjm committed 618ad10 on 8.0.x
    Issue #2357997 by mpdonadio, martin107, lauriii, cilefen, alexpott,...

Status: Fixed » Closed (fixed)

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