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)); }
/** Sets up the Set instance */ public function setUp() { $childPosts = get_posts(array('post_type' => SetCpt::CPT_SLUG, 'post_parent' => $this->getId())); foreach ($childPosts as $post) { if (self::postMatchesCriteria($post)) { $this->id = $post->ID; $this->post = $post; break; } } /** Action: op_set_before_setup */ do_action(self::WP_ACTION_BEFORE_SETUP, $this); $persistence = new Persistence($this->post); $this->periods = ArrayObject::createFromArray($persistence->loadPeriods()); $this->holidays = ArrayObject::createFromArray($persistence->loadHolidays()); $this->irregularOpenings = ArrayObject::createFromArray($persistence->loadIrregularOpenings()); $post_detail_description = get_post_detail('description', $this->id); $post_parent_detail_description = get_post_detail('description', $this->parentId); if (!empty($post_detail_description)) { $this->description = $post_detail_description; } elseif (!empty($post_parent_detail_description)) { $this->description = $post_parent_detail_description; } }