From cbc6346ba60c9a31f4acacdd99576dc003677845 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 29 Jun 2009 12:50:55 -0400 Subject: [PATCH] refactor test --- test/DailyImageWidgetTest.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test/DailyImageWidgetTest.php b/test/DailyImageWidgetTest.php index 425ff02..bba3ed8 100644 --- a/test/DailyImageWidgetTest.php +++ b/test/DailyImageWidgetTest.php @@ -254,17 +254,25 @@ class DailyImageWidgetTest extends PHPUnit_Framework_TestCase { } } - function testGetCachedData() { - $test_time = time() + 86500; - update_option('hubblesite-daily-image-cache', array($test_time, $this->sample_data)); - $this->assertEquals($this->sample_data, $this->diw->_get_cached_data()); - - $test_time = time() - 86500; - update_option('hubblesite-daily-image-cache', array($test_time, $this->sample_data)); - $this->assertEquals(false, $this->diw->_get_cached_data()); - - update_option('hubblesite-daily-image-cache', null); - $this->assertEquals(false, $this->diw->_get_cached_data()); + function providerTestGetCachedData() { + return array( + array(time() + 86500, true), + array(time() - 86500, false), + array(null, false) + ); + } + + /** + * @dataProvider providerTestGetCachedData + */ + function testGetCachedData($test_time, $has_sample_data) { + if (!is_null($test_time)) { + update_option('hubblesite-daily-image-cache', array($test_time, $this->sample_data)); + } else { + update_option('hubblesite-daily-image-cache', null); + } + + $this->assertEquals($has_sample_data ? $this->sample_data : false, $this->diw->_get_cached_data()); } function providerTestLoadData() {