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());
 }
Exemple #2
0
 /** 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;
     }
 }