Commit 2775f311 authored by alexpott's avatar alexpott

Issue #2387981 by hussainweb: Clean-up statistics module test members - ensure...

Issue #2387981 by hussainweb: Clean-up statistics module test members - ensure property definition and use of camelCase naming convention
parent 07149c42
......@@ -26,18 +26,16 @@ class StatisticsAdminTest extends WebTestBase {
/**
* A user that has permission to administer statistics.
*
* @var object|FALSE
*
* A fully loaded user object, or FALSE if user creation failed.
* @var \Drupal\user\UserInterface
*/
protected $privileged_user;
protected $privilegedUser;
/**
* A page node for which to check content statistics.
*
* @var object
* @var \Drupal\node\NodeInterface
*/
protected $test_node;
protected $testNode;
/**
* The Guzzle HTTP client.
......@@ -53,9 +51,9 @@ protected function setUp() {
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->setDefaultOption('config/curl', array(CURLOPT_TIMEOUT => 10));
}
......@@ -74,9 +72,9 @@ 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';
......@@ -84,11 +82,11 @@ function testStatisticsSettings() {
// 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('body' => $post));
$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('body' => $post));
$this->assertText('2 views', 'Node is viewed 2 times.');
}
......@@ -99,9 +97,9 @@ function testStatisticsSettings() {
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';
......@@ -109,16 +107,16 @@ function testDeleteNode() {
$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,14 +131,14 @@ function testExpiredLogs() {
->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';
$this->client->post($stats_path, array('body' => $post));
$this->drupalGet('node/' . $this->test_node->id());
$this->drupalGet('node/' . $this->testNode->id());
$this->client->post($stats_path, array('body' => $post));
$this->assertText('1 view', 'Node is viewed once.');
......@@ -152,11 +150,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.');
......
......@@ -26,6 +26,13 @@ class StatisticsLoggingTest extends WebTestBase {
*/
public static $modules = array('node', 'statistics', 'block');
/**
* User with permissions to create and edit pages.
*
* @var \Drupal\user\UserInterface
*/
protected $authUser;
/**
* The Guzzle HTTP client.
*
......@@ -41,10 +48,10 @@ protected function setUp() {
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
}
$this->auth_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content'));
$this->authUser = $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->randomMachineName(255), 'uid' => $this->auth_user->id()));
$this->node = $this->drupalCreateNode(array('title' => $this->randomMachineName(255), 'uid' => $this->authUser->id()));
// Enable access logging.
\Drupal::config('statistics.settings')
......
......@@ -22,7 +22,7 @@ function testPopularContentBlock() {
$this->container->get('plugin.manager.block')->clearCachedDefinitions();
// Visit a node to have something show up in the block.
$node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blocking_user->id()));
$node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blockingUser->id()));
$this->drupalGet('node/' . $node->id());
// Manually calling statistics.php, simulating ajax behavior.
$nid = $node->id();
......
......@@ -21,6 +21,13 @@ abstract class StatisticsTestBase extends WebTestBase {
*/
public static $modules = array('node', 'block', 'ban', 'statistics');
/**
* User with permissions to ban IP's.
*
* @var \Drupal\user\UserInterface
*/
protected $blockingUser;
protected function setUp() {
parent::setUp();
......@@ -30,7 +37,7 @@ protected function setUp() {
}
// Create user.
$this->blocking_user = $this->drupalCreateUser(array(
$this->blockingUser = $this->drupalCreateUser(array(
'access administration pages',
'access site reports',
'ban IP addresses',
......@@ -38,7 +45,7 @@ protected function setUp() {
'administer statistics',
'administer users',
));
$this->drupalLogin($this->blocking_user);
$this->drupalLogin($this->blockingUser);
// Enable logging.
\Drupal::config('statistics.settings')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment