public function FusionApplyRulesApiTestCase::testFusionApplyRulesVisibility in Fusion Accelerator 7.2
Same name and namespace in other branches
- 7 fusion_apply/tests/fusion_apply.test \FusionApplyRulesApiTestCase::testFusionApplyRulesVisibility()
Tests visibility of rules.
File
- fusion_apply/
tests/ fusion_apply.test, line 643 - Tests for the Fusion Apply module.
Class
- FusionApplyRulesApiTestCase
- Tests API functionality.
Code
public function testFusionApplyRulesVisibility() {
$front = variable_get('site_frontpage', 'node');
$article = $this->nodes['article'];
$page = $this->nodes['page'];
$rule = (object) array(
'title' => 'Rule 1',
'rule_type' => 'page',
'node_types' => array(),
'roles' => array(),
'visibility' => 0,
// Show on all pages, except those listed.
'pages' => '',
);
fusion_apply_rule_save($rule);
// Test visibility when no filters are applied.
$this
->drupalGet('');
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid), 'The rule is visible on the front page.');
$this
->drupalGet('node/' . $article->nid);
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid), 'The rule is visible for an article node.');
$this
->drupalGet('node/' . $page->nid);
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid), 'The rule is visible for a basic page node.');
// Test visibility with a node type filter.
$rule->node_types = array(
'article' => 'article',
);
fusion_apply_rule_save($rule);
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, $front), "The rule is not visible on the front page when it has the node type filter set to 'article'.");
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid, 'node/' . $article->nid), "The rule is visible for an article node when it has the node type filter set to 'article'.");
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, 'node/' . $page->nid), "The rule is not visible for a basic page node when it has the node type filter set to 'article'.");
// @todo Need to test with node/add/* path.
// Problem to solve: node_type_get_types() always returns an empty array when running tests.
// Test visibility with a roles filter.
$rule->node_types = array();
$rule->roles = array(
2 => '2',
);
fusion_apply_rule_save($rule);
// @todo Is there a way to test role API functionality without temporarily
// changing global user?
global $user;
$current_user = $user;
$user = $this->users['normal_user'];
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid, $front), "The rule is visible for a logged-in user when it has a role filter set to 'authenticated user'.");
$user = drupal_anonymous_user();
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, $front), "The rule is not visible for an anonymous user when it has a role filter set to 'authenticated user'.");
$user = $current_user;
// Test visibility with an exclude page filter.
$rule->roles = array();
$rule->pages = "<front>";
fusion_apply_rule_save($rule);
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, $front), "The rule is not visible on the front page when it has the page filter set to exclude '<front>'.");
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid, 'node/' . $article->nid), "The rule is visible for an article node when it has the page filter set to exclude '<front>'.");
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid, 'node/' . $page->nid), "The rule is visible for a basic page node when it has the page filter set to exclude '<front>'.");
// Test visibility with an include page filter.
$rule->visibility = 1;
fusion_apply_rule_save($rule);
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid, $front), "The rule is visible on the front page when it has the page filter set to include '<front>'.");
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, 'node/' . $article->nid), "The rule is not visible for an article node when it has the page filter set to include '<front>'.");
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, 'node/' . $page->nid), "The rule is not visible for a basic page node when it has the page filter set to include '<front>'.");
// Test visibility with a php page filter.
$rule->visibility = 2;
$rule->pages = "<?php\nreturn FALSE;\n?>";
fusion_apply_rule_save($rule);
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, $front), "The rule is not visible on the front page when it has the page filter set to php with code always returning FALSE.");
$this
->assertFalse(fusion_apply_rule_is_visible($rule->rid, 'node/' . $article->nid), "The rule is not visible for an article node when it has the page filter set to php with code always returning FALSE.");
$rule->pages = "<?php\nreturn TRUE;\n?>";
fusion_apply_rule_save($rule);
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid), "The rule is visible on the front page when it has the page filter set to php with code always returning TRUE.");
$this
->assertTrue(fusion_apply_rule_is_visible($rule->rid, 'node/' . $article->nid), "The rule is visible for an article node when it has the page filter set to php with code always returning TRUE.");
}