/** @inheritdoc */ protected function saveData($post_id, WP_Post $post, $update) { $config = $_POST[static::GLOBAL_POST_KEY]; $holidays = $this->getHolidaysFromPostData($config); $persistence = new Persistence($post); $persistence->saveHolidays($holidays); }
public function testHolidayPersistence() { $ts = new TestScenario($this->factory); $post = $ts->setUpBasicSet(); $persistence = new Persistence($post); $holidays = array(new Holiday('Holiday1', new DateTime('2016-02-03'), new DateTime('2016-02-07')), new Holiday('Holiday2', new DateTime('2016-03-03'), new DateTime('2016-03-07'))); $persistence->saveHolidays($holidays); // Check meta $meta = get_post_meta($post->ID, Persistence::HOLIDAYS_META_KEY, true); $this->assertTrue(is_array($meta)); $this->assertEquals(2, count($meta)); $h1 = $meta[0]; $h2 = $meta[1]; $this->assertEquals('Holiday1', $h1['name']); $this->assertEquals('2016-02-03', $h1['dateStart']); $this->assertEquals('2016-02-07', $h1['dateEnd']); $this->assertEquals('Holiday2', $h2['name']); $this->assertEquals('2016-03-03', $h2['dateStart']); $this->assertEquals('2016-03-07', $h2['dateEnd']); // Load Holidays $holidays = $persistence->loadHolidays(); $this->assertTrue(is_array($holidays)); $this->assertEquals(2, count($holidays)); $h1 = $holidays[0]; $h2 = $holidays[1]; $this->assertEquals('Holiday1', $h1->getName()); $this->assertEquals(new DateTime('2016-02-03'), $h1->getDateStart()); $this->assertEquals(new DateTime('2016-02-07 23:59:59'), $h1->getDateEnd()); $this->assertEquals('Holiday2', $h2->getName()); $this->assertEquals(new DateTime('2016-03-03'), $h2->getDateStart()); $this->assertEquals(new DateTime('2016-03-07 23:59:59'), $h2->getDateEnd()); }
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; }