Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
176f8695
Commit
176f8695
authored
15 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#441002
by naxoc: Tests for Statistics module.
parent
3ce9499a
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/statistics/statistics.test
+173
-6
173 additions, 6 deletions
modules/statistics/statistics.test
with
173 additions
and
6 deletions
modules/statistics/statistics.test
+
173
−
6
View file @
176f8695
...
...
@@ -10,10 +10,12 @@ class StatisticsTestCase extends DrupalWebTestCase {
parent
::
setUp
(
'statistics'
);
// Create user.
$this
->
blocking_user
=
$this
->
drupalCreateUser
(
array
(
'block IP addresses'
,
'access statistics'
));
$this
->
blocking_user
=
$this
->
drupalCreateUser
(
array
(
'block IP addresses'
,
'access statistics'
,
'administer blocks'
,
'administer statistics'
,
'administer users'
));
$this
->
drupalLogin
(
$this
->
blocking_user
);
// Enable access logging.
variable_set
(
'statistics_enable_access_log'
,
1
);
variable_set
(
'statistics_count_content_views'
,
1
);
// Insert dummy access by anonymous user into access log.
db_insert
(
'accesslog'
)
...
...
@@ -47,7 +49,6 @@ class StatisticsReportsTestCase extends StatisticsTestCase {
* Verifies that 'Recent hits' renders properly and displays the added hit.
*/
function
testRecentHits
()
{
$this
->
drupalLogin
(
$this
->
blocking_user
);
$this
->
drupalGet
(
'admin/reports/hits'
);
$this
->
assertText
(
'test'
,
t
(
'Hit title found.'
));
$this
->
assertText
(
'node/1'
,
t
(
'Hit URL found.'
));
...
...
@@ -58,7 +59,6 @@ class StatisticsReportsTestCase extends StatisticsTestCase {
* Verifies that 'Top pages' renders properly and displays the added hit.
*/
function
testTopPages
()
{
$this
->
drupalLogin
(
$this
->
blocking_user
);
$this
->
drupalGet
(
'admin/reports/pages'
);
$this
->
assertText
(
'test'
,
t
(
'Hit title found.'
));
$this
->
assertText
(
'node/1'
,
t
(
'Hit URL found.'
));
...
...
@@ -68,7 +68,6 @@ class StatisticsReportsTestCase extends StatisticsTestCase {
* Verifies that 'Top referrers' renders properly and displays the added hit.
*/
function
testTopReferrers
()
{
$this
->
drupalLogin
(
$this
->
blocking_user
);
$this
->
drupalGet
(
'admin/reports/referrers'
);
$this
->
assertText
(
'http://example.com'
,
t
(
'Hit referrer found.'
));
}
...
...
@@ -77,7 +76,6 @@ class StatisticsReportsTestCase extends StatisticsTestCase {
* Verifies that 'Details' page renders properly and displays the added hit.
*/
function
testDetails
()
{
$this
->
drupalLogin
(
$this
->
blocking_user
);
$this
->
drupalGet
(
'admin/reports/access/1'
);
$this
->
assertText
(
'test'
,
t
(
'Hit title found.'
));
$this
->
assertText
(
'node/1'
,
t
(
'Hit URL found.'
));
...
...
@@ -88,12 +86,41 @@ class StatisticsReportsTestCase extends StatisticsTestCase {
* Verifies that access logging is working and is reported correctly.
*/
function
testAccessLogging
()
{
$this
->
drupalLogin
(
$this
->
blocking_user
);
$this
->
drupalGet
(
'admin/reports/referrers'
);
$this
->
drupalGet
(
'admin/reports/hits'
);
$this
->
assertText
(
'Top referrers in the past 3 days'
,
t
(
'Hit title found.'
));
$this
->
assertText
(
'admin/reports/referrers'
,
t
(
'Hit URL found.'
));
}
/**
* Tests the "popular content" block.
*/
function
testPopularContentBlock
()
{
// Visit a node to have something show up in the block.
$node
=
$this
->
drupalCreateNode
(
array
(
'type'
=>
'page'
,
'uid'
=>
$this
->
blocking_user
->
uid
));
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
// Configure and save the block.
$block
=
block_load
(
'statistics'
,
'popular'
);
$block
->
theme
=
'garland'
;
$block
->
status
=
1
;
$block
->
pages
=
''
;
$block
->
region
=
'sidebar_first'
;
$block
->
cache
=
-
1
;
$block
->
visibility
=
0
;
$edit
=
array
(
'statistics_block_top_day_num'
=>
3
,
'statistics_block_top_all_num'
=>
3
,
'statistics_block_top_last_num'
=>
3
);
module_invoke
(
'statistics'
,
'block_save'
,
'popular'
,
$edit
);
drupal_write_record
(
'block'
,
$block
);
// Get some page and check if the block is displayed.
$this
->
drupalGet
(
'user'
);
$this
->
assertText
(
'Popular content'
,
t
(
'Found the popular content block.'
));
$this
->
assertText
(
"Today's"
,
t
(
'Found today\'s popular content.'
));
$this
->
assertText
(
'All time'
,
t
(
'Found the alll time popular content.'
));
$this
->
assertText
(
'Last viewed'
,
t
(
'Found the last viewed popular content.'
));
$this
->
assertRaw
(
l
(
$node
->
title
[
LANGUAGE_NONE
][
0
][
'value'
],
'node/'
.
$node
->
nid
),
t
(
'Found link to visited node.'
));
}
}
/**
...
...
@@ -145,3 +172,143 @@ class StatisticsBlockVisitorsTestCase extends StatisticsTestCase {
$this
->
assertRaw
(
t
(
'The IP address %ip was deleted.'
,
array
(
'%ip'
=>
$test_ip_address
)),
t
(
'IP address deleted.'
));
}
}
/**
* Test statistics administration screen.
*/
class
StatisticsAdminTestCase
extends
DrupalWebTestCase
{
protected
$privileged_user
;
protected
$test_node
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Test statistics admin.'
,
'description'
=>
'Tests the statistics admin.'
,
'group'
=>
'Statistics'
);
}
function
setUp
()
{
parent
::
setUp
(
'statistics'
);
$this
->
privileged_user
=
$this
->
drupalCreateUser
(
array
(
'access statistics'
,
'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
->
uid
));
}
/**
* Verifies that the statistics settings page works.
*/
function
testStatisticsSettings
()
{
$this
->
assertFalse
(
variable_get
(
'statistics_enable_access_log'
,
0
),
t
(
'Access log is disabled by default.'
));
$this
->
assertFalse
(
variable_get
(
'statistics_count_content_views'
,
0
),
t
(
'Count content view log is disabled by default.'
));
$this
->
drupalGet
(
'admin/reports/pages'
);
$this
->
assertRaw
(
t
(
'No statistics available.'
),
t
(
'Verifying text shown when no statistics is available.'
));
// Enable access log and counter on content view.
$edit
[
'statistics_enable_access_log'
]
=
1
;
$edit
[
'statistics_count_content_views'
]
=
1
;
$this
->
drupalPost
(
'admin/config/system/statistics'
,
$edit
,
t
(
'Save configuration'
));
$this
->
assertTrue
(
variable_get
(
'statistics_enable_access_log'
),
t
(
'Access log is enabled.'
));
$this
->
assertTrue
(
variable_get
(
'statistics_count_content_views'
),
t
(
'Count content view log is enabled.'
));
// Hit the node.
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$this
->
drupalGet
(
'admin/reports/pages'
);
$this
->
assertText
(
'node/1'
,
t
(
'Test node found.'
));
// Hit the node again (the counter is incremented after the hit, so
// "1 read" will actually be shown when the node is hit the second time).
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$this
->
assertText
(
'1 read'
,
t
(
'Node is read once.'
));
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$this
->
assertText
(
'2 reads'
,
t
(
'Node is read 2 times.'
));
}
/**
* Tests that when a node is deleted, the node counter is deleted too.
*/
function
testDeleteNode
()
{
variable_set
(
'statistics_count_content_views'
,
1
);
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$result
=
db_select
(
'node_counter'
,
'n'
)
->
fields
(
'n'
,
array
(
'nid'
))
->
condition
(
'n.nid'
,
$this
->
test_node
->
nid
)
->
execute
()
->
fetchAssoc
();
$this
->
assertEqual
(
$result
[
'nid'
],
$this
->
test_node
->
nid
,
'Verifying that the node counter is incremented.'
);
node_delete
(
$this
->
test_node
->
nid
);
$result
=
db_select
(
'node_counter'
,
'n'
)
->
fields
(
'n'
,
array
(
'nid'
))
->
condition
(
'n.nid'
,
$this
->
test_node
->
nid
)
->
execute
()
->
fetchAssoc
();
$this
->
assertFalse
(
$result
,
'Verifying that the node counter is deleted.'
);
}
/**
* Tests that accesslog reflects when a user is deleted.
*/
function
testDeleteUser
()
{
variable_set
(
'statistics_enable_access_log'
,
1
);
variable_set
(
'user_cancel_method'
,
'user_cancel_delete'
);
$this
->
drupalLogout
(
$this
->
privileged_user
);
$account
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
'cancel account'
));
$this
->
drupalLogin
(
$account
);
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$account
=
user_load
(
$account
->
uid
,
TRUE
);
$this
->
drupalGet
(
'user/'
.
$account
->
uid
.
'/edit'
);
$this
->
drupalPost
(
NULL
,
NULL
,
t
(
'Cancel account'
));
$timestamp
=
time
();
$this
->
drupalPost
(
NULL
,
NULL
,
t
(
'Cancel account'
));
// Confirm account cancellation request.
$this
->
drupalGet
(
"user/
$account->uid
/cancel/confirm/
$timestamp
/"
.
user_pass_rehash
(
$account
->
pass
,
$timestamp
,
$account
->
login
));
$this
->
assertFalse
(
user_load
(
$account
->
uid
,
TRUE
),
t
(
'User is not found in the database.'
));
$this
->
drupalGet
(
'admin/reports/visitors'
);
$this
->
assertNoText
(
$account
->
name
,
t
(
'Did not find user in visitor statistics.'
));
}
/**
* Tests that cron clears day counts and expired access logs.
*/
function
testExpiredLogs
()
{
variable_set
(
'statistics_enable_access_log'
,
1
);
variable_set
(
'statistics_count_content_views'
,
1
);
variable_set
(
'statistics_day_timestamp'
,
8640000
);
variable_set
(
'statistics_flush_accesslog_timer'
,
1
);
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$this
->
drupalGet
(
'node/'
.
$this
->
test_node
->
nid
);
$this
->
assertText
(
'1 read'
,
t
(
'Node is read once.'
));
$this
->
drupalGet
(
'admin/reports/pages'
);
$this
->
assertText
(
'node/'
.
$this
->
test_node
->
nid
,
t
(
'Hit URL found.'
));
// statistics_cron will subtract the statistics_flush_accesslog_timer
// variable from REQUEST_TIME in the delete query, so wait two secs here to
// make sure the access log will be flushed for the node just hit.
sleep
(
2
);
$this
->
cronRun
();
$this
->
drupalGet
(
'admin/reports/pages'
);
$this
->
assertNoText
(
'node/'
.
$this
->
test_node
->
nid
,
t
(
'No hit URL found.'
));
$result
=
db_select
(
'node_counter'
,
'nc'
)
->
fields
(
'nc'
,
array
(
'daycount'
))
->
condition
(
'nid'
,
$this
->
test_node
->
nid
,
'='
)
->
execute
()
->
fetchField
();
$this
->
assertFalse
(
$result
,
t
(
'Daycounter is zero.'
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment