Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -0,0 +1,57 @@
<?php
namespace Drupal\Tests\statistics\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\node\Entity\Node;
/**
* Tests if statistics.js is loaded when content is not printed.
*
* @group statistics
*/
class StatisticsAttachedTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'statistics'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(['type' => 'page']);
// Install "statistics_test_attached" and set it as the default theme.
$theme = 'statistics_test_attached';
\Drupal::service('theme_handler')->install([$theme]);
$this->config('system.theme')
->set('default', $theme)
->save();
// Installing a theme will cause the kernel terminate event to rebuild the
// router. Simulate that here.
\Drupal::service('router.builder')->rebuildIfNeeded();
}
/**
* Tests if statistics.js is loaded when content is not printed.
*/
public function testAttached() {
$node = Node::create([
'type' => 'page',
'title' => 'Page node',
'body' => 'body text'
]);
$node->save();
$this->drupalGet('node/' . $node->id());
$this->assertRaw('core/modules/statistics/statistics.js', 'Statistics library is available');
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Drupal\Tests\statistics\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Defines a base class for testing the Statistics module.
*/
abstract class StatisticsTestBase extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['node', 'block', 'ban', 'statistics'];
/**
* User with permissions to ban IP's.
*
* @var \Drupal\user\UserInterface
*/
protected $blockingUser;
protected function setUp() {
parent::setUp();
// Create Basic page node type.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
}
// Create user.
$this->blockingUser = $this->drupalCreateUser([
'access administration pages',
'access site reports',
'ban IP addresses',
'administer blocks',
'administer statistics',
'administer users',
]);
$this->drupalLogin($this->blockingUser);
// Enable logging.
$this->config('statistics.settings')
->set('count_content_views', 1)
->save();
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace Drupal\Tests\statistics\Functional;
/**
* Generates text using placeholders for dummy content to check statistics token
* replacement.
*
* @group statistics
*/
class StatisticsTokenReplaceTest extends StatisticsTestBase {
/**
* Creates a node, then tests the statistics tokens generated from it.
*/
public function testStatisticsTokenReplacement() {
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
// Create user and node.
$user = $this->drupalCreateUser(['create page content']);
$this->drupalLogin($user);
$node = $this->drupalCreateNode(['type' => 'page', 'uid' => $user->id()]);
// Hit the node.
$this->drupalGet('node/' . $node->id());
// Manually calling statistics.php, simulating ajax behavior.
$nid = $node->id();
$post = http_build_query(['nid' => $nid]);
$headers = ['Content-Type' => 'application/x-www-form-urlencoded'];
global $base_url;
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php';
$client = \Drupal::httpClient();
$client->post($stats_path, ['headers' => $headers, 'body' => $post]);
$statistics = statistics_get($node->id());
// Generate and test tokens.
$tests = [];
$tests['[node:total-count]'] = 1;
$tests['[node:day-count]'] = 1;
$tests['[node:last-view]'] = format_date($statistics['timestamp']);
$tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'short');
// Test to make sure that we generated something for each token.
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$output = \Drupal::token()->replace($input, ['node' => $node], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', ['%token' => $input]));
}
}
}

View file

@ -2,7 +2,7 @@
namespace Drupal\Tests\statistics\Kernel\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
@ -17,7 +17,7 @@ class MigrateStatisticsConfigsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('statistics');
public static $modules = ['statistics'];
/**
* {@inheritdoc}
@ -32,8 +32,6 @@ class MigrateStatisticsConfigsTest extends MigrateDrupal6TestBase {
*/
public function testStatisticsSettings() {
$config = $this->config('statistics.settings');
$this->assertIdentical(FALSE, $config->get('access_log.enabled'));
$this->assertIdentical(259200, $config->get('access_log.max_lifetime'));
$this->assertIdentical(0, $config->get('count_content_views'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'statistics.settings', $config->get());
}

View file

@ -2,7 +2,7 @@
namespace Drupal\Tests\statistics\Kernel\Migrate\d7;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
@ -17,7 +17,7 @@ class MigrateStatisticsConfigsTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('statistics');
public static $modules = ['statistics'];
/**
* {@inheritdoc}
@ -32,8 +32,6 @@ class MigrateStatisticsConfigsTest extends MigrateDrupal7TestBase {
*/
public function testStatisticsSettings() {
$config = $this->config('statistics.settings');
$this->assertIdentical(TRUE, $config->get('access_log.enabled'));
$this->assertIdentical(3600, $config->get('access_log.max_lifetime'));
$this->assertIdentical(1, $config->get('count_content_views'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'statistics.settings', $config->get());
}