public function testPeriodPersistence()
 {
     $ts = new TestScenario($this->factory);
     $post = $ts->setUpBasicSet();
     $persistence = new Persistence($post);
     $periods = array(new Period(1, '13:00', '17:00'), new Period(2, '16:30', '19:00'));
     $persistence->savePeriods($periods);
     // Check meta
     $meta = get_post_meta($post->ID, Persistence::PERIODS_META_KEY, true);
     $this->assertTrue(is_array($meta));
     $this->assertEquals(2, count($meta));
     $this->assertTrue(is_array($meta[0]));
     $this->assertTrue(is_array($meta[1]));
     $p1 = $meta[0];
     $p2 = $meta[1];
     $this->assertEquals(1, $p1['weekday']);
     $this->assertEquals('13:00', $p1['timeStart']);
     $this->assertEquals('17:00', $p1['timeEnd']);
     $this->assertEquals(2, $p2['weekday']);
     $this->assertEquals('16:30', $p2['timeStart']);
     $this->assertEquals('19:00', $p2['timeEnd']);
     // Load Periods
     $periods = $persistence->loadPeriods();
     $this->assertTrue(is_array($periods));
     $this->assertEquals(2, count($periods));
     $p1 = $periods[0];
     $p2 = $periods[1];
     $format = Dates::STD_TIME_FORMAT;
     $this->assertEquals(1, $p1->getWeekday());
     $this->assertEquals('13:00', $p1->getTimeStart()->format($format));
     $this->assertEquals('17:00', $p1->getTimeEnd()->format($format));
     $this->assertEquals(2, $p2->getWeekday());
     $this->assertEquals('16:30', $p2->getTimeStart()->format($format));
     $this->assertEquals('19:00', $p2->getTimeEnd()->format($format));
 }
 /** @inheritdoc */
 protected function saveData($post_id, WP_Post $post, $update)
 {
     $config = $_POST['opening-hours'];
     $periods = $this->getPeriodsFromPostData($config);
     $persistence = new Persistence($post);
     $persistence->savePeriods($periods);
 }
 public function setUpSetWithData(array $args = array(), array $periods = array(), array $holidays = array(), array $irregularOpenings = array())
 {
     $post = $this->setUpBasicSet($args);
     $persistence = new Persistence($post);
     if (count($periods) > 0) {
         $persistence->savePeriods($periods);
     }
     if (count($holidays) > 0) {
         $persistence->saveHolidays($holidays);
     }
     if (count($irregularOpenings) > 0) {
         $persistence->saveIrregularOpenings($irregularOpenings);
     }
     return $post;
 }
Beispiel #4
0
 public function testGetPeriodsByDay()
 {
     $ts = new TestScenario($this->factory);
     $post = $ts->setUpBasicSet();
     $persistence = new Persistence($post);
     $persistence->savePeriods(array(new Period(1, '13:00', '17:00'), new Period(1, '18:00', '21:00'), new Period(2, '13:00', '17:00')));
     $set = new Set($post);
     $day1 = $set->getPeriodsByDay(1);
     $this->assertEquals(2, count($day1));
     $this->assertEquals(1, $day1[0]->getWeekday());
     $this->assertEquals(1, $day1[1]->getWeekday());
     $day2 = $set->getPeriodsByDay(2);
     $this->assertTrue(is_array($day2));
     $this->assertEquals(1, count($day2));
     $this->assertEquals(2, $day2[0]->getWeekday());
     $day3 = $set->getPeriodsByDay(3);
     $this->assertTrue(is_array($day3));
     $this->assertEquals(0, count($day3));
     $days12 = $set->getPeriodsByDay(array(1, 2));
     $this->assertEquals(3, count($days12));
 }