You are here

function RulesTestCase::testSorting in Rules 8.3

Same name and namespace in other branches
  1. 7.2 tests/rules.test \RulesTestCase::testSorting()

Test sorting rule elements.

File

d7-tests/rules_test_case.test, line 390
Rules 7.x tests.

Class

RulesTestCase

Code

function testSorting() {
  $rule = $this
    ->createTestRule();
  $conditions = $rule
    ->conditions();
  $conditions[0]->weight = 10;
  $conditions[2]->weight = 10;
  $id[0] = $conditions[0]
    ->elementId();
  $id[1] = $conditions[1]
    ->elementId();
  $id[2] = $conditions[2]
    ->elementId();

  // For testing use a deep sort, even if not necessary here.
  $rule
    ->sortChildren(TRUE);
  $conditions = $rule
    ->conditions();
  $this
    ->assertEqual($conditions[0]
    ->elementId(), $id[1], 'Condition sorted correctly.');
  $this
    ->assertEqual($conditions[1]
    ->elementId(), $id[0], 'Condition sorted correctly.');
  $this
    ->assertEqual($conditions[2]
    ->elementId(), $id[2], 'Condition sorted correctly.');
}