Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
c50651f7
Commit
c50651f7
authored
Dec 09, 2008
by
Dries Buytaert
Browse files
- Patch
#340557
by Dave Reid: use static caching in drupal_is_front_page().
parent
1ffa4fe3
Changes
3
Hide whitespace changes
Inline
Side-by-side
includes/path.inc
View file @
c50651f7
...
...
@@ -212,6 +212,7 @@ function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {
if
(
isset
(
$title
))
{
$stored_title
=
(
$output
==
PASS_THROUGH
)
?
$title
:
check_plain
(
$title
);
}
return
$stored_title
;
}
...
...
@@ -222,9 +223,15 @@ function drupal_set_title($title = NULL, $output = CHECK_PLAIN) {
* Boolean value: TRUE if the current page is the front page; FALSE if otherwise.
*/
function
drupal_is_front_page
()
{
// As drupal_init_path updates $_GET['q'] with the 'site_frontpage' path,
// we can check it against the 'site_frontpage' variable.
return
$_GET
[
'q'
]
==
drupal_get_normal_path
(
variable_get
(
'site_frontpage'
,
'node'
));
static
$is_front_page
;
if
(
!
isset
(
$is_front_page
))
{
// As drupal_init_path updates $_GET['q'] with the 'site_frontpage' path,
// we can check it against the 'site_frontpage' variable.
$is_front_page
=
(
$_GET
[
'q'
]
==
drupal_get_normal_path
(
variable_get
(
'site_frontpage'
,
'node'
)));
}
return
$is_front_page
;
}
/**
...
...
modules/simpletest/tests/system_test.module
View file @
c50651f7
...
...
@@ -149,6 +149,16 @@ function system_test_boot() {
watchdog
(
'system_test'
,
'hook_boot'
);
}
/**
* Implementation of hook_init().
*/
function
system_test_init
()
{
// Used by FrontPageTestCase to get the results of drupal_is_front_page().
if
(
variable_get
(
'front_page_output'
,
0
)
&&
drupal_is_front_page
())
{
drupal_set_message
(
t
(
'On front page.'
));
}
}
/**
* Implementation of hook_exit().
*/
...
...
modules/system/system.test
View file @
c50651f7
...
...
@@ -576,3 +576,58 @@ class PageTitleFiltering extends DrupalWebTestCase {
$this
->
assertText
(
check_plain
(
$edit
[
'title'
]),
'Check to make sure tags in the node title are converted.'
);
}
}
/**
* Test front page functionality and administration.
*/
class
FrontPageTestCase
extends
DrupalWebTestCase
{
function
getInfo
()
{
return
array
(
'name'
=>
t
(
'Front page'
),
'description'
=>
t
(
'Tests front page functionality and administration.'
),
'group'
=>
t
(
'System'
),
);
}
function
setUp
()
{
parent
::
setUp
(
'system_test'
);
// Create admin user, log in admin user, and create one node.
$this
->
admin_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
'administer site configuration'
));
$this
->
drupalLogin
(
$this
->
admin_user
);
$this
->
node_path
=
"node/"
.
$this
->
drupalCreateNode
(
array
(
'promote'
=>
1
))
->
nid
;
// Enable front page logging in system_test.module.
variable_set
(
'front_page_output'
,
1
);
}
/**
* Test front page functionality.
*/
function
testDrupalIsFrontPage
()
{
$this
->
drupalGet
(
''
);
$this
->
assertText
(
t
(
'On front page.'
),
t
(
'Path is the front page.'
));
$this
->
drupalGet
(
'node'
);
$this
->
assertText
(
t
(
'On front page.'
),
t
(
'Path is the front page.'
));
$this
->
drupalGet
(
$this
->
node_path
);
$this
->
assertNoText
(
t
(
'On front page.'
),
t
(
'Path is not the front page.'
));
// Change the front page to an invalid path.
$edit
=
array
(
'site_frontpage'
=>
'kittens'
);
$this
->
drupalPost
(
'admin/settings/site-information'
,
$edit
,
t
(
'Save configuration'
));
$this
->
assertText
(
t
(
"The path '@path' is either invalid or you do not have access to it."
,
array
(
'@path'
=>
$edit
[
'site_frontpage'
])));
// Change the front page to a valid path.
$edit
[
'site_frontpage'
]
=
$this
->
node_path
;
$this
->
drupalPost
(
'admin/settings/site-information'
,
$edit
,
t
(
'Save configuration'
));
$this
->
assertText
(
t
(
'The configuration options have been saved.'
),
t
(
'The front page path has been saved.'
));
$this
->
drupalGet
(
''
);
$this
->
assertText
(
t
(
'On front page.'
),
t
(
'Path is the front page.'
));
$this
->
drupalGet
(
'node'
);
$this
->
assertNoText
(
t
(
'On front page.'
),
t
(
'Path is not the front page.'
));
$this
->
drupalGet
(
$this
->
node_path
);
$this
->
assertText
(
t
(
'On front page.'
),
t
(
'Path is the front page.'
));
}
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment