public function testToStringCheckInConstraint()
{
$u1 = new Unit(1, 10, array());
$checkin_day = 1;
$units = array($u1);
$sd = new \DateTime('2016-01-01 12:12');
$ed = new \DateTime('2016-03-31 18:12');
$sd1 = new \DateTime('2016-01-02 12:12');
$ed1 = new \DateTime('2016-01-10 13:12');
// Create an event for unit 1.
$e1u1 = new Event($sd1, $ed1, $u1, 11);
$store = new SqlLiteDBStore($this->pdo, 'availability_event', SqlDBStore::BAT_STATE);
$calendar = new Calendar($units, $store);
// Add the events.
$calendar->addEvents(array($e1u1), Event::BAT_HOURLY);
// Constraint with Dates
$checkinday_constraint = new CheckInDayConstraint(array($u1), $checkin_day, $sd, $ed);
$string = $checkinday_constraint->toString();
$this->assertEquals($string['text'], 'From @start_date to @end_date, bookings must start on @day_of_the_week');
$this->assertEquals($string['args']['@start_date'], '2016-01-01');
$this->assertEquals($string['args']['@end_date'], '2016-03-31');
$this->assertEquals($string['args']['@day_of_the_week'], 'Monday');
$constraints = array($checkinday_constraint);
// Constraint without Dates
$checkinday_constraint = new CheckInDayConstraint(array($u1), $checkin_day);
$string = $checkinday_constraint->toString();
$this->assertEquals($string['text'], 'Bookings must start on @day_of_the_week');
$this->assertEquals($string['args']['@day_of_the_week'], 'Monday');
$response = $calendar->getMatchingUnits($sd, $ed, array(10, 11), array());
$valid_unit_ids = array_keys($response->getIncluded());
$this->assertEquals($valid_unit_ids[0], 1);
// Applying the constraint the unit 1 should be no longer valid.
$response->applyConstraints($constraints);
$invalid_unit_ids = array_keys($response->getExcluded());
$this->assertEquals($invalid_unit_ids[0], 1);
}