code coverage
This commit is contained in:
parent
ad64a7b349
commit
4a8ddf2e5a
|
@ -37,6 +37,7 @@ class DailyImageWidget {
|
||||||
/**
|
/**
|
||||||
* WordPress init hook.
|
* WordPress init hook.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function _init() {
|
function _init() {
|
||||||
wp_register_sidebar_widget(
|
wp_register_sidebar_widget(
|
||||||
'hubblesite-daily-image',
|
'hubblesite-daily-image',
|
||||||
|
@ -59,21 +60,25 @@ class DailyImageWidget {
|
||||||
$this->handle_post();
|
$this->handle_post();
|
||||||
$this->get_display_options();
|
$this->get_display_options();
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a warning if the connection failed.
|
* Display a warning if the connection failed.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function _connection_warning() {
|
function _connection_warning() {
|
||||||
echo "<div class=\"updated fade\">";
|
echo "<div class=\"updated fade\">";
|
||||||
_e("<strong>HubbleSite Daily Image Widget</strong> was unable to retrieve new data from HubbleSite.", "hubblesite-daily-image-widget");
|
_e("<strong>HubbleSite Daily Image Widget</strong> was unable to retrieve new data from HubbleSite.", "hubblesite-daily-image-widget");
|
||||||
_e("The widget will appear as empty in your site until data can be downloaded again.", "hubblesite-daily-image-widget");
|
_e("The widget will appear as empty in your site until data can be downloaded again.", "hubblesite-daily-image-widget");
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around a remote data call for unit testing purposes.
|
* Wrapper around a remote data call for unit testing purposes.
|
||||||
* @return string The data from the remote source.
|
* @return string The data from the remote source.
|
||||||
*/
|
*/
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function _get_from_data_source() {
|
function _get_from_data_source() {
|
||||||
$response = wp_remote_request($this->data_source, array('method' => 'GET'));
|
$response = wp_remote_request($this->data_source, array('method' => 'GET'));
|
||||||
if (!is_wp_error($response)) {
|
if (!is_wp_error($response)) {
|
||||||
|
@ -83,6 +88,7 @@ class DailyImageWidget {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the remote data into the object.
|
* Load the remote data into the object.
|
||||||
|
@ -278,9 +284,9 @@ class DailyImageWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
function the_hubblesite_daily_image_widget() {
|
function the_hubblesite_daily_image_widget() {
|
||||||
$diw = new DailyImageWidget();
|
$diw = new DailyImageWidget();
|
||||||
$diw->render();
|
$diw->render();
|
||||||
}
|
}
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
?>
|
|
||||||
|
|
|
@ -256,6 +256,7 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
function providerTestGetCachedData() {
|
function providerTestGetCachedData() {
|
||||||
return array(
|
return array(
|
||||||
array(time() + 86500, true),
|
array(time() + 86500, true),
|
||||||
|
array(time() + 86500, array('test' => 'test'), false),
|
||||||
array(time() - 86500, false),
|
array(time() - 86500, false),
|
||||||
array(null, false)
|
array(null, false)
|
||||||
);
|
);
|
||||||
|
@ -264,14 +265,21 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerTestGetCachedData
|
* @dataProvider providerTestGetCachedData
|
||||||
*/
|
*/
|
||||||
function testGetCachedData($test_time, $has_sample_data) {
|
function testGetCachedData($test_time, $has_sample_data, $expected_return = null) {
|
||||||
if (!is_null($test_time)) {
|
if (!is_null($test_time)) {
|
||||||
update_option('hubblesite-daily-image-cache', array($test_time, $this->sample_data));
|
if ($has_sample_data === true) {
|
||||||
|
$has_sample_data = $this->sample_data;
|
||||||
|
}
|
||||||
|
update_option('hubblesite-daily-image-cache', array($test_time, $has_sample_data));
|
||||||
} else {
|
} else {
|
||||||
update_option('hubblesite-daily-image-cache', null);
|
update_option('hubblesite-daily-image-cache', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals($has_sample_data ? $this->sample_data : false, $this->diw->_get_cached_data());
|
if (is_null($expected_return)) {
|
||||||
|
$expected_return = $has_sample_data ? $has_sample_data : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($expected_return, $this->diw->_get_cached_data());
|
||||||
}
|
}
|
||||||
|
|
||||||
function providerTestLoadData() {
|
function providerTestLoadData() {
|
||||||
|
|
Loading…
Reference in New Issue