Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
494b908c
Commit
494b908c
authored
Jul 01, 2012
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Committing missing test file.
parent
6895cc3c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php
...les/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php
+80
-0
No files found.
core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php
0 → 100644
View file @
494b908c
<?php
/**
* @file
* Definition of Drupal\node\Tests\NodeAccessLanguageTest.
*/
namespace
Drupal\node\Tests
;
/**
* Test case to verify node_access functionality for multiple languages.
*/
class
NodeAccessLanguageTest
extends
NodeTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Node access language'
,
'description'
=>
'Test node_access functionality with multiple languages.'
,
'group'
=>
'Node'
,
);
}
/**
* Asserts node_access correctly grants or denies access.
*/
function
assertNodeAccess
(
$ops
,
$node
,
$account
,
$langcode
=
NULL
)
{
foreach
(
$ops
as
$op
=>
$result
)
{
$msg
=
t
(
"node_access returns @result with operation '@op', language code @langcode."
,
array
(
'@result'
=>
$result
?
'true'
:
'false'
,
'@op'
=>
$op
,
'@langcode'
=>
!
empty
(
$langcode
)
?
"'
$langcode
'"
:
'empty'
));
$this
->
assertEqual
(
$result
,
node_access
(
$op
,
$node
,
$account
,
$langcode
),
$msg
);
}
}
function
setUp
()
{
parent
::
setUp
(
array
(
'language'
,
'node_access_test'
));
// Clear permissions for authenticated users.
db_delete
(
'role_permission'
)
->
condition
(
'rid'
,
DRUPAL_AUTHENTICATED_RID
)
->
execute
();
}
/**
* Runs tests for node_access function with multiple languages.
*/
function
testNodeAccess
()
{
// Add Hungarian and Catalan.
$language
=
(
object
)
array
(
'langcode'
=>
'hu'
,
);
language_save
(
$language
);
$language
=
(
object
)
array
(
'langcode'
=>
'ca'
,
);
language_save
(
$language
);
// Tests the default access provided for a published Hungarian node.
$web_user
=
$this
->
drupalCreateUser
(
array
(
'access content'
));
$node
=
$this
->
drupalCreateNode
(
array
(
'body'
=>
array
(
'hu'
=>
array
(
array
())),
'langcode'
=>
'hu'
));
$this
->
assertTrue
(
$node
->
langcode
==
'hu'
,
t
(
'Node created as Hungarian.'
));
$expected_node_access
=
array
(
'view'
=>
TRUE
,
'update'
=>
FALSE
,
'delete'
=>
FALSE
);
$this
->
assertNodeAccess
(
$expected_node_access
,
$node
,
$web_user
);
// Tests that Hungarian provided specifically results in the same.
$this
->
assertNodeAccess
(
$expected_node_access
,
$node
,
$web_user
,
'hu'
);
// There is no specific Catalan version of this node and Croatian is not
// even set up on the system in this scenario, so these languages will not
// play a role in the node's permissions.
$this
->
assertNodeAccess
(
$expected_node_access
,
$node
,
$web_user
,
'ca'
);
$this
->
assertNodeAccess
(
$expected_node_access
,
$node
,
$web_user
,
'hr'
);
// Reset the node access cache and turn on our test node_access() code.
drupal_static_reset
(
'node_access'
);
variable_set
(
'node_access_test_secret_catalan'
,
1
);
// Tests that Hungarian is still accessible.
$this
->
assertNodeAccess
(
$expected_node_access
,
$node
,
$web_user
,
'hu'
);
// Tests that Catalan is not accessible anymore.
$this
->
assertNodeAccess
(
array
(
'view'
=>
FALSE
,
'update'
=>
FALSE
,
'delete'
=>
FALSE
),
$node
,
$web_user
,
'ca'
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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