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()); }
/** * Sets up test set with criteria to test postMatchesCriteria * Any parameter can be null and no meta will be saved * * @param int $startOffset The offset in days from today * @param int $endOffset The offset in days from today * @param bool $weekScheme Whether the week scheme shall match * @param array $postArgs Custom args for the new post * @return WP_Post The post representing the newly created set */ protected function setUpSetWithCriteria($startOffset = null, $endOffset = null, $weekScheme = null, $postArgs = array()) { $ts = new TestScenario($this->factory); $post = $ts->setUpBasicSet($postArgs); if ($startOffset !== null) { $date = new DateTime('00:00'); $interval = new DateInterval('P' . abs($startOffset) . 'D'); if ($startOffset < 0) { $interval->invert = 1; } $date->add($interval); update_post_meta($post->ID, get_meta_key('date-start', SetPostType::CPT_SLUG), $date->format(Dates::STD_DATE_FORMAT)); } if ($endOffset !== null) { $date = new DateTime('23:59:59'); $interval = new DateInterval('P' . abs($endOffset) . 'D'); if ($endOffset < 0) { $interval->invert = 1; } $date->add($interval); update_post_meta($post->ID, get_meta_key('date-end', SetPostType::CPT_SLUG), $date->format(Dates::STD_DATE_FORMAT)); } if ($weekScheme === null) { $wsm = 'all'; } else { $now = new DateTime('now'); $nowEven = (int) $now->format('W') % 2 === 0; if (!$weekScheme) { $nowEven = !$nowEven; } $wsm = $nowEven ? 'even' : 'odd'; } update_post_meta($post->ID, get_meta_key('week-scheme', SetPostType::CPT_SLUG), $wsm); return $post; }
public function testWillBeOpen() { $ts = new TestScenario($this->factory); $hStart = Dates::applyWeekContext(new DateTime('00:00:00'), 2); $hEnd = clone $hStart; $hEnd->add(new DateInterval('P1D')); $post = $ts->setUpSetWithData(array(), array(), array(new Holiday('Holiday', $hStart, $hEnd))); $set = new Set($post); $p1 = new Period(2, '13:00', '18:00'); $p2 = new Period(4, '13:00', '18:00'); $this->assertFalse($p1->willBeOpen($set)); $this->assertTrue($p2->willBeOpen($set)); }