diff --git a/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php index 1a19761..ae8b2c2 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php +++ b/core/modules/statistics/lib/Drupal/statistics/Plugin/Block/StatisticsPopularBlock.php @@ -25,21 +25,21 @@ class StatisticsPopularBlock extends BlockBase { * * @var int */ - protected $day_list; + protected $dayList; /** * Number of all time views to display. * * @var int */ - protected $all_time_list; + protected $allTimeList; /** * Number of most recent views to display. * * @var int */ - protected $last_list; + protected $lastList; /** * {@inheritdoc} @@ -48,7 +48,7 @@ public function defaultConfiguration() { return array( 'top_day_num' => 0, 'top_all_num' => 0, - 'top_last_num' => 0 + 'top_last_num' => 0, ); } @@ -58,15 +58,15 @@ public function defaultConfiguration() { public function access(AccountInterface $account) { 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, t("Today's:")))) { + if (!$daytop || !($result = statistics_title_list('daycount', $daytop)) || !($this->dayList = node_title_list($result, t("Today's:")))) { return FALSE; } $alltimetop = $this->configuration['top_all_num']; - if (!$alltimetop || !($result = statistics_title_list('totalcount', $alltimetop)) || !($this->all_time_list = node_title_list($result, t('All time:')))) { + if (!$alltimetop || !($result = statistics_title_list('totalcount', $alltimetop)) || !($this->allTimeList = node_title_list($result, t('All time:')))) { return FALSE; } $lasttop = $this->configuration['top_last_num']; - if (!$lasttop || !($result = statistics_title_list('timestamp', $lasttop)) || !($this->last_list = node_title_list($result, t('Last viewed:')))) { + if (!$lasttop || !($result = statistics_title_list('timestamp', $lasttop)) || !($this->lastList = node_title_list($result, t('Last viewed:')))) { return FALSE; } return TRUE; @@ -82,11 +82,11 @@ public function blockForm($form, &$form_state) { $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40); $numbers = array('0' => t('Disabled')) + array_combine($numbers, $numbers); $form['statistics_block_top_day_num'] = array( - '#type' => 'select', - '#title' => t("Number of day's top views to display"), - '#default_value' => $this->configuration['top_day_num'], - '#options' => $numbers, - '#description' => t('How many content items to display in "day" list.'), + '#type' => 'select', + '#title' => t("Number of day's top views to display"), + '#default_value' => $this->configuration['top_day_num'], + '#options' => $numbers, + '#description' => t('How many content items to display in "day" list.'), ); $form['statistics_block_top_all_num'] = array( '#type' => 'select', @@ -120,18 +120,18 @@ public function blockSubmit($form, &$form_state) { public function build() { $content = array(); - if ($this->day_list) { - $content['top_day'] = $this->day_list; + if ($this->dayList) { + $content['top_day'] = $this->dayList; $content['top_day']['#suffix'] = '
'; } - if ($this->all_time_list) { - $content['top_all'] = $this->all_time_list; + if ($this->allTimeList) { + $content['top_all'] = $this->allTimeList; $content['top_all']['#suffix'] = '
'; } - if ($this->last_list) { - $content['top_last'] = $this->last_list; + if ($this->lastList) { + $content['top_last'] = $this->lastList; $content['top_last']['#suffix'] = '
'; } diff --git a/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php index d4683a9..7842a45 100644 --- a/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php +++ b/core/modules/statistics/lib/Drupal/statistics/StatisticsSettingsForm.php @@ -93,4 +93,3 @@ public function submitForm(array &$form, array &$form_state) { parent::submitForm($form, $form_state); } } - diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php index e8abd34..09906ab 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php @@ -28,14 +28,14 @@ class StatisticsAdminTest extends WebTestBase { * * A fully loaded user object, or FALSE if user creation failed. */ - protected $privileged_user; + protected $privilegedUser; /** * A page node for which to check content statistics. * * @var object */ - protected $test_node; + protected $testNode; /** * The Guzzle HTTP client. @@ -44,24 +44,35 @@ class StatisticsAdminTest extends WebTestBase { */ protected $client; + /** + * Modules to enable. + */ public static function getInfo() { return array( 'name' => 'Test statistics admin.', 'description' => 'Tests the statistics admin.', - 'group' => 'Statistics' + 'group' => 'Statistics', ); } - function setUp() { + /** + * {@inheritdoc} + */ + public function setUp() { parent::setUp(); // Create Basic page node type. if ($this->profile != 'standard') { $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); } - $this->privileged_user = $this->drupalCreateUser(array('administer statistics', 'view post access counter', 'create page content')); - $this->drupalLogin($this->privileged_user); - $this->test_node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->privileged_user->id())); + $this->privilegedUser = $this->drupalCreateUser( + array( + 'administer statistics', + 'view post access counter', + 'create page content', + )); + $this->drupalLogin($this->privilegedUser); + $this->testNode = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->privilegedUser->id())); $this->client = \Drupal::httpClient(); $this->client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); } @@ -69,7 +80,7 @@ function setUp() { /** * Verifies that the statistics settings page works. */ - function testStatisticsSettings() { + public function testStatisticsSettings() { $config = \Drupal::config('statistics.settings'); $this->assertFalse($config->get('count_content_views'), 'Count content view log is disabled by default.'); @@ -80,21 +91,21 @@ function testStatisticsSettings() { $this->assertTrue($config->get('count_content_views'), 'Count content view log is enabled.'); // Hit the node. - $this->drupalGet('node/' . $this->test_node->id()); + $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. - $nid = $this->test_node->id(); + $nid = $this->testNode->id(); $post = array('nid' => $nid); global $base_url; - $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; + $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array(), $post)->send(); // Hit the node again (the counter is incremented after the hit, so // "1 view" will actually be shown when the node is hit the second time). - $this->drupalGet('node/' . $this->test_node->id()); + $this->drupalGet('node/' . $this->testNode->id()); $this->client->post($stats_path, array(), $post)->send(); $this->assertText('1 view', 'Node is viewed once.'); - $this->drupalGet('node/' . $this->test_node->id()); + $this->drupalGet('node/' . $this->testNode->id()); $this->client->post($stats_path, array(), $post)->send(); $this->assertText('2 views', 'Node is viewed 2 times.'); } @@ -102,29 +113,29 @@ function testStatisticsSettings() { /** * Tests that when a node is deleted, the node counter is deleted too. */ - function testDeleteNode() { + public function testDeleteNode() { \Drupal::config('statistics.settings')->set('count_content_views', 1)->save(); - $this->drupalGet('node/' . $this->test_node->id()); + $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. - $nid = $this->test_node->id(); + $nid = $this->testNode->id(); $post = array('nid' => $nid); global $base_url; - $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; + $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array(), $post)->send(); $result = db_select('node_counter', 'n') ->fields('n', array('nid')) - ->condition('n.nid', $this->test_node->id()) + ->condition('n.nid', $this->testNode->id()) ->execute() ->fetchAssoc(); - $this->assertEqual($result['nid'], $this->test_node->id(), 'Verifying that the node counter is incremented.'); + $this->assertEqual($result['nid'], $this->testNode->id(), 'Verifying that the node counter is incremented.'); - $this->test_node->delete(); + $this->testNode->delete(); $result = db_select('node_counter', 'n') ->fields('n', array('nid')) - ->condition('n.nid', $this->test_node->id()) + ->condition('n.nid', $this->testNode->id()) ->execute() ->fetchAssoc(); $this->assertFalse($result, 'Verifying that the node counter is deleted.'); @@ -133,20 +144,20 @@ function testDeleteNode() { /** * Tests that cron clears day counts and expired access logs. */ - function testExpiredLogs() { + public function testExpiredLogs() { \Drupal::config('statistics.settings') ->set('count_content_views', 1) ->save(); \Drupal::state()->set('statistics.day_timestamp', 8640000); - $this->drupalGet('node/' . $this->test_node->id()); + $this->drupalGet('node/' . $this->testNode->id()); // Manually calling statistics.php, simulating ajax behavior. - $nid = $this->test_node->id(); + $nid = $this->testNode->id(); $post = array('nid' => $nid); global $base_url; - $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; + $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $this->client->post($stats_path, array(), $post)->send(); - $this->drupalGet('node/' . $this->test_node->id()); + $this->drupalGet('node/' . $this->testNode->id()); $this->client->post($stats_path, array(), $post)->send(); $this->assertText('1 view', 'Node is viewed once.'); @@ -158,11 +169,11 @@ function testExpiredLogs() { $this->cronRun(); $this->drupalGet('admin/reports/pages'); - $this->assertNoText('node/' . $this->test_node->id(), 'No hit URL found.'); + $this->assertNoText('node/' . $this->testNode->id(), 'No hit URL found.'); $result = db_select('node_counter', 'nc') ->fields('nc', array('daycount')) - ->condition('nid', $this->test_node->id(), '=') + ->condition('nid', $this->testNode->id(), '=') ->execute() ->fetchField(); $this->assertFalse($result, 'Daycounter is zero.'); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php index 6177b86..523a2d6 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsLoggingTest.php @@ -31,23 +31,38 @@ class StatisticsLoggingTest extends WebTestBase { */ protected $client; + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Statistics logging tests', 'description' => 'Tests request logging for cached and uncached pages.', - 'group' => 'Statistics' + 'group' => 'Statistics', ); } - function setUp() { + /** + * {@inheritdoc} + */ + public function setUp() { parent::setUp(); // Create Basic page node type. if ($this->profile != 'standard') { - $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); + $this->drupalCreateContentType( + array( + 'type' => 'page', + 'name' => 'Basic page', + )); } - $this->auth_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content')); + $this->auth_user = $this->drupalCreateUser( + array( + 'access content', + 'create page content', + 'edit own page content', + )); // Ensure we have a node page to access. $this->node = $this->drupalCreateNode(array('title' => $this->randomName(255), 'uid' => $this->auth_user->id())); @@ -67,7 +82,7 @@ function setUp() { /** * Verifies node hit counter logging and script placement. */ - function testLogging() { + public function testLogging() { global $base_url; $path = 'node/' . $this->node->id(); $module_path = drupal_get_path('module', 'statistics'); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php index e1dc9f6..9850c48 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsReportsTest.php @@ -12,18 +12,21 @@ */ class StatisticsReportsTest extends StatisticsTestBase { + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Statistics reports tests', 'description' => 'Tests display of statistics report blocks.', - 'group' => 'Statistics' + 'group' => 'Statistics', ); } /** * Tests the "popular content" block. */ - function testPopularContentBlock() { + public function testPopularContentBlock() { // Clear the block cache to load the Statistics module's block definitions. $this->container->get('plugin.manager.block')->clearCachedDefinitions(); @@ -35,7 +38,7 @@ function testPopularContentBlock() { $post = http_build_query(array('nid' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; - $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; + $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::httpClient(); $client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); $client->post($stats_path, $headers, $post)->send(); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php index 8ad4df2..af61600 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTestBase.php @@ -21,7 +21,10 @@ */ public static $modules = array('node', 'block', 'ban', 'statistics'); - function setUp() { + /** + * {@inheritdoc} + */ + public function setUp() { parent::setUp(); // Create Basic page node type. diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php index 712c5ab..6a2b31f 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php @@ -13,6 +13,10 @@ * Tests statistics token replacement in strings. */ class StatisticsTokenReplaceTest extends StatisticsTestBase { + + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Statistics token replacement', @@ -24,7 +28,7 @@ public static function getInfo() { /** * Creates a node, then tests the statistics tokens generated from it. */ - function testStatisticsTokenReplacement() { + public function testStatisticsTokenReplacement() { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); // Create user and node. @@ -39,7 +43,7 @@ function testStatisticsTokenReplacement() { $post = http_build_query(array('nid' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; - $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php'; + $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::httpClient(); $client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); $client->post($stats_path, $headers, $post)->send(); diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php index 7d3e567..1ef19ad 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php @@ -46,6 +46,9 @@ class IntegrationTest extends ViewTestBase { */ public static $testViews = array('test_statistics_integration'); + /** + * {@inheritdoc} + */ public static function getInfo() { return array( 'name' => 'Statistics: Integration tests', @@ -54,6 +57,9 @@ public static function getInfo() { ); } + /** + * {@inheritdoc} + */ protected function setUp() { parent::setUp(); @@ -81,7 +87,7 @@ public function testNodeCounterIntegration() { // 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'; + $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::httpClient(); $client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10))); $client->post($stats_path, array(), array('nid' => $this->node->id()))->send(); diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php index 85864e1..bef30b7 100644 --- a/core/modules/statistics/statistics.php +++ b/core/modules/statistics/statistics.php @@ -28,4 +28,3 @@ ->execute(); } } - diff --git a/core/modules/statistics/statistics.views.inc b/core/modules/statistics/statistics.views.inc index fe9a9e6..0873784 100644 --- a/core/modules/statistics/statistics.views.inc +++ b/core/modules/statistics/statistics.views.inc @@ -24,7 +24,7 @@ function statistics_views_data() { 'field' => array( 'id' => 'numeric', 'click sortable' => TRUE, - ), + ), 'filter' => array( 'id' => 'numeric', ), @@ -42,7 +42,7 @@ function statistics_views_data() { 'field' => array( 'id' => 'numeric', 'click sortable' => TRUE, - ), + ), 'filter' => array( 'id' => 'numeric', ),