我已经开始在构建中加入单元测试。我有一个创建数据库表和数据库版本选项的类。
我不知道如何测试是否正在创建表和选项。这是课程
class Safety_links_Create_Database {
public function __construct() {
$this->create_db();
}
/**
* Get the databse version
* @return string the databse version
*/
public function get_db_version() {
$database_version = SAFETY_LINKS_DB_VERSION;
return $database_version;
}
public function get_table_name() {
$table_name = SAFETY_LINKS_DB_TABLE_NAME;
return $table_name;
}
public function get_db_option_name() {
$option_name = SAFETY_LINKS_DB_OPTION_NAME;
return $option_name;
}
public function get_charset() {
$charset = SAFETY_LINKS_DB_CHARSET_NAME;
return $charset;
}
public function check_table_name() {
$table_name = $this->get_table_name();
$check_name = $GLOBALS[\'wpdb\']->get_var("show tables like \'$table_name\'");
if( $check_name != $table_name ) {
return true;
}
return false;
}
public function create_db() {
global $wpdb;
$table_name = $this->get_table_name();
$charset = $this->get_charset();
if( $wpdb->get_var( "SHOW TABLES LIKE \'$table_name\'" ) != $table_name ) {
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
ulr VARCHAR(2083) NOT NULL,
code smallint(3) NOT NULL,
body tinytext NOT NULL,
date datetime DEFAULT \'0000-00-00 00:00:00\' NOT NULL,
UNIQUE KEY id (id)
) $charset;";
require_once( ABSPATH . \'wp-admin/includes/upgrade.php\' );
dbDelta($sql);
if( !get_option( $this->get_db_option_name() ) ) {
add_option( $this->get_db_option_name(), $this->get_db_version() );
}
}
}
}
就像我说的,我不知道如何构建一个测试,或者是否需要测试。