<commit_before><?php

class WPPostTest extends \PHPUnit_Framework_TestCase {
	
    public static $wp      = null;
	
    public static $blog    = null;
    
    public static $address = "http://localhost/";
    
    public static $user = "admin";
    
    public static $pass = "<PASSWORD>";
    
    public static $ids  = array();
    
    public static function setUpBeforeClass() {
        
        self::$wp = new \Comodojo\WPAPI\WP(self::$address);
    	
    	if (self::$wp->login(self::$user, self::$pass)) {
    		
    		foreach (self::$wp->getBlogs() as $blog) {
    			
    			foreach ($blog->getPosts() as $id => $post) {
    				
		    		$post->delete();
		    		
		    	}
    			
    			foreach ($blog->getPages() as $id => $post) {
    				
		    		$post->delete();
		    		
		    	}
    		
    			self::$blog = $blog;
    			
    			break;
		    	
    		}
    		
    	}
    
    }
    
    public function testWPPostCreate() {
    	
    	$timestamp = time();
    	
    	if (self::$wp->isLogged()) {
			
			for ($i=0; $i<3; $i++) {
				
				$post = new \Comodojo\WPAPI\WPPost(self::$blog);
				
				$post->setTitle("Test POST n." . $i)
					->setCreationDate($timestamp - ($i * 60))
					->setStatus("draft")
					->setType("post")
					->setFormat("standard")
					->setAuthor(self::$blog->getProfile())
					->setPassword("")
					->setExcerpt("Test " . $i)
					->setContent("Post content N." . $i)
					->setMenuOrder($i)
					->setCommentStatus("open")
					->setPingStatus("open")
					->setSticky(false)
					->setCustomField("test_custom_field", $i)
					->setCustomField("test_custom_data",  date("Y-m-d H:i:s",$timestamp))
					->setPingStatus("open")
					->addCategory("wptest")
					->addTag("wpapi")
					->save();
					
				array_push(self::$ids, $post->getID());
				
			}
    		
    		$posts = self::$blog->getPosts("post", "draft", 3);
			
			$this->assertSame($posts->getLength(), 3);
			
    	}
    	
    }
    
    public function testWPPostData() {
		
    	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"));
				
				$timestamp = strtotime($post->getCustomField("test_custom_data"));
				
				$this->assertSame($post->getCreationDate(), $timestamp + 7200 - ($i * 60));
				
				$this->assertSame($post->getTitle(), "Test POST n." . $i);
				
				$this->assertSame($post->getStatus(), "draft");
				
				$this->assertSame($post->getType(), "post");
				
				$this->assertSame($post->getFormat(), "standard");
				
				$this->assertSame($post->getAuthor()->getID(), self::$blog->getProfile()->getID());
				
				$this->assertSame($post->getPassword(), false);
				
				$this->assertSame($post->getExcerpt(), "Test " . $i);
				
				$this->assertSame($post->getContent(), "Post content N." . $i);
				
				$this->assertSame($post->getMenuOrder(), $i);
				
				$this->assertSame($post->getCommentStatus(), "open");
				
				$this->assertSame($post->getPingStatus(), "open");<commit_msg>new tests, bug fixes and some complexity issues addressed<commit_after><?php

class WPPostTest extends \PHPUnit_Framework_TestCase {
	
    public static $wp      = null;
	
    public static $blog    = null;
    
    public static $address = "http://localhost/";
    
    public static $user = "admin";
    
    public static $pass = "<PASSWORD>";
    
    public static $ids  = array();
    
    public static function setUpBeforeClass() {
        
        self::$wp = new \Comodojo\WPAPI\WP(self::$address);
    	
    	if (self::$wp->login(self::$user, self::$pass)) {
    		
    		foreach (self::$wp->getBlogs() as $blog) {
    			
    			foreach ($blog->getPosts() as $id => $post) {
    				
		    		$post->delete();
		    		
		    	}
    			
    			foreach ($blog->getPages() as $id => $post) {
    				
		    		$post->delete();
		    		
		    	}
    		
    			self::$blog = $blog;
    			
    			break;
		    	
    		}
    		
    	}
    
    }
    
    public function testWPPostCreate() {
    	
    	$timestamp = time();
    	
    	if (self::$wp->isLogged()) {
			
			for ($i=0; $i<3; $i++) {
				
				$post = new \Comodojo\WPAPI\WPPost(self::$blog);
				
				$post->setTitle("Test POST n." . $i)
					->setCreationDate($timestamp - ($i * 60))
					->setStatus("draft")
					->setType("post")
					->setFormat("standard")
					->setAuthor(self::$blog->getProfile())
					->setPassword("")
					->setExcerpt("Test " . $i)
					->setContent("Post content N." . $i)
					->setMenuOrder($i)
					->setCommentStatus("open")
					->setPingStatus("open")
					->setSticky(false)
					->setCustomField("test_custom_field", $i)
					->setCustomField("test_custom_data",  date("Y-m-d H:i:s",$timestamp))
					->setPingStatus("open")
					->addCategory("wptest")
					->addTag("wpapi")
					->save();
					
				array_push(self::$ids, $post->getID());
				
			}
    		
    		$posts = self::$blog->getPosts("post", "draft", 3);
			
			$this->assertSame($posts->getLength(), 3);
			
    	}
    	
    }
    
    public function testWPPostData() {
		
    	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"));
				
				$timestamp = strtotime($post->getCustomField("test_custom_data"));
				
				$this->assertSame($post->getCreationDate(), $timestamp - ($i * 60));
				
				$this->assertSame($post->getTitle(), "Test POST n." . $i);
				
				$this->assertSame($post->getStatus(), "draft");
				
				$this->assertSame($post->getType(), "post");
				
				$this->assertSame($post->getFormat(), "standard");
				
				$this->assertSame($post->getAuthor()->getID(), self::$blog->getProfile()->getID());
				
				$this->assertSame($post->getPassword(), false);
				
				$this->assertSame($post->getExcerpt(), "Test " . $i);
				
				$this->assertSame($post->getContent(), "Post content N." . $i);
				
				$this->assertSame($post->getMenuOrder(), $i);
				
				$this->assertSame($post->getCommentStatus(), "open");
				
				$this->assertSame($post->getPingStatus(), "open");
{'fraction_non_alphanumeric': 0.19846851070479762, 'fraction_numerical': 0.003750586029067042, 'mean_word_length': 2.335070349140177, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 141, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5972173', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2172, 'n_words': 340}