(I'm trying to solve style problems of code samples)
I'm developing a theme but I have some classes which developed for this theme. I want to run unit tests on my theme.
I've followed this steps:
Checked out test repo to my root web folder:
svn co http://develop.svn.wordpress.org/trunk/ wordpress-develop
Copied my theme folder to wordpress-develop/src/wp-content/themes
Created an empty database and set up wp-tests-config.php file. Also added this line to wp-tests-config.php
define( 'WP_DEFAULT_THEME', 'THEMENAME' );
Created wordpress-develop/tests/phpunit/tests/konser.php file with this content:
<?php class Test_Konser extends WP_UnitTestCase { public function test_firstTest(){ // Arrange $id = $this->factory->post->create(array( 'post_type' => 'konser', )); add_post_meta($id, "konser_tarih", time()); $ids = get_posts(array( 'post_type' => 'konser', ) ); foreach ($ids as $id) { $this->assertInstanceOf('WP_Post',$id); $ss = get_post_meta($id->ID, "konser_tarih", true); $this->assertTrue($ss!=''); } } }
But I want to use my
Konser
andPostType
classes.function setUp() { $this->post_id = new Konser(410); parent::setUp(); } function test_ID() { $this->assertInternalType("int", $this->post_id); }
Added this 2 lines to /wordpress-develop/tests/phpunit/includes/functions.php
require_once('src/wp-content/themes/THEMENAME/include/PostType.php'); require_once('src/wp-content/themes/THEMENAME/include/Konser.php');
But I'm getting Call to undefined function get_post() in konsertv-develop/src/wp-content/themes/THEMENAME/include/PostType.php
Can you tell me what I'm missing?
CONTENT OF PostType.php
<?php
class PostType
{
public $post;
public $ID;
function PostType($ID) {
$this->post = get_post($ID);
$this->ID = $ID;
}
function getPost()
{
return $this->post;
}
function getTarih()
{
return get_post_meta($this->ID, "konser_tarih", true);
}
function getID()
{
return $this->ID;
}
}