Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -5,5 +5,5 @@ package: Testing
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- statistics
|
||||
- views
|
||||
- drupal:statistics
|
||||
- drupal:views
|
||||
|
|
|
@ -38,7 +38,7 @@ class StatisticsAdminTest extends BrowserTestBase {
|
|||
/**
|
||||
* The Guzzle HTTP client.
|
||||
*
|
||||
* @var \GuzzleHttp\Client;
|
||||
* @var \GuzzleHttp\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class StatisticsAttachedTest extends BrowserTestBase {
|
|||
$node = Node::create([
|
||||
'type' => 'page',
|
||||
'title' => 'Page node',
|
||||
'body' => 'body text'
|
||||
'body' => 'body text',
|
||||
]);
|
||||
$node->save();
|
||||
$this->drupalGet('node/' . $node->id());
|
||||
|
|
|
@ -39,7 +39,7 @@ class StatisticsLoggingTest extends BrowserTestBase {
|
|||
/**
|
||||
* The Guzzle HTTP client.
|
||||
*
|
||||
* @var \GuzzleHttp\Client;
|
||||
* @var \GuzzleHttp\Client
|
||||
*/
|
||||
protected $client;
|
||||
|
||||
|
@ -125,7 +125,7 @@ class StatisticsLoggingTest extends BrowserTestBase {
|
|||
$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.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Drupal\Tests\statistics\Functional;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
|
||||
|
||||
/**
|
||||
* Tests display of statistics report blocks.
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\Tests\statistics\Functional;
|
|||
* @group statistics
|
||||
*/
|
||||
class StatisticsTokenReplaceTest extends StatisticsTestBase {
|
||||
|
||||
/**
|
||||
* Creates a node, then tests the statistics tokens generated from it.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Functional\Views;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
/**
|
||||
* Tests basic integration of views data from the statistics module.
|
||||
*
|
||||
* @group statistics
|
||||
* @see
|
||||
*/
|
||||
class IntegrationTest extends ViewTestBase {
|
||||
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['statistics', 'statistics_test_views', 'node'];
|
||||
|
||||
/**
|
||||
* Stores the user object that accesses the page.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $webUser;
|
||||
|
||||
/**
|
||||
* Stores the node object which is used by the test.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $node;
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_statistics_integration'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
ViewTestData::createTestViews(get_class($this), ['statistics_test_views']);
|
||||
|
||||
// Create a new user for viewing nodes and statistics.
|
||||
$this->webUser = $this->drupalCreateUser(['access content', 'view post access counter']);
|
||||
|
||||
// Create a new user for viewing nodes only.
|
||||
$this->deniedUser = $this->drupalCreateUser(['access content']);
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->node = $this->drupalCreateNode(['type' => 'page']);
|
||||
|
||||
// Enable counting of content views.
|
||||
$this->config('statistics.settings')
|
||||
->set('count_content_views', 1)
|
||||
->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the integration of the {node_counter} table in views.
|
||||
*/
|
||||
public function testNodeCounterIntegration() {
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
||||
$this->drupalGet('node/' . $this->node->id());
|
||||
// Manually calling statistics.php, simulating ajax behavior.
|
||||
// @see \Drupal\statistics\Tests\StatisticsLoggingTest::testLogging().
|
||||
global $base_url;
|
||||
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
|
||||
$client = $this->getHttpClient();
|
||||
$client->post($stats_path, ['form_params' => ['nid' => $this->node->id()]]);
|
||||
$this->drupalGet('test_statistics_integration');
|
||||
|
||||
$expected = statistics_get($this->node->id());
|
||||
// Convert the timestamp to year, to match the expected output of the date
|
||||
// handler.
|
||||
$expected['timestamp'] = date('Y', $expected['timestamp']);
|
||||
|
||||
foreach ($expected as $field => $value) {
|
||||
$xpath = "//div[contains(@class, views-field-$field)]/span[@class = 'field-content']";
|
||||
$this->assertFieldByXpath($xpath, $value, "The $field output matches the expected.");
|
||||
}
|
||||
|
||||
$this->drupalLogout();
|
||||
$this->drupalLogin($this->deniedUser);
|
||||
$this->drupalGet('test_statistics_integration');
|
||||
$this->assertResponse(200);
|
||||
|
||||
foreach ($expected as $field => $value) {
|
||||
$xpath = "//div[contains(@class, views-field-$field)]/span[@class = 'field-content']";
|
||||
$this->assertNoFieldByXpath($xpath, $value, "The $field output is not displayed.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\FunctionalJavascript;
|
||||
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\user\Entity\Role;
|
||||
|
||||
/**
|
||||
* Tests that statistics works.
|
||||
*
|
||||
* @group system
|
||||
*/
|
||||
class StatisticsLoggingTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['node', 'statistics', 'language'];
|
||||
|
||||
/**
|
||||
* Node for tests.
|
||||
*
|
||||
* @var \Drupal\node\Entity\Node
|
||||
*/
|
||||
protected $node;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->config('statistics.settings')
|
||||
->set('count_content_views', 1)
|
||||
->save();
|
||||
|
||||
Role::load(AccountInterface::ANONYMOUS_ROLE)
|
||||
->grantPermission('view post access counter')
|
||||
->save();
|
||||
|
||||
// Add another language to enable multilingual path processor.
|
||||
ConfigurableLanguage::create(['id' => 'xx'])->save();
|
||||
$this->config('language.negotiation')->set('url.prefixes.en', 'en')->save();
|
||||
|
||||
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
|
||||
$this->node = $this->drupalCreateNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that statistics works with different addressing variants.
|
||||
*/
|
||||
public function testLoggingPage() {
|
||||
// At the first request, the page does not contain statistics counter.
|
||||
$this->assertNull($this->getStatisticsCounter('node/1'));
|
||||
$this->assertSame(1, $this->getStatisticsCounter('node/1'));
|
||||
$this->assertSame(2, $this->getStatisticsCounter('en/node/1'));
|
||||
$this->assertSame(3, $this->getStatisticsCounter('en/node/1'));
|
||||
$this->assertSame(4, $this->getStatisticsCounter('index.php/node/1'));
|
||||
$this->assertSame(5, $this->getStatisticsCounter('index.php/node/1'));
|
||||
$this->assertSame(6, $this->getStatisticsCounter('index.php/en/node/1'));
|
||||
$this->assertSame(7, $this->getStatisticsCounter('index.php/en/node/1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets counter of views by path.
|
||||
*
|
||||
* @param string $path
|
||||
* A path to node.
|
||||
*
|
||||
* @return int|null
|
||||
* A counter of views. Returns NULL if the page does not contain statistics.
|
||||
*/
|
||||
protected function getStatisticsCounter($path) {
|
||||
$this->drupalGet($path);
|
||||
// Wait while statistics module send ajax request.
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
// Resaving the node to call the hook_node_links_alter(), which is used to
|
||||
// update information on the page. See statistics_node_links_alter().
|
||||
$this->node->save();
|
||||
|
||||
$field_counter = $this->getSession()->getPage()->find('css', '.statistics-counter');
|
||||
return $field_counter ? (int) explode(' ', $field_counter->getText())[0] : NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Kernel\Migrate\d6;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of node counter data to Drupal 8.
|
||||
*
|
||||
* @group statistics
|
||||
*/
|
||||
class MigrateNodeCounterTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'statistics',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installConfig('node');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('statistics', ['node_counter']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd6_filter_format',
|
||||
'd6_user_role',
|
||||
'd6_node_settings',
|
||||
'd6_user',
|
||||
'd6_node_type',
|
||||
'd6_language_content_settings',
|
||||
'd6_node',
|
||||
'd6_node_translation',
|
||||
'statistics_node_counter',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of node counter.
|
||||
*/
|
||||
public function testStatisticsSettings() {
|
||||
$this->assertNodeCounter(1, 2, 0, 1421727536);
|
||||
$this->assertNodeCounter(2, 1, 0, 1471428059);
|
||||
$this->assertNodeCounter(3, 1, 0, 1471428153);
|
||||
$this->assertNodeCounter(4, 1, 1, 1478755275);
|
||||
$this->assertNodeCounter(5, 1, 1, 1478755314);
|
||||
$this->assertNodeCounter(10, 5, 1, 1521137459);
|
||||
$this->assertNodeCounter(12, 3, 0, 1521137469);
|
||||
|
||||
// Tests that translated node counts include all translation counts.
|
||||
$this->executeMigration('statistics_node_translation_counter');
|
||||
$this->assertNodeCounter(10, 8, 2, 1521137463);
|
||||
$this->assertNodeCounter(12, 5, 1, 1521137470);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a node counter.
|
||||
*
|
||||
* @param int $nid
|
||||
* The node ID.
|
||||
* @param int $total_count
|
||||
* The expected total count.
|
||||
* @param int $day_count
|
||||
* The expected day count.
|
||||
* @param int $timestamp
|
||||
* The expected timestamp.
|
||||
*/
|
||||
protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) {
|
||||
/** @var \Drupal\statistics\StatisticsViewsResult $statistics */
|
||||
$statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
|
||||
// @todo Remove casting after https://www.drupal.org/node/2926069 lands.
|
||||
$this->assertSame($total_count, (int) $statistics->getTotalCount());
|
||||
$this->assertSame($day_count, (int) $statistics->getDayCount());
|
||||
$this->assertSame($timestamp, (int) $statistics->getTimestamp());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Kernel\Migrate\d7;
|
||||
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Tests the migration of node counter data to Drupal 8.
|
||||
*
|
||||
* @group statistics
|
||||
*/
|
||||
class MigrateNodeCounterTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = [
|
||||
'content_translation',
|
||||
'language',
|
||||
'menu_ui',
|
||||
// Required for translation migrations.
|
||||
'migrate_drupal_multilingual',
|
||||
'node',
|
||||
'statistics',
|
||||
'text',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installConfig('node');
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('statistics', ['node_counter']);
|
||||
|
||||
$this->executeMigrations([
|
||||
'language',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
'd7_node_type',
|
||||
'd7_language_content_settings',
|
||||
'd7_node',
|
||||
'd7_node_translation',
|
||||
'statistics_node_counter',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of node counter.
|
||||
*/
|
||||
public function testStatisticsSettings() {
|
||||
$this->assertNodeCounter(1, 2, 0, 1421727536);
|
||||
$this->assertNodeCounter(2, 1, 0, 1471428059);
|
||||
$this->assertNodeCounter(4, 1, 1, 1478755275);
|
||||
|
||||
// Tests that translated node counts include all translation counts.
|
||||
$this->executeMigration('statistics_node_translation_counter');
|
||||
$this->assertNodeCounter(2, 2, 0, 1471428153);
|
||||
$this->assertNodeCounter(4, 2, 2, 1478755314);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a node counter.
|
||||
*
|
||||
* @param int $nid
|
||||
* The node ID.
|
||||
* @param int $total_count
|
||||
* The expected total count.
|
||||
* @param int $day_count
|
||||
* The expected day count.
|
||||
* @param int $timestamp
|
||||
* The expected timestamp.
|
||||
*/
|
||||
protected function assertNodeCounter($nid, $total_count, $day_count, $timestamp) {
|
||||
/** @var \Drupal\statistics\StatisticsViewsResult $statistics */
|
||||
$statistics = $this->container->get('statistics.storage.node')->fetchView($nid);
|
||||
// @todo Remove casting after https://www.drupal.org/node/2926069 lands.
|
||||
$this->assertSame($total_count, (int) $statistics->getTotalCount());
|
||||
$this->assertSame($day_count, (int) $statistics->getDayCount());
|
||||
$this->assertSame($timestamp, (int) $statistics->getTimestamp());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Kernel\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
|
||||
|
||||
/**
|
||||
* Tests the node_counter source plugin.
|
||||
*
|
||||
* @covers \Drupal\statistics\Plugin\migrate\source\NodeCounter
|
||||
*
|
||||
* @group statistics
|
||||
*/
|
||||
class NodeCounterTest extends MigrateSqlSourceTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['migrate_drupal', 'statistics'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function providerSource() {
|
||||
$tests = [];
|
||||
|
||||
// The source data.
|
||||
$tests[0]['source_data']['node_counter'] = [
|
||||
[
|
||||
'nid' => 1,
|
||||
'totalcount' => 2,
|
||||
'daycount' => 0,
|
||||
'timestamp' => 1421727536,
|
||||
],
|
||||
[
|
||||
'nid' => 2,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 0,
|
||||
'timestamp' => 1471428059,
|
||||
],
|
||||
[
|
||||
'nid' => 3,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 0,
|
||||
'timestamp' => 1471428153,
|
||||
],
|
||||
[
|
||||
'nid' => 4,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 1,
|
||||
'timestamp' => 1478755275,
|
||||
],
|
||||
[
|
||||
'nid' => 5,
|
||||
'totalcount' => 1,
|
||||
'daycount' => 1,
|
||||
'timestamp' => 1478755314,
|
||||
],
|
||||
];
|
||||
|
||||
// The expected results.
|
||||
$tests[0]['expected_data'] = $tests[0]['source_data']['node_counter'];
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\statistics\Unit;
|
||||
|
||||
use Drupal\statistics\StatisticsViewsResult;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\statistics\StatisticsViewsResult
|
||||
* @group statistics
|
||||
*/
|
||||
class StatisticsViewsResultTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests migration of node counter.
|
||||
*
|
||||
* @covers ::__construct
|
||||
*
|
||||
* @dataProvider providerTestStatisticsCount
|
||||
*/
|
||||
public function testStatisticsCount($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());
|
||||
}
|
||||
|
||||
public function providerTestStatisticsCount() {
|
||||
return [
|
||||
[2, 0, 1421727536],
|
||||
[1, 0, 1471428059],
|
||||
[1, 1, 1478755275],
|
||||
['1', '1', '1478755275'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue