You are here

public function FusionApplyDisplayTestCase::testFusionApplyRulesLoadSave in Fusion Accelerator 7

Same name and namespace in other branches
  1. 7.2 fusion_apply/tests/fusion_apply.test \FusionApplyDisplayTestCase::testFusionApplyRulesLoadSave()

Tests loading and saving of rules.

File

fusion_apply/tests/fusion_apply.test, line 553
Tests for the Fusion Apply module.

Class

FusionApplyDisplayTestCase
Tests API functionality.

Code

public function testFusionApplyRulesLoadSave() {

  // Test saving a rule.
  $rule = (object) array(
    'title' => 'Rule 1',
    'rule_type' => 'page',
    'node_types' => array(),
    'roles' => array(),
    'visibility' => 0,
    // Show on all pages, except those listed.
    'pages' => '',
  );
  $this
    ->assertTrue(fusion_apply_rule_save($rule), 'Rule object was saved when no filtering is applied.');
  $rule->title = '';
  $this
    ->assertFalse($status = fusion_apply_rule_save($rule), 'Rule object was not saved when the required $rule->title field was empty.');
  $this
    ->pass('Status: ' . ($status ? 'true' : 'false'));
  $rule->title = 'Rule 1';
  $rule->rule_type = '';
  $this
    ->assertFalse(fusion_apply_rule_save($rule), 'Rule object was not saved when the required $rule->rule_type field was empty.');
  $rule->rule_type = 'page';
  $rule->node_types = FALSE;
  $this
    ->assertFalse(fusion_apply_rule_save($rule), 'Rule object was not saved when $rule->node_types was not an array.');
  $rule->node_types = array();
  $rule->roles = FALSE;
  $this
    ->assertFalse(fusion_apply_rule_save($rule), 'Rule object was not saved when $rule->roles was not an array.');
  $rule->roles = array();

  // Test loading a rule.
  $loaded_rule = fusion_apply_rule_load($rule->rid);
  $this
    ->assertTrue(is_array($loaded_rule->node_types), 'Node types for the rule object were unserialized.');
  $this
    ->assertTrue(is_array($loaded_rule->roles), 'Roles for the rule object were unserialized.');
  $this
    ->assertTrue($loaded_rule->title == $rule->title && $loaded_rule->rule_type == $rule->rule_type && $loaded_rule->node_types == $rule->node_types && $loaded_rule->roles == $rule->roles && $loaded_rule->visibility == $rule->visibility && $loaded_rule->pages == $rule->pages, 'Rule object was loaded properly.');

  // Save a second rule.
  $second_rule = (object) array(
    'title' => 'Rule 2',
    'rule_type' => 'page',
    'node_types' => array(),
    'roles' => array(),
    'visibility' => 0,
    // Show on all pages, except those listed.
    'pages' => '',
  );
  fusion_apply_rule_save($second_rule);

  // Test loading multiple skin configurations.
  $rules = fusion_apply_rule_load_multiple(array(
    $rule->rid,
    $second_rule->rid,
  ));
  $this
    ->assertTrue(count($rules) == 2 && isset($rules[$rule->rid]->rid) && isset($rules[$second_rule->rid]->rid), 'Successfully loaded multiple rules.');

  // Test loading all skin configurations.
  $rules = fusion_apply_rule_load_multiple();
  $this
    ->assertTrue(count($rules) == 2 && isset($rules[$rule->rid]->rid) && isset($rules[$second_rule->rid]->rid), 'Successfully loaded all rules.');
}