You are here

class RulesConditionalUITestCase in Conditional Rules 8

Same name and namespace in other branches
  1. 7 tests/rules_conditional.test \RulesConditionalUITestCase

UI tests.

Hierarchy

Expanded class hierarchy of RulesConditionalUITestCase

File

tests/rules_conditional.test, line 655
SimpleTest testing suites.

View source
class RulesConditionalUITestCase extends RulesConditionalBaseTestCase {

  /**
   * Returns test info.
   */
  public static function getInfo() {
    return array(
      'name' => 'User interface',
      'description' => 'Test the user interface implementations for conditional plugins.',
      'group' => 'Conditional Rules',
    );
  }

  /**
   * Sets up test case.
   */
  protected function setUp() {
    parent::setUp('rules_conditional_test', 'rules_admin');
    $user = $this
      ->drupalCreateUser(array(
      'administer rules',
    ));
    $this
      ->drupalLogin($user);
  }

  /**
   * Tests RulesConditionalPluginUI.
   */
  public function testBaseUI() {

    // Create component.
    $componentName = 'base_test';
    $comp = rules_action_set(array())
      ->action($container = new RulesConditionalTestStubContainer());
    $comp->component = TRUE;
    $comp
      ->integrityCheck()
      ->save($componentName);
    $componentPath = 'admin/config/workflow/rules/components';
    RulesPluginUI::$basePath = $componentPath;
    $managePath = RulesPluginUI::path($componentName);
    $addSinglePath = RulesPluginUI::path($componentName, 'add', $container, 'stub conditional single element');
    $addDependentPath = RulesPluginUI::path($componentName, 'add', $container, 'stub conditional dependent element');

    // Test 'conditional depends'.
    $this
      ->drupalGet($managePath);

    // Check dependent element cannot be added.
    $this
      ->assertNoLinkByHref(url($addDependentPath), 'Dependent plugin is unavailable to add.');

    // Add element and then check for link to add dependent element.
    $element = new RulesConditionalTestStubElement();
    $element
      ->setParent($container);
    $comp
      ->save();
    $this
      ->drupalGet($managePath);
    $this
      ->assertLinkByHref(url($addDependentPath), 0, 'Dependent plugin can be added on fulfilling prerequisite.');

    // Test 'conditional single'.
    $element = new RulesConditionalTestStubSingleElement();
    $element
      ->setParent($container);
    $comp
      ->save();
    $this
      ->drupalGet($managePath);
    $this
      ->assertNoLinkByHref(url($addSinglePath), 'Single plugins cannot be added more than once.');
  }

  /**
   * Tests RulesConditionalEmptyUI.
   */
  public function testEmptyUI() {

    // Create component.
    $componentName = 'empty_test';
    $comp = rules_action_set(array());
    $comp->component = TRUE;
    $comp
      ->integrityCheck()
      ->save($componentName);
    $componentPath = 'admin/config/workflow/rules/components';
    RulesPluginUI::$basePath = $componentPath;
    $managePath = RulesPluginUI::path($componentName);
    $addPath = RulesPluginUI::path($componentName, 'add', $comp, 'stub conditional');

    // Test adding with empty UI.
    $this
      ->drupalGet($addPath);
    $this
      ->assertUrl($managePath, array(), 'Adding via the empty UI redirects to the parent edit form.');
  }

  /**
   * Tests RulesConditionalPredicateUI.
   */
  public function testPredicateUI() {

    // Create component.
    $componentName = 'predicate_test';
    $comp = rules_action_set(array(
      'node' => array(
        'type' => 'node',
        'label' => t('Node'),
      ),
    ));
    $comp->component = TRUE;
    $comp
      ->integrityCheck()
      ->save($componentName);
    $componentPath = 'admin/config/workflow/rules/components';
    RulesPluginUI::$basePath = $componentPath;
    $addPath = RulesPluginUI::path($componentName, 'add', $comp, 'stub conditional predicate element');
    $addPredicatePath = RulesPluginUI::path($componentName, 'add-predicate', $comp, 'stub conditional predicate element');

    // Test adding with predicate UI.
    $this
      ->drupalGet($addPath);
    $this
      ->assertUrl($addPredicatePath, array(), 'Adding via the predicate UI redirects to a special creation form.');

    // Add 'data_is'.
    $edit = array(
      'element_name' => 'data_is',
    );
    $this
      ->drupalPost(NULL, $edit, t('Continue'));
    $this
      ->assertFieldByName('parameter[data][settings][data:select]', '', 'Creating a predicate shows the condition form.');

    // Save the condition.
    $edit = array(
      'parameter[data][settings][data:select]' => 'node:type',
    );
    $this
      ->drupalPost(NULL, $edit, t('Continue'));
    $edit = array(
      'parameter[value][settings][value]' => 'page',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // Reload and execute component.
    $comp = rules_config_load($componentName);
    $comp
      ->elements()
      ->current()
      ->action('data_set', array(
      'data:select' => 'node:title',
      'value' => 'evaluate predicate',
    ));
    $comp
      ->execute($node = $this
      ->drupalCreateNode());
    $this
      ->assertEqual('evaluate predicate', $node->title, 'Element created from predicate UI can be evaluated.');
  }

  /**
   * Tests RulesConditionalCaseUI.
   */
  public function testCaseUI() {

    // Create component.
    $componentName = 'case_test';
    $comp = rules_action_set(array(
      'node' => array(
        'type' => 'node',
        'label' => t('Node'),
      ),
    ))
      ->action($switch = rules_conditional_switch('node:type'));
    $comp->component = TRUE;
    $comp
      ->integrityCheck()
      ->save($componentName);
    $componentPath = 'admin/config/workflow/rules/components';
    RulesPluginUI::$basePath = $componentPath;
    $addPath = RulesPluginUI::path($componentName, 'add', $switch, 'case');

    // Test adding a case.
    $this
      ->drupalGet($addPath);
    $this
      ->assertFieldByXPath("//select[@name='parameter[value][settings][value]']", NULL, 'Option case values are shown as select list.');
    $edit = array(
      'parameter[value][settings][value]' => 'page',
    );
    $this
      ->drupalPost(NULL, $edit, t('Save'));

    // Reload and execute component.
    $comp = rules_config_load($componentName);

    // Navigate to switch.
    $comp
      ->elements()
      ->current()
      ->elements()
      ->current()
      ->action('data_set', array(
      'data:select' => 'node:title',
      'value' => 'evaluate case',
    ));
    $comp
      ->execute($node = $this
      ->drupalCreateNode());
    $this
      ->assertEqual('evaluate case', $node->title, 'Case element created from case UI can be evaluated.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RulesConditionalBaseTestCase::assertExecution protected function Asserts a test message from the execution of a rule configuration.
RulesConditionalBaseTestCase::getFileContents protected function Retrieves a file in the test directory.
RulesConditionalUITestCase::getInfo public static function Returns test info.
RulesConditionalUITestCase::setUp protected function Sets up test case.
RulesConditionalUITestCase::testBaseUI public function Tests RulesConditionalPluginUI.
RulesConditionalUITestCase::testCaseUI public function Tests RulesConditionalCaseUI.
RulesConditionalUITestCase::testEmptyUI public function Tests RulesConditionalEmptyUI.
RulesConditionalUITestCase::testPredicateUI public function Tests RulesConditionalPredicateUI.