Exemple #1
0
 /**
  * @depends testWPPostData 
  */
 public function testWPPostModify()
 {
     if (self::$wp->isLogged()) {
         $posts = self::$blog->getPosts("post", "draft", 3);
         $this->assertSame($posts->getLength(), 3);
         foreach ($posts as $id => $post) {
             $this->assertTrue(in_array(intval($id), self::$ids));
             $i = intval($post->getCustomField("test_custom_field"));
             $post->setTitle("Ready to be deleted");
             if ($i > 0) {
                 $parent = new \Comodojo\WPAPI\WPPost(self::$blog);
                 $parent->loadFromID(self::$ids[$i - 1]);
                 $post->setParent($parent);
             }
             $post->setStatus("publish")->cleanCustomFields()->removeCategory("wptest")->removeTag("wpapi")->save();
             $parent = $post->getParent();
             if (!is_null($parent)) {
                 $this->assertTrue(in_array($parent->getID(), self::$ids));
             }
             $this->assertSame($post->getStatus(), "publish");
             $this->assertFalse($post->hasCategory("wptest"));
             $this->assertFalse($post->hasTag("wpapi"));
             $this->assertFalse($post->hasCustomField("test_custom_field"));
         }
     }
 }
Exemple #2
0
 /**
  * @depends testWPBlogUsers 
  */
 public function testWPBlogPosts()
 {
     $timestamp = time() - 7200;
     for ($i = 0; $i < 3; $i++) {
         $new_post = new \Comodojo\WPAPI\WPPost(self::$blog);
         $new_post->setTitle("Test post n." . $i)->setCreationDate($timestamp - $i * 60)->setContent("TEST")->addTag("Test Tag " . $i)->addCategory("Test Category " . $i)->setStatus("publish")->save();
         $this->assertGreaterThan(0, $new_post->getID());
     }
     for ($i = 0; $i < 3; $i++) {
         $posts = self::$blog->getPostsByTag("Test Tag " . $i);
         $this->assertGreaterThan(0, $posts->getLength());
         foreach ($posts as $post) {
             $this->assertSame($post->getTitle(), "Test post n." . $i);
         }
     }
     for ($i = 0; $i < 3; $i++) {
         $posts = self::$blog->getPostsByCategory("Test Category " . $i);
         $this->assertGreaterThan(0, $posts->getLength());
         foreach ($posts as $post) {
             $this->assertSame($post->getTitle(), "Test post n." . $i);
         }
     }
     foreach (self::$blog->getLatestPosts() as $post) {
         $this->assertSame($post->getContent(), "TEST");
         $p = self::$blog->getPostByID($post->getID());
         $this->assertSame($post->getTitle(), $p->getTitle());
         $this->assertTrue($post->delete());
     }
 }