/** @inheritdoc */ protected function saveData($post_id, WP_Post $post, $update) { $config = $_POST[static::GLOBAL_POST_KEY]; $ios = $this->getIrregularOpeningsFromPostData($config); $persistence = new Persistence($post); $persistence->saveIrregularOpenings($ios); }
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; }
public function testIrregularOpeningPersistence() { $ts = new TestScenario($this->factory); $post = $ts->setUpBasicSet(); $persistence = new Persistence($post); $ios = array(new IrregularOpening('IO1', '2016-02-03', '13:00', '17:00'), new IrregularOpening('IO2', '2016-03-03', '16:30', '19:00')); $persistence->saveIrregularOpenings($ios); // Check meta $meta = get_post_meta($post->ID, Persistence::IRREGULAR_OPENINGS_META_KEY, true); $this->assertTrue(is_array($meta)); $this->assertEquals(2, count($meta)); $io1 = $meta[0]; $io2 = $meta[1]; $this->assertEquals('IO1', $io1['name']); $this->assertEquals('2016-02-03', $io1['date']); $this->assertEquals('13:00', $io1['timeStart']); $this->assertEquals('17:00', $io1['timeEnd']); $this->assertEquals('IO2', $io2['name']); $this->assertEquals('2016-03-03', $io2['date']); $this->assertEquals('16:30', $io2['timeStart']); $this->assertEquals('19:00', $io2['timeEnd']); // Load Irregular Openings $ios = $persistence->loadIrregularOpenings(); $this->assertTrue(is_array($ios)); $this->assertEquals(2, count($ios)); $io1 = $ios[0]; $io2 = $ios[1]; $this->assertEquals('IO1', $io1->getName()); $this->assertEquals(new DateTime('2016-02-03'), $io1->getDate()); $this->assertEquals(new DateTime('2016-02-03 13:00'), $io1->getTimeStart()); $this->assertEquals(new DateTime('2016-02-03 17:00'), $io1->getTimeEnd()); $this->assertEquals('IO2', $io2->getName()); $this->assertEquals(new DateTime('2016-03-03'), $io2->getDate()); $this->assertEquals(new DateTime('2016-03-03 16:30'), $io2->getTimeStart()); $this->assertEquals(new DateTime('2016-03-03 19:00'), $io2->getTimeEnd()); }