You are here

StateFlowSPSIntegrationWeb.test in State Machine 7.2

File

modules/state_flow_sps/tests/StateFlowSPSIntegrationWeb.test
View source
<?php

class StateFlowSPSIntegrationWebTest extends DrupalWebTestCase {
  static function getInfo() {
    return array(
      'name' => 'State Flow SPS Integration Web Tests',
      'description' => 'Test the State Flow integration.',
      'group' => 'SPSInteractiveIntegration',
    );
  }
  public function setUp() {
    parent::setUp("iib", "sps", "sps_test", "ctools", "state_flow", "state_flow_schedule", "state_flow_sps");
  }
  public function testStateFlowBasicTableData() {
    $this
      ->clearSchedule();
    $basic = array(
      array(
        2,
        2,
        time() + 1000,
      ),
      array(
        2,
        5,
        time() + 2000,
      ),
      array(
        3,
        8,
        time() + 3000,
      ),
      array(
        3,
        11,
        time() + 4000,
      ),
      array(
        4,
        12,
        time() + 10000,
      ),
      array(
        4,
        14,
        time() + 20000,
      ),
      array(
        5,
        17,
        time() + 30000,
      ),
      array(
        5,
        18,
        time() + 40000,
      ),
    );
    $this
      ->addValuesToSchedule($basic);
    $test_manager = new Drupal\sps\Test\Manager();
    $state_flow_override = new Drupal\state_flow_sps\StateFlowOverride(array(), $test_manager);
    $state_flow_override
      ->setData(time());
    $overrides = $state_flow_override
      ->getOverrides();
    $this
      ->assertTrue(empty($overrides), 'StateFlowOverrides should not return any overrides if none exist for the timeframe.');
    $state_flow_override
      ->setData(time() + 2500);
    $overrides = $state_flow_override
      ->getOverrides();
    $this
      ->verbose('<pre>' . print_r($overrides, TRUE) . '</pre>');
    $this
      ->assertTrue(!empty($overrides['node-2']), 'StateFlowOverride should return nodes in the \'Scheduled\' state.');
    $this
      ->assertEqual($overrides['node-2']['vid'], 5, 'StateFlowOverride should properly find the revision a node will be transitioned to.');
    if (!empty($overrides['node-3'])) {
      $this
        ->fail('StateFlowOverrides should not return overrides scheduled in the future');
    }
    else {
      $this
        ->pass('StateFlowOverrides should not return overrides scheduled in the future');
    }
  }

  /**
   * Add values to the state_flow_schedule table.
   *
   * @param $values - an array of data with fields:
   *  nid, vid, date
   */
  protected function addValuesToSchedule($values) {
    $insert = db_insert('state_flow_schedule')
      ->fields(array(
      'nid',
      'vid',
      'date',
    ));
    foreach ($values as $item) {
      $insert
        ->values($item);
    }
    $insert
      ->execute();
  }

  /**
   * Clear all the data from state_flow_schedule table.
   */
  protected function clearSchedule() {
    db_delete('state_flow_schedule')
      ->execute();
  }

}

Classes