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());
 }
示例#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;
     }
 }