Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -22,27 +22,6 @@ use Drupal\Core\Session\AccountInterface;
|
|||
*/
|
||||
class StatisticsPopularBlock extends BlockBase {
|
||||
|
||||
/**
|
||||
* Number of day's top views to display.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $day_list;
|
||||
|
||||
/**
|
||||
* Number of all time views to display.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $all_time_list;
|
||||
|
||||
/**
|
||||
* Number of most recent views to display.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $last_list;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -58,23 +37,7 @@ class StatisticsPopularBlock extends BlockBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function blockAccess(AccountInterface $account) {
|
||||
$access = AccessResult::allowedIfHasPermission($account, 'access content');
|
||||
if ($account->hasPermission('access content')) {
|
||||
$daytop = $this->configuration['top_day_num'];
|
||||
if (!$daytop || !($result = statistics_title_list('daycount', $daytop)) || !($this->day_list = node_title_list($result, $this->t("Today's:")))) {
|
||||
return AccessResult::forbidden()->inheritCacheability($access);
|
||||
}
|
||||
$alltimetop = $this->configuration['top_all_num'];
|
||||
if (!$alltimetop || !($result = statistics_title_list('totalcount', $alltimetop)) || !($this->all_time_list = node_title_list($result, $this->t('All time:')))) {
|
||||
return AccessResult::forbidden()->inheritCacheability($access);
|
||||
}
|
||||
$lasttop = $this->configuration['top_last_num'];
|
||||
if (!$lasttop || !($result = statistics_title_list('timestamp', $lasttop)) || !($this->last_list = node_title_list($result, $this->t('Last viewed:')))) {
|
||||
return AccessResult::forbidden()->inheritCacheability($access);
|
||||
}
|
||||
return $access;
|
||||
}
|
||||
return AccessResult::forbidden()->inheritCacheability($access);
|
||||
return AccessResult::allowedIfHasPermission($account, 'access content');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,18 +86,25 @@ class StatisticsPopularBlock extends BlockBase {
|
|||
public function build() {
|
||||
$content = array();
|
||||
|
||||
if ($this->day_list) {
|
||||
$content['top_day'] = $this->day_list;
|
||||
$content['top_day']['#suffix'] = '<br />';
|
||||
if ($this->configuration['top_day_num'] > 0) {
|
||||
$result = statistics_title_list('daycount', $this->configuration['top_day_num']);
|
||||
if ($result) {
|
||||
$content['top_day'] = node_title_list($result, $this->t("Today's:"));
|
||||
$content['top_day']['#suffix'] = '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->all_time_list) {
|
||||
$content['top_all'] = $this->all_time_list;
|
||||
$content['top_all']['#suffix'] = '<br />';
|
||||
if ($this->configuration['top_all_num'] > 0) {
|
||||
$result = statistics_title_list('totalcount', $this->configuration['top_all_num']);
|
||||
if ($result) {
|
||||
$content['top_all'] = node_title_list($result, $this->t('All time:'));
|
||||
$content['top_all']['#suffix'] = '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->last_list) {
|
||||
$content['top_last'] = $this->last_list;
|
||||
if ($this->configuration['top_last_num'] > 0) {
|
||||
$result = statistics_title_list('timestamp', $this->configuration['top_last_num']);
|
||||
$content['top_last'] = node_title_list($result, $this->t('Last viewed:'));
|
||||
$content['top_last']['#suffix'] = '<br />';
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
/**
|
||||
* Upgrade variables to statistics.settings.yml.
|
||||
*
|
||||
* @group statistics
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateStatisticsConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
|
@ -31,7 +31,6 @@ class MigrateStatisticsConfigsTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->loadDumps(['Variable.php']);
|
||||
$this->executeMigration('d6_statistics_settings');
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class StatisticsLoggingTest extends WebTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'statistics', 'block');
|
||||
public static $modules = array('node', 'statistics', 'block', 'locale');
|
||||
|
||||
/**
|
||||
* User with permissions to create and edit pages.
|
||||
|
@ -33,6 +33,13 @@ class StatisticsLoggingTest extends WebTestBase {
|
|||
*/
|
||||
protected $authUser;
|
||||
|
||||
/**
|
||||
* Associative array representing a hypothetical Drupal language.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* The Guzzle HTTP client.
|
||||
*
|
||||
|
@ -48,11 +55,31 @@ class StatisticsLoggingTest extends WebTestBase {
|
|||
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
|
||||
}
|
||||
|
||||
$this->authUser = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
|
||||
$this->authUser = $this->drupalCreateUser(array(
|
||||
// For node creation.
|
||||
'access content',
|
||||
'create page content',
|
||||
'edit own page content',
|
||||
// For language negotiation administration.
|
||||
'administer languages',
|
||||
'access administration pages',
|
||||
));
|
||||
|
||||
// Ensure we have a node page to access.
|
||||
$this->node = $this->drupalCreateNode(array('title' => $this->randomMachineName(255), 'uid' => $this->authUser->id()));
|
||||
|
||||
// Add a custom language and enable path-based language negotiation.
|
||||
$this->drupalLogin($this->authUser);
|
||||
$this->language = array(
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => 'xx',
|
||||
'label' => $this->randomMachineName(16),
|
||||
'direction' => 'ltr',
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $this->language, t('Add custom language'));
|
||||
$this->drupalPostForm('admin/config/regional/language/detection', array('language_interface[enabled][language-url]' => 1), t('Save settings'));
|
||||
$this->drupalLogout();
|
||||
|
||||
// Enable access logging.
|
||||
$this->config('statistics.settings')
|
||||
->set('count_content_views', 1)
|
||||
|
@ -69,32 +96,40 @@ class StatisticsLoggingTest extends WebTestBase {
|
|||
* Verifies node hit counter logging and script placement.
|
||||
*/
|
||||
function testLogging() {
|
||||
global $base_url;
|
||||
$path = 'node/' . $this->node->id();
|
||||
$module_path = drupal_get_path('module', 'statistics');
|
||||
$stats_path = $base_url . '/' . $module_path . '/statistics.php';
|
||||
$expected_library = $module_path . '/statistics.js';
|
||||
$expected_settings = '"statistics":{"data":{"nid":"' . $this->node->id() . '"}';
|
||||
$stats_path = base_path() . $module_path . '/statistics.php';
|
||||
$lib_path = base_path() . $module_path . '/statistics.js';
|
||||
$expected_library = '/<script src=".*?' . preg_quote($lib_path, '/.') . '.*?">/is';
|
||||
|
||||
// Verify that logging scripts are not found on a non-node page.
|
||||
$this->drupalGet('node');
|
||||
$this->assertNoRaw($expected_library, 'Statistics library JS not found on node page.');
|
||||
$this->assertNoRaw($expected_settings, 'Statistics settings not found on node page.');
|
||||
$settings = $this->getDrupalSettings();
|
||||
$this->assertNoPattern($expected_library, 'Statistics library JS not found on node page.');
|
||||
$this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.');
|
||||
|
||||
// Verify that logging scripts are not found on a non-existent node page.
|
||||
$this->drupalGet('node/9999');
|
||||
$this->assertNoRaw($expected_library, 'Statistics library JS not found on non-existent node page.');
|
||||
$this->assertNoRaw($expected_settings, 'Statistics settings not found on non-existent node page.');
|
||||
$settings = $this->getDrupalSettings();
|
||||
$this->assertNoPattern($expected_library, 'Statistics library JS not found on non-existent node page.');
|
||||
$this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.');
|
||||
|
||||
// Verify that logging scripts are found on a valid node page.
|
||||
$this->drupalGet($path);
|
||||
$this->assertRaw($expected_library, 'Found statistics library JS on node page.');
|
||||
$this->assertRaw($expected_settings, 'Found statistics settings on node page.');
|
||||
$settings = $this->getDrupalSettings();
|
||||
$this->assertPattern($expected_library, 'Found statistics library JS on node page.');
|
||||
$this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on node page.');
|
||||
|
||||
// Verify the same when loading the site in a non-default language.
|
||||
$this->drupalGet($this->language['langcode'] . '/' . $path);
|
||||
$settings = $this->getDrupalSettings();
|
||||
$this->assertPattern($expected_library, 'Found statistics library JS on a valid node page in a non-default language.');
|
||||
$this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on valid node page in a non-default language.');
|
||||
|
||||
// Manually call statistics.php to simulate ajax data collection behavior.
|
||||
$nid = $this->node->id();
|
||||
$post = array('nid' => $nid);
|
||||
$this->client->post($stats_path, array('form_params' => $post));
|
||||
global $base_root;
|
||||
$post = array('nid' => $this->node->id());
|
||||
$this->client->post($base_root . $stats_path, array('form_params' => $post));
|
||||
$node_counter = statistics_get($this->node->id());
|
||||
$this->assertIdentical($node_counter['totalcount'], '1');
|
||||
}
|
||||
|
|
|
@ -5,3 +5,5 @@ package: Core
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
configure: statistics.settings
|
||||
dependencies:
|
||||
- node
|
||||
|
|
|
@ -57,3 +57,17 @@ function statistics_schema() {
|
|||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the Statistics module if the node module is not enabled.
|
||||
*/
|
||||
function statistics_update_8001() {
|
||||
if (!\Drupal::moduleHandler()->moduleExists('node')) {
|
||||
if (\Drupal::service('module_installer')->uninstall(array('statistics'), TRUE)) {
|
||||
return 'The statistics module depends on the node module and has therefore been uninstalled.';
|
||||
}
|
||||
else {
|
||||
return 'There was an error uninstalling the statistcs module.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue