From 1e3f1f0ab04552dcebd1c3cfeb896e3653be33d5 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 1 Feb 2010 22:41:56 -0500 Subject: [PATCH] code coverage --- .../backends/ComicPressBackendFilesystem.inc | 4 +- .../ComicPressBackendFilesystemTest.php | 37 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/classes/backends/ComicPressBackendFilesystem.inc b/classes/backends/ComicPressBackendFilesystem.inc index 720286f..abd632f 100644 --- a/classes/backends/ComicPressBackendFilesystem.inc +++ b/classes/backends/ComicPressBackendFilesystem.inc @@ -12,10 +12,12 @@ class ComicPressBackendFilesystem extends ComicPressBackend { $this->source_name = __('Filesystem', 'comicpress'); } + function _getimagesize($file) { return getimagesize($file); } + function dims($size = null) { $dims = array(); - if ($result = getimagesize($this->files_by_type[$this->ensure_type($size)])) { + if ($result = $this->_getimagesize($this->files_by_type[$this->ensure_type($size)])) { $dims = array_combine(array('width', 'height'), array_slice($result, 0, 2)); } diff --git a/test/backends/ComicPressBackendFilesystemTest.php b/test/backends/ComicPressBackendFilesystemTest.php index 2aee51b..17c1eaf 100644 --- a/test/backends/ComicPressBackendFilesystemTest.php +++ b/test/backends/ComicPressBackendFilesystemTest.php @@ -15,5 +15,40 @@ class ComicPressBackendFilesystemTest extends PHPUnit_Framework_TestCase { vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); } - function testSomething() {} + function providerTestDims() { + return array( + array(false, array()), + array( + array( + 200, 100, 300 + ), + array( + 'width' => 200, + 'height' => 100 + ) + ) + ); + } + + /** + * @dataProvider providerTestDims + */ + function testDims($getimagesize_return, $expected_result) { + $fs = $this->getMock('ComicPressBackendFilesystem', array('_getimagesize', 'ensure_type')); + $fs->expects($this->once())->method('ensure_type')->with('type')->will($this->returnValue('newtype')); + $fs->expects($this->once())->method('_getimagesize')->with('file')->will($this->returnValue($getimagesize_return)); + + $fs->files_by_type = array('newtype' => 'file'); + + $this->assertEquals($expected_result, $fs->dims('type')); + } + + function testUrl() { + $fs = $this->getMock('ComicPressBackendFilesystem', array('ensure_type')); + $fs->expects($this->once())->method('ensure_type')->with('type')->will($this->returnValue('newtype')); + + $fs->file_urls_by_type = array('newtype' => 'url'); + + $this->assertEquals('url', $fs->url('type')); + } }