You are here

public function RulesConditionalUITestCase::testPredicateUI in Conditional Rules 8

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

Tests RulesConditionalPredicateUI.

File

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

Class

RulesConditionalUITestCase
UI tests.

Code

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.');
}