diff -u b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/AccessLogPathTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/AccessLogPathTest.php --- b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/AccessLogPathTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/AccessLogPathTest.php @@ -7,27 +7,19 @@ namespace Drupal\statistics\Tests\Views; -use Drupal\views\Tests\ViewTestBase; -use Drupal\views\Tests\ViewTestData; - /** * Tests the AccessLogPath handler. + * + * @see \Drupal\statistics\Plugin\views\field\AccesslogPath */ -class AccessLogPathTest extends ViewTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('statistics', 'statistics_test_views'); +class AccessLogPathTest extends StatisticsTestBase { /** * Views used by this test. * * @var array */ - public static $testViews = array('test_statistics_integration', 'test_statistics_accesslog_integration'); + public static $testViews = array('test_statistics_accesslog_integration'); public static function getInfo() { return array( @@ -37,27 +29,8 @@ ); } - protected function setUp() { - parent::setUp(); - - ViewTestData::importTestViews(get_class($this), array('statistics_test_views')); - - // Create a new user for viewing nodes. - $this->webUser = $this->drupalCreateUser(array('access content')); - - $this->node = $this->drupalCreateNode(array('type' => 'page')); - - // Enable access logging. - config('statistics.settings') - ->set('access_log.enabled', 1) - ->set('count_content_views', 1) - ->save(); - - $this->drupalLogin($this->webUser); - } - /** - * Tests the AcessLogPath field handler. + * Tests the AccessLogPath field handler. */ public function testHandler() { $view = views_get_view('test_statistics_accesslog_integration'); diff -u b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php --- b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/IntegrationTest.php @@ -8,20 +8,11 @@ namespace Drupal\statistics\Tests\Views; use PDO; -use Drupal\views\Tests\ViewTestBase; -use Drupal\views\Tests\ViewTestData; /** - * Tests basic integeration of views data from the statistics module. + * Tests basic integration of views data from the statistics module. */ -class IntegrationTest extends ViewTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('statistics', 'statistics_test_views'); +class IntegrationTest extends StatisticsTestBase { /** * Views used by this test. @@ -40,32 +31,13 @@ public static function getInfo() { return array( 'name' => 'Statistics: Integration tests', - 'description' => 'Tests basic integeration of views data from the statistics module.', + 'description' => 'Tests basic integration of views data from the statistics module.', 'group' => 'Views Modules', ); } - protected function setUp() { - parent::setUp(); - - ViewTestData::importTestViews(get_class($this), array('statistics_test_views')); - - // Create a new user for viewing nodes. - $this->webUser = $this->drupalCreateUser(array('access content')); - - $this->node = $this->drupalCreateNode(array('type' => 'page')); - - // Enable access logging. - config('statistics.settings') - ->set('access_log.enabled', 1) - ->set('count_content_views', 1) - ->save(); - - $this->drupalLogin($this->webUser); - } - /** - * Tests the integration of node_counter views data. + * Tests the integration of the {node_counter} table in views. */ public function testNodeCounterIntegration() { $this->drupalGet('node/' . $this->node->id()); @@ -91,7 +63,7 @@ } /** - * [textAccessLogIntegration description] + * Tests the integration of the {accesslog} table in views. */ public function testAccessLogIntegration() { // Get the expected before requesting the page. @@ -100,7 +72,7 @@ $this->drupalGet('test_statistics_accesslog_integration'); // Test we have all the results results. - $elements = $this->xpath("//div[@class = 'view-content']/div[contains(@class, views-row)]"); + $elements = $this->xpath("//div[@class='view-content']/div[contains(@class, views-row)]"); $this->assertEqual(count($elements), count($results)); $expected = reset($results); @@ -111,8 +83,8 @@ // Test the first row values. foreach ($expected as $field => $value) { - $xpath = "//div[@class = 'view-content']/div[contains(@class, views-row-1)]/div[contains(@class, views-field-$field)]/span[@class = 'field-content']"; - $this->assertFieldByXpath($xpath ,$value, "Value $value is correct for $field field."); + $xpath = "//div[@class='view-content']/div[contains(@class, views-row-1)]/div[contains(@class, views-field-$field)]/span[@class = 'field-content']"; + $this->assertFieldByXpath($xpath ,$value, format_string("Value @value is correct for @field field.", array('@value' => $value, '@field' => $field))); } } diff -u b/core/modules/statistics/statistics.views.inc b/core/modules/statistics/statistics.views.inc --- b/core/modules/statistics/statistics.views.inc +++ b/core/modules/statistics/statistics.views.inc @@ -11,25 +11,18 @@ * Implements hook_views_data(). */ function statistics_views_data() { - // Basic table information. - - // node_counter table - $data['node_counter']['table']['group'] = t('Content statistics'); $data['node_counter']['table']['join'] = array( - // ...to the node table 'node' => array( 'left_field' => 'nid', 'field' => 'nid', ), ); - // totalcount $data['node_counter']['totalcount'] = array( 'title' => t('Total views'), 'help' => t('The total number of times the node has been viewed.'), - 'field' => array( 'id' => 'numeric', 'click sortable' => TRUE, @@ -37,16 +30,17 @@ 'filter' => array( 'id' => 'numeric', ), + 'argument' => array( + 'id' => 'numeric', + ), 'sort' => array( 'id' => 'standard', ), ); - // daycount $data['node_counter']['daycount'] = array( 'title' => t('Views today'), 'help' => t('The total number of times the node has been viewed today.'), - 'field' => array( 'id' => 'numeric', 'click sortable' => TRUE, @@ -54,16 +48,17 @@ 'filter' => array( 'id' => 'numeric', ), + 'argument' => array( + 'id' => 'numeric', + ), 'sort' => array( 'id' => 'standard', ), ); - // timestamp $data['node_counter']['timestamp'] = array( 'title' => t('Most recent view'), 'help' => t('The most recent time the node has been viewed.'), - 'field' => array( 'id' => 'date', 'click sortable' => TRUE, @@ -71,16 +66,16 @@ 'filter' => array( 'id' => 'date', ), + 'argument' => array( + 'id' => 'date', + ), 'sort' => array( 'id' => 'standard', ), ); - // accesslog table - $data['accesslog']['table']['group'] = t('Access log'); - // Advertise this table as a possible base table $data['accesslog']['table']['base'] = array( 'field' => 'aid', 'title' => t('Access log'), @@ -88,7 +83,6 @@ 'weight' => 10, ); - // For other base tables, explain how we join $data['accesslog']['table']['join'] = array( 'users' => array( 'field' => 'uid', @@ -96,7 +90,6 @@ ), ); - // accesslog.aid $data['accesslog']['aid'] = array( 'title' => t('Aid'), 'help' => t('Unique access event ID.'), @@ -117,7 +110,6 @@ ), ); - // session id $data['accesslog']['sid'] = array( 'title' => t('Session ID'), 'help' => t('Browser session ID of user that visited page.'), @@ -137,11 +129,9 @@ ), ); - // title $data['accesslog']['title'] = array( 'title' => t('Page title'), 'help' => t('Title of page visited.'), - 'field' => array( 'id' => 'accesslog_path', 'click sortable' => TRUE, @@ -157,11 +147,9 @@ ), ); - // path $data['accesslog']['path'] = array( 'title' => t('Path'), 'help' => t('Internal path to page visited (relative to Drupal root.)'), - 'field' => array( 'id' => 'accesslog_path', 'click sortable' => TRUE, @@ -172,12 +160,10 @@ 'sort' => array( 'id' => 'standard', ), - //No argument here. Can't send forward slashes as arguments. - //Can be worked around by node ID. - //(but what about aliases?) + //@todo No argument here. Can't send forward slashes as arguments. + // Can be worked around by node ID (but what about aliases?). ); - // referrer $data['accesslog']['url'] = array( 'title' => t('Referrer'), 'help' => t('Referrer URI.'), @@ -193,7 +179,6 @@ ), ); - // hostname $data['accesslog']['hostname'] = array( 'title' => t('Hostname'), 'help' => t('Hostname of user that visited the page.'), @@ -212,18 +197,26 @@ ), ); - // user $data['accesslog']['uid'] = array( - 'title' => t('User'), + 'title' => t('UID'), 'help' => t('The user who visited the site.'), 'relationship' => array( + 'title' => t('User'), 'id' => 'standard', 'base' => 'users', 'base field' => 'uid', ), + 'filter' => array( + 'id' => 'user_name', + ), + 'argument' => array( + 'id' => 'numeric', + ), + 'field' => array( + 'id' => 'user', + ), ); - // timer $data['accesslog']['timer'] = array( 'title' => t('Timer'), 'help' => t('Time in milliseconds that the page took to load.'), @@ -239,7 +232,6 @@ ), ); - // timestamp $data['accesslog']['timestamp'] = array( 'title' => t('Timestamp'), 'help' => t('Timestamp of when the page was visited.'), @@ -253,6 +245,9 @@ 'filter' => array( 'id' => 'date', ), + 'argument' => array( + 'id' => 'date', + ), ); return $data; only in patch2: unchanged: --- /dev/null +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/Views/StatisticsTestBase.php @@ -0,0 +1,57 @@ +webUser = $this->drupalCreateUser(array('access content')); + + $this->node = $this->drupalCreateNode(array('type' => 'page')); + + // Enable access logging. + config('statistics.settings') + ->set('access_log.enabled', 1) + ->set('count_content_views', 1) + ->save(); + + $this->drupalLogin($this->webUser); + } +}