You are here

public function FeatureContext::createUnitTypes in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

@Given /^unit types:$/

File

test/features/bootstrap/FeatureContext.php, line 322

Class

FeatureContext
Features context.

Code

public function createUnitTypes(TableNode $nodesTable) {
  $random = new Random();
  foreach ($nodesTable
    ->getHash() as $nodeHash) {
    $unit_type_definition = array();
    $unit_type_definition['type'] = isset($nodeHash['type']) ? $nodeHash['type'] : drupal_strtolower($random
      ->name(8));
    $unit_type_definition['label'] = isset($nodeHash['label']) ? $nodeHash['label'] : $random
      ->name(8);
    $other_properties = array(
      'base_price',
      'min_children',
      'max_children',
      'min_sleeps',
      'max_sleeps',
    );
    foreach ($other_properties as $property) {
      if (isset($nodeHash[$property])) {
        $unit_type_definition['data'][$property] = $nodeHash[$property];
      }
    }
    $unit_type = rooms_unit_type_create($unit_type_definition);
    $unit_type
      ->save();
    $this->unitTypes[] = $unit_type;
  }
}