update database version
This commit is contained in:
parent
7a662ac5c3
commit
03bc11fb74
@ -16,15 +16,7 @@ class PluginWonderful {
|
||||
$this->adboxes_client = new PWAdboxesClient();
|
||||
|
||||
$this->_get_publisher_info();
|
||||
|
||||
$result = get_option('plugin-wonderful-database-version');
|
||||
if (empty($result) || ($result < PLUGIN_WONDERFUL_DATABASE_VERSION)) {
|
||||
if ($this->adboxes_client->initialize(true)) {
|
||||
update_option('plugin-wonderful-database-version', PLUGIN_WONDERFUL_DATABASE_VERSION);
|
||||
} else {
|
||||
$this->messages[] = "Unable to update database schema!";
|
||||
}
|
||||
}
|
||||
$this->_update_database_version();
|
||||
|
||||
$this->set_up_widgets();
|
||||
|
||||
@ -36,6 +28,17 @@ class PluginWonderful {
|
||||
return new PublisherInfo();
|
||||
}
|
||||
|
||||
function _update_database_version() {
|
||||
$result = get_option('plugin-wonderful-database-version');
|
||||
if (empty($result) || ($result < PLUGIN_WONDERFUL_DATABASE_VERSION)) {
|
||||
if ($this->adboxes_client->initialize(true)) {
|
||||
update_option('plugin-wonderful-database-version', PLUGIN_WONDERFUL_DATABASE_VERSION);
|
||||
} else {
|
||||
$this->messages[] = "Unable to update database schema!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _get_publisher_info() {
|
||||
$this->publisher_info = false;
|
||||
$member_id = get_option('plugin-wonderful-memberid');
|
||||
|
@ -5,6 +5,9 @@ require_once(dirname(__FILE__) . '/../classes/PluginWonderful.php');
|
||||
require_once(dirname(__FILE__) . '/../classes/PublisherInfo.php');
|
||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
|
||||
|
||||
define("PLUGIN_WONDERFUL_DATABASE_VERSION", 5);
|
||||
define('PLUGIN_WONDERFUL_UPDATE_TIME', 60 * 60 * 12); // every 12 hours
|
||||
|
||||
class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
function setUp() {
|
||||
$this->pw = new PluginWonderful();
|
||||
@ -141,6 +144,41 @@ class PluginWonderfulTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$this->assertEquals($expected_result, $pw->_get_publisher_info());
|
||||
}
|
||||
|
||||
function providerTestUpdateDatabaseVersion() {
|
||||
return array(
|
||||
array(false, true, false),
|
||||
array(false, true, true),
|
||||
array(PLUGIN_WONDERFUL_DATABASE_VERSION - 1, true, false),
|
||||
array(PLUGIN_WONDERFUL_DATABASE_VERSION - 1, true, true),
|
||||
array(PLUGIN_WONDERFUL_DATABASE_VERSION, false, false),
|
||||
array(PLUGIN_WONDERFUL_DATABASE_VERSION, false, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerTestUpdateDatabaseVersion
|
||||
*/
|
||||
function testUpdateDatabaseVersion($option, $will_initialize, $initialize_results) {
|
||||
update_option('plugin-wonderful-database-version', $option);
|
||||
|
||||
$this->pw->adboxes_client = $this->getMock('PWAdboxesClient', array('initialize'));
|
||||
if ($will_initialize) {
|
||||
$this->pw->adboxes_client->expects($this->once())->method('initialize')->will($this->returnValue($initialize_results));
|
||||
} else {
|
||||
$this->pw->adboxes_client->expects($this->never())->method('initialize');
|
||||
}
|
||||
|
||||
$this->pw->_update_database_version();
|
||||
|
||||
if ($will_initialize) {
|
||||
if ($initialize_results) {
|
||||
$this->assertEquals(PLUGIN_WONDERFUL_DATABASE_VERSION, get_option('plugin-wonderful-database-version'));
|
||||
} else {
|
||||
$this->assertEquals(1, count($this->pw->messages));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user