Commit f247d598 authored by catch's avatar catch
Browse files

Issue #3341098 by quietone: Move non-migrations tests to Statistics

parent c34b922a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ class BlockConfigSchemaTest extends KernelTestBase {
    'comment',
    'forum',
    'node',
    'statistics',
    // \Drupal\block\Entity\Block->preSave() calls system_region_list().
    'system',
    'taxonomy',
+3 −17
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@

use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Core\Database\Database;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\filter\Entity\FilterFormat;
@@ -33,7 +32,7 @@ class SearchRankingTest extends BrowserTestBase {
  /**
   * {@inheritdoc}
   */
  protected static $modules = ['node', 'search', 'statistics', 'comment'];
  protected static $modules = ['node', 'search', 'comment'];

  /**
   * {@inheritdoc}
@@ -65,7 +64,7 @@ public function testRankings() {
    $this->addDefaultCommentField('node', 'page');

    // Build a list of the rankings to test.
    $node_ranks = ['sticky', 'promote', 'relevance', 'recent', 'comments', 'views'];
    $node_ranks = ['sticky', 'promote', 'relevance', 'recent', 'comments'];

    // Create nodes for testing.
    $nodes = [];
@@ -116,18 +115,7 @@ public function testRankings() {
    $this->submitForm($edit, 'Preview');
    $this->submitForm($edit, 'Save');

    // Enable counting of statistics.
    $this->config('statistics.settings')->set('count_content_views', 1)->save();

    // Simulating content views is kind of difficult in the test. Leave that
    // to the Statistics module. So instead go ahead and manually update the
    // counter for this node.
    $nid = $nodes['views'][1]->id();
    Database::getConnection()->insert('node_counter')
      ->fields(['totalcount' => 5, 'daycount' => 5, 'timestamp' => REQUEST_TIME, 'nid' => $nid])
      ->execute();

    // Run cron to update the search index and comment/statistics totals.
    // Run cron to update the search index totals.
    $this->cronRun();

    // Test that the settings form displays the content ranking section.
@@ -177,7 +165,6 @@ public function testRankings() {
      'relevance' => 0,
      'recent' => 0,
      'comments' => 0,
      'views' => 0,
    ];
    $configuration = $this->nodeSearch->getPlugin()->getConfiguration();
    foreach ($node_ranks as $var => $value) {
@@ -202,7 +189,6 @@ public function testRankings() {
      'relevance' => 0,
      'recent' => 10,
      'comments' => 1,
      'views' => 0,
    ];
    $configuration = $this->nodeSearch->getPlugin()->getConfiguration();
    foreach ($node_ranks as $var => $value) {
+116 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\statistics\Functional\search;

use Drupal\Core\Database\Database;
use Drupal\search\Entity\SearchPage;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\Traits\Core\CronRunTrait;

/**
 * Indexes content and tests ranking factors.
 *
 * @group statistics
 */
class SearchRankingTest extends BrowserTestBase {

  use CronRunTrait;

  /**
   * The node search page.
   *
   * @var \Drupal\search\SearchPageInterface
   */
  protected $nodeSearch;

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['node', 'search', 'statistics'];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);

    // Create a plugin instance.
    $this->nodeSearch = SearchPage::load('node_search');

    // Log in with sufficient privileges.
    $this->drupalLogin($this->drupalCreateUser([
      'create page content',
      'administer search',
    ]));
  }

  /**
   * Tests statistics ranking on search pages.
   */
  public function testRankings() {
    // Create nodes for testing.
    $nodes = [];
    $settings = [
      'type' => 'page',
      'title' => 'Drupal rocks',
      'body' => [['value' => "Drupal's search rocks"]],
      // Node is one day old.
      'created' => \Drupal::time()->getRequestTime() - 24 * 3600,
      'sticky' => 0,
      'promote' => 0,
    ];
    foreach ([0, 1] as $num) {
      $nodes['views'][$num] = $this->drupalCreateNode($settings);
    }

    // Enable counting of statistics.
    $this->config('statistics.settings')->set('count_content_views', 1)->save();

    // Simulating content views is kind of difficult in the test. So instead go
    // ahead and manually update the counter for this node.
    $nid = $nodes['views'][1]->id();
    Database::getConnection()->insert('node_counter')
      ->fields([
        'totalcount' => 5,
        'daycount' => 5,
        'timestamp' => \Drupal::time()->getRequestTime(),
        'nid' => $nid,
      ])
      ->execute();

    // Run cron to update the search index and statistics totals.
    $this->cronRun();

    // Test that the settings form displays the content ranking section.
    $this->drupalGet('admin/config/search/pages/manage/node_search');
    $this->assertSession()->pageTextContains('Content ranking');

    // Check that views ranking is visible and set to 0.
    $this->assertSession()->optionExists('edit-rankings-views-value', '0');

    // Test each of the possible rankings.
    $edit = [];

    // Enable views ranking.
    $edit['rankings[views][value]'] = 10;
    $this->drupalGet('admin/config/search/pages/manage/node_search');
    $this->submitForm($edit, 'Save search page');
    $this->drupalGet('admin/config/search/pages/manage/node_search');
    $this->assertSession()->optionExists('edit-rankings-views-value', '10');

    // Reload the plugin to get the up-to-date values.
    $this->nodeSearch = SearchPage::load('node_search');
    // Do the search and assert the results.
    $this->nodeSearch->getPlugin()->setSearch('rocks', [], []);
    $set = $this->nodeSearch->getPlugin()->execute();
    $this->assertEquals($nodes['views'][1]->id(), $set[0]['node']->id());
  }

}
+0 −1
Original line number Diff line number Diff line
@@ -375,7 +375,6 @@ public function testUpdatedSite() {
      'search',
      'serialization',
      'shortcut',
      'statistics',
      'syslog',
      'system',
      'taxonomy',
+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ class HandlerAllTest extends ViewTestBase {
    'locale',
    'node',
    'search',
    'statistics',
    'taxonomy',
    'user',
  ];
Loading