diff --git a/core/modules/statistics/src/StatisticsViewsResult.php b/core/modules/statistics/src/StatisticsViewsResult.php index ef0db9775e..3b9247073a 100644 --- a/core/modules/statistics/src/StatisticsViewsResult.php +++ b/core/modules/statistics/src/StatisticsViewsResult.php @@ -23,9 +23,9 @@ class StatisticsViewsResult { protected $timestamp; public function __construct($total_count, $day_count, $timestamp) { - $this->totalCount = $total_count; - $this->dayCount = $day_count; - $this->timestamp = $timestamp; + $this->totalCount = (int) $total_count; + $this->dayCount = (int) $day_count; + $this->timestamp = (int) $timestamp; } /** diff --git a/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php b/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php index 09565aefae..8ac0014761 100644 --- a/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php +++ b/core/modules/statistics/tests/src/Functional/StatisticsLoggingTest.php @@ -125,7 +125,7 @@ public function testLogging() { $post = ['nid' => $this->node->id()]; $this->client->post($base_root . $stats_path, ['form_params' => $post]); $node_counter = statistics_get($this->node->id()); - $this->assertIdentical($node_counter['totalcount'], '1'); + $this->assertIdentical($node_counter['totalcount'], 1); // Try fetching statistics for an invalid node ID and verify it returns // FALSE. diff --git a/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php b/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php new file mode 100644 index 0000000000..662f36eda4 --- /dev/null +++ b/core/modules/statistics/tests/src/Unit/StatisticsViewsResultTest.php @@ -0,0 +1,51 @@ +assertNodeCounter($total_count, $day_count, $timestamp); + } + + public function providerTestStatisticsCount() { + return [ + [2, 0, 1421727536], + [1, 0, 1471428059], + [1, 1, 1478755275], + ['1', '1', '1478755275'], + ]; + } + + /** + * Asserts various aspects of a node counter. + * + * @param int|string $total_count + * The expected total count. + * @param int|string $day_count + * The expected day count. + * @param int|string $timestamp + * The expected timestamp. + */ + protected function assertNodeCounter($total_count, $day_count, $timestamp) { + $statistics = new StatisticsViewsResult($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()); + } + +}