(我试图解决代码示例的样式问题)
我正在开发一个主题,但我有一些课程是为这个主题开发的。我想在我的主题上运行单元测试。
我遵循以下步骤:
已将测试repo签出到我的根web文件夹:
svn co http://develop.svn.wordpress.org/trunk/ wordpress-develop
将我的主题文件夹复制到wordpress develop/src/wp content/themes
创建了一个空数据库并设置wp tests配置。php文件。还将此行添加到wp tests配置中。php
define( \'WP_DEFAULT_THEME\', \'THEMENAME\' );
创建wordpress开发/测试/phpunit/测试/konser。包含以下内容的php文件:
<?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!=\'\');
}
}
}
但是我想用我的Konser
和PostType
课程。function setUp() {
$this->post_id = new Konser(410);
parent::setUp();
}
function test_ID() {
$this->assertInternalType("int", $this->post_id);
}
在wordpress开发/测试/phpunit/包含/功能中添加了这两行。php require_once(\'src/wp-content/themes/THEMENAME/include/PostType.php\');
require_once(\'src/wp-content/themes/THEMENAME/include/Konser.php\');
但是我Call to undefined function get_post() in konsertv-develop/src/wp-content/themes/THEMENAME/include/PostType.php你能告诉我我错过了什么吗?
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;
}
}