Problem/Motivation

This is a follow-up to #2500521: Upgrade path for Statistics 7.x and 6.x where we identified that StatisticsViewsResult was (sometimes) returning strings when it should only ever return integers.

Proposed resolution

Cast the inputs to integer in the constructor.

Remaining tasks

Write patch.
Review patch.
etc.
Removes @todo from Drupal\Tests\statistics\Kernel\Migrate\d6\MigrateNodeCounterTest and Drupal\Tests\statistics\Kernel\Migrate\d7\MigrateNodeCounterTest (assuming #2500521: Upgrade path for Statistics 7.x and 6.x lands first).

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jo Fitzgerald created an issue. See original summary.

jofitz’s picture

Assigned: jofitz » Unassigned
Issue summary: View changes
Status: Active » Needs review
FileSize
1.42 KB

Cast the inputs to StatisticsViewsResult to integer in the constructor.

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Thanks! It's updating one assertion, but can we also add an explicit test that we always get integer output even when the input is strings?

jofitz’s picture

@xjm Can you explain a little more, please? I'm sorry, I don't understand what you are asking for.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +migrate

@xjm means: construct a StatisticsViewsResult object, pass 3 strings, verify you get back 3 integers when you use the 3 getters.

My inclination is that that seems a disproportionate amount of testing for the bugfix. OTOH, this appears to not be a problem in core, only with migrate? Then isn't this a bug in migrate?

heddn’s picture

Status: Postponed (maintainer needs more info) » Needs work

Re #7: it isn't so much a bug in migrate as a bug in the statistics API that migrate is using in a test. Back to NW for #4.

heddn’s picture

Status: Needs work » Needs review
Related issues: +#2930101: i18n / statistics - node counter not updated for translations
FileSize
1.33 KB
2.92 KB

This will also need a re-roll if/when #2930101: i18n / statistics - node counter not updated for translations lands. Since it is critical, let's soft-block here. Or get this in super fast. Here's a patch with the added tests.

Status: Needs review » Needs work

The last submitted patch, 9: 2926069-9.patch, failed testing. View results

heddn’s picture

Status: Needs work » Needs review
FileSize
3 KB
753 bytes
timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

LGTM

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php
    @@ -0,0 +1,46 @@
    +  public function testStatisticsCount() {
    +    $this->assertNodeCounter(2, 0, 1421727536);
    +    $this->assertNodeCounter(1, 0, 1471428059);
    +    $this->assertNodeCounter(1, 1, 1478755275);
    +    $this->assertNodeCounter('1', '1', '1478755275');
    +  }
    ...
    +   * @param int $total_count
    +   *   The expected total count.
    +   * @param int $day_count
    +   *   The expected day count.
    +   * @param int $timestamp
    +   *   The expected timestamp.
    

    int|string right? as that's the point of the test to assert that if strings are input then ints are output.

    Also I think this test would be better as a data provider rather than a single test.

  2. +++ b/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php
    @@ -0,0 +1,46 @@
    +   * @param int $nid
    +   *   The node ID.
    

    This param is not passed.

jofitz’s picture

Status: Needs work » Needs review
FileSize
3.13 KB
1.58 KB

Addressed both of @alexpott's comments in #13.

I'm not sure if there's any point in retaining assertNodeCounter(), but I've left it for now.

borisson_’s picture

Status: Needs review » Needs work
+++ b/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php
@@ -0,0 +1,52 @@
+
+

Should be only one empty line

I don't think assertNodeCounter is needed as it's used only once.

Dinesh18’s picture

Status: Needs work » Needs review
FileSize
474 bytes
3.14 KB

removed the extra empty line as per comment #15.
Here is the patch and interdiff.

dawehner’s picture

+++ b/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php
@@ -0,0 +1,51 @@
+  protected function assertNodeCounter($total_count, $day_count, $timestamp) {
...
+    $this->assertSame((int) $total_count, $statistics->getTotalCount());
+    $this->assertSame((int) $day_count, $statistics->getDayCount());
+    $this->assertSame((int) $timestamp, $statistics->getTimestamp());

What about providing also the expected values?

jofitz’s picture

What do you mean, @dawehner?

borisson_’s picture

I'm not sure about adding assertNodeCounter as a seperate method, it doesn't add any value to extract this, as it's only used in one place. I already mentioned this in #15. If we do that, I feel like @dawehner's remark will be resolved as well.

jofitz’s picture

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, looks great!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 2926069-20.patch, failed testing. View results

Mixologic’s picture

Status: Needs work » Reviewed & tested by the community

Testbot Snafu.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 2926069-20.patch, failed testing. View results

bibliophileaxe’s picture

Status: Needs work » Reviewed & tested by the community

Testbot issue.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed c01bed2b2d to 8.6.x and c71f50f5ad to 8.5.x. Thanks!

  • alexpott committed c01bed2 on 8.6.x
    Issue #2926069 by Jo Fitzgerald, heddn, Dinesh18, borisson_, xjm:...

  • alexpott committed c71f50f on 8.5.x
    Issue #2926069 by Jo Fitzgerald, heddn, Dinesh18, borisson_, xjm:...

Status: Fixed » Closed (fixed)

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