You are here

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

Checks the state of a unit for a given range of dates.

Parameters

$unit_name: The name of the unit actions be performed.

$start_date: The range start date.

$end_date: The range end date.

$expected_value: The id that the event should have.

$type: The operation to perform type. Can be pricing or availability.

Throws

RuntimeException

3 calls to FeatureContext::checkUnitPropertyRange()
FeatureContext::checkUnitLockedByLastBooking in test/features/bootstrap/FeatureContext.php
Checks if one unit is being locked by a booking in a date range.
FeatureContext::thePriceForBetweenAndShouldBe in test/features/bootstrap/FeatureContext.php
@Then /^the price for "([^"]*)" between "([^"]*)" and "([^"]*)" should be "([^"]*)"$/
FeatureContext::theStateForBetweenAndShouldBe in test/features/bootstrap/FeatureContext.php
@Then /^the state for "([^"]*)" between "([^"]*)" and "([^"]*)" should be "([^"]*)"$/

File

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

Class

FeatureContext
Features context.

Code

protected function checkUnitPropertyRange($unit_name, $start_date, $end_date, $expected_value, $type) {
  $unit_id = $this
    ->findBookableUnitByName($unit_name);
  $start = new DateTime($start_date);
  $start_format = $start
    ->format('Y-m-d');
  $end = new DateTime($end_date);
  $end_format = $end
    ->format('Y-m-d');
  foreach ($this
    ->monthsBetweenDates($start, $end) as $month) {
    $path = 'bat/v1/' . $type . '?units=' . $unit_id . '&start_date=' . $month
      ->format('Y-m') . '-01&duration=1M';
    $this
      ->getSession()
      ->visit($this
      ->locatePath($path));
    $content = $this
      ->getSession()
      ->getPage()
      ->find('xpath', '/body')
      ->getText();
    $events = json_decode($content);
    foreach ($events->events->{$unit_id} as $event) {
      $event_start = new DateTime($event->start);
      $event_end = new DateTime($event->end);
      if ($start_format >= $event_start
        ->format('Y-m-d') && $end_format <= $event_end
        ->format('Y-m-d')) {

        // Throw exception if the event id is not the desired.
        if ($event->id != $expected_value) {
          throw new RuntimeException("The {$type} for unit {$unit_name} between {$start_date} and {$end_date} is not always {$expected_value}");
        }
      }
    }
  }
}