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