diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc
index 30bddf6..20af209 100644
--- a/classes/ComicPress.inc
+++ b/classes/ComicPress.inc
@@ -237,8 +237,10 @@ class ComicPress {
if (isset($this->comicpress_options['image_types'])) {
if (is_array($this->comicpress_options['image_types'])) {
foreach ($this->comicpress_options['image_types'] as $type => $properties) {
- if ($properties['default'] === true) {
- return $type;
+ if (isset($properties['default'])) {
+ if ($properties['default'] === true) {
+ return $type;
+ }
}
}
}
diff --git a/classes/ComicPressBackend.inc b/classes/ComicPressBackend.inc
index 3e7658a..9adc790 100644
--- a/classes/ComicPressBackend.inc
+++ b/classes/ComicPressBackend.inc
@@ -2,6 +2,7 @@
class ComicPressBackend {
function _embed_image($size) {
+ $size = $this->ensure_type($size);
$extras = array();
$dims = $this->dims($size);
if (!empty($dims)) {
@@ -17,7 +18,7 @@ class ComicPressBackend {
unset($extras[$field]);
}
- $output = sprintf('', $this->url(), $this->alt(), $this->title(), implode("", $extras));
+ $output = sprintf('', $this->url($size), $this->alt(), $this->title(), implode("", $extras));
return apply_filters('comicpress_embed_image', $output, $this);
}
@@ -31,4 +32,32 @@ class ComicPressBackend {
}
return false;
}
+
+ function ensure_type($type) {
+ if (is_null($type)) {
+ $comicpress = ComicPress::get_instance();
+ if (is_null($type)) {
+ $type = $comicpress->get_default_image_type();
+ }
+ }
+ return $type;
+ }
+
+ function embed($type = null) { return $this->_embed_image($this->ensure_type($type)); }
+
+
+ function get_info($size = null) {
+ $size = $this->ensure_type($size);
+
+ $info = array();
+ foreach (array('dims', 'url', 'file') as $field) {
+ $result = $this->{$field}($size);
+ if (is_array($result)) {
+ $info = array_merge($info, $result);
+ } else {
+ $info[$field] = $result;
+ }
+ }
+ return $info;
+ }
}
diff --git a/classes/backends/ComicPressBackendAttachment.inc b/classes/backends/ComicPressBackendAttachment.inc
index 88c246e..3fe52db 100644
--- a/classes/backends/ComicPressBackendAttachment.inc
+++ b/classes/backends/ComicPressBackendAttachment.inc
@@ -12,17 +12,12 @@ class ComicPressBackendAttachment extends ComicPressBackend {
$this->type = get_post_meta($this->attachment->ID, 'comic_image_type', true);
}
- function dims($size = 'comic') {
+ function dims($size = null) {
+ $size = $this->ensure_type($size);
$comicpress = ComicPress::get_instance();
$dims = array();
if (isset($comicpress->comicpress_options['image_types'])) {
- if ($size == 'default') {
- foreach ($comicpress->comicpress_options['image_types'] as $type => $info) {
- if ($info['default']) { $size = $type; break; }
- }
- }
-
if (isset($comicpress->comicpress_options['image_types'][$size])) {
if (isset($comicpress->comicpress_options['image_types'][$size]['dimensions'])) {
$dims = array_combine(array('width', 'height'), explode("x", $comicpress->comicpress_options['image_types'][$size]['dimensions']));
@@ -44,24 +39,10 @@ class ComicPressBackendAttachment extends ComicPressBackend {
}
// @codeCoverageIgnoreStart
- function embed($size = 'comic') { return $this->_embed_image($size); }
- function file($size = 'comic') { return $this->attachment->guid; }
+ function file($size = null) { return $this->attachment->guid; }
function alt() { return $this->attachment->post_title; }
function title() { return $this->attachment->post_excerpt; }
// @codeCoverageIgnoreEnd
-
- function get_info($size = 'comic') {
- $info = array();
- foreach (array('dims', 'url', 'file') as $field) {
- $result = $this->{$field}($size);
- if (is_array($result)) {
- $info = array_merge($info, $result);
- } else {
- $info[$field] = $result;
- }
- }
- return $info;
- }
}
class ComicPressBackendAttachmentFactory {
diff --git a/classes/backends/ComicPressBackendURL.inc b/classes/backends/ComicPressBackendURL.inc
index de0679a..2e026ac 100644
--- a/classes/backends/ComicPressBackendURL.inc
+++ b/classes/backends/ComicPressBackendURL.inc
@@ -49,6 +49,8 @@ class ComicPressBackendURL extends ComicPressBackend {
return false;
}
+
+ function dims($size = null) { return false; }
}
class ComicPressBackendURLFactory {
diff --git a/classes/backends/partials/backend-url/_editor.inc b/classes/backends/partials/backend-url/_editor.inc
index dd5b74f..da39bbf 100644
--- a/classes/backends/partials/backend-url/_editor.inc
+++ b/classes/backends/partials/backend-url/_editor.inc
@@ -1,8 +1,8 @@
-
+
- X
+ X
|
Add a new image
diff --git a/test/ComicPressBackendTest.php b/test/ComicPressBackendTest.php
index fc504fc..7bf6296 100644
--- a/test/ComicPressBackendTest.php
+++ b/test/ComicPressBackendTest.php
@@ -36,7 +36,7 @@ class ComicPressBackendTest extends PHPUnit_Framework_TestCase {
$backend = $this->getMock('ComicPressBackend', array('dims', 'url', 'alt', 'title'));
$backend->expects($this->once())->method('dims')->with('comic')->will($this->returnValue($dims_result));
- $backend->expects($this->once())->method('url')->will($this->returnValue('http://comic'));
+ $backend->expects($this->once())->method('url')->with('comic')->will($this->returnValue('http://comic'));
$backend->expects($this->once())->method('alt')->will($this->returnValue('alt'));
$backend->expects($this->once())->method('title')->will($this->returnValue('title'));
@@ -67,4 +67,51 @@ class ComicPressBackendTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected_result, ComicPressBackend::generate_from_id($id));
}
+
+ function providerTestEnsureType() {
+ return array(
+ array(null, 'comic'),
+ array('comic', 'comic'),
+ array('rss', 'rss')
+ );
+ }
+
+ /**
+ * @dataProvider providerTestEnsureType
+ */
+ function testEnsureType($provided, $expected) {
+ $comicpress = ComicPress::get_instance();
+ $comicpress->comicpress_options = array(
+ 'image_types' => array(
+ 'comic' => array('default' => true),
+ 'rss' => array('default' => false)
+ )
+ );
+
+ $this->assertEquals($expected, ComicPressBackend::ensure_type($provided));
+ }
+
+ function testGetEmbed() {
+ $ba = $this->getMock('ComicPressBackend', array('_embed_image', 'ensure_type'));
+ $ba->expects($this->once())->method('ensure_type')->with('test')->will($this->returnValue('ensured'));
+ $ba->expects($this->once())->method('_embed_image')->with('ensured')->will($this->returnValue('embed'));
+
+ $this->assertEquals('embed', $ba->embed('test'));
+ }
+
+
+ function testGetInfo() {
+ $ba = $this->getMock('ComicPressBackend', array('dims', 'url', 'file'), array(), 'Mock_ComicPressBackend', false);
+
+ $ba->expects($this->once())->method('dims')->will($this->returnValue(array('width' => 320, 'height' => 240)));
+ $ba->expects($this->once())->method('url')->will($this->returnValue('http://blah/file.jpg'));
+ $ba->expects($this->once())->method('file')->will($this->returnValue('/root/file.jpg'));
+
+ $this->assertEquals(array(
+ 'width' => 320,
+ 'height' => 240,
+ 'url' => 'http://blah/file.jpg',
+ 'file' => '/root/file.jpg'
+ ), $ba->get_info());
+ }
}
\ No newline at end of file
diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php
index 3b7c8ff..c0a5e26 100644
--- a/test/ComicPressTest.php
+++ b/test/ComicPressTest.php
@@ -301,6 +301,13 @@ class ComicPressTest extends PHPUnit_Framework_TestCase {
),
'comic'
),
+ array(
+ array(
+ 'rss' => array(),
+ 'comic' => array('default' => true),
+ ),
+ 'comic'
+ ),
);
}
diff --git a/test/backends/ComicPressBackendAttachmentTest.php b/test/backends/ComicPressBackendAttachmentTest.php
index 309da37..7f0a3ff 100644
--- a/test/backends/ComicPressBackendAttachmentTest.php
+++ b/test/backends/ComicPressBackendAttachmentTest.php
@@ -17,7 +17,7 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
array('comic', true, array()),
array('comic', array(), array()),
array('comic', array('dimensions' => '300x200'), array('width' => 300, 'height' => 200)),
- array('default', array('dimensions' => '300x200', 'default' => true), array('width' => 300, 'height' => 200))
+ array(null, array('default' => true, 'dimensions' => '300x200'), array('width' => 300, 'height' => 200)),
);
}
@@ -40,30 +40,16 @@ class ComicPressBackendAttachmentTest extends PHPUnit_Framework_TestCase {
array(false, false),
array(true, false),
array(array(), false),
- array(array('url', 300, 200, false), 'url')
- );
+ array(array('url', 300, 200, false), 'url'),
+ array(array('url', 300, 200, false), 'url', null),
+ );
}
/**
* @dataProvider providerTestUrl
*/
- function testUrl($image_downsize_result, $expected_result) {
- _set_image_downsize_result(1, 'comic', $image_downsize_result);
+ function testUrl($image_downsize_result, $expected_result, $which = 'comic') {
+ _set_image_downsize_result(1, 'comic', $image_downsize_result);
$this->assertEquals($expected_result, $this->ba->url('comic'));
}
-
- function testGetInfo() {
- $ba = $this->getMock('ComicPressBackendAttachment', array('dims', 'url', 'file'), array(), 'Mock_ComicPressBackendAttachment', false);
-
- $ba->expects($this->once())->method('dims')->will($this->returnValue(array('width' => 320, 'height' => 240)));
- $ba->expects($this->once())->method('url')->will($this->returnValue('http://blah/file.jpg'));
- $ba->expects($this->once())->method('file')->will($this->returnValue('/root/file.jpg'));
-
- $this->assertEquals(array(
- 'width' => 320,
- 'height' => 240,
- 'url' => 'http://blah/file.jpg',
- 'file' => '/root/file.jpg'
- ), $ba->get_info());
- }
}