start migrating functions into comicpress class

This commit is contained in:
John Bintz 2009-07-08 19:54:56 -04:00
parent a120fc059f
commit 9fe1ff034e
3 changed files with 35 additions and 29 deletions

View File

@ -24,6 +24,29 @@ class ComicPress {
function init() {
$this->load();
}
function get_comic_img_tag($url, $type, $additional_parameters = array()) {
$dimensions = array();
if (isset($this->comicpress_options["${type}_dimensions"])) {
list($width, $height) = explode("x", $this->comicpress_options["${type}_dimensions"]);
$dimensions = compact('width', 'height');
}
$output = '<img src="' . $url . '" ';
foreach (array('width', 'height') as $field) {
if (!empty($dimensions[$field])) {
$output .= $field . '="' . $dimensions[$field] . '" ';
}
}
if (is_array($additional_parameters)) {
foreach ($additional_parameters as $parameter => $value) {
$output .= $parameter . '="' . $value . '" ';
}
}
$output .= "/>";
return $output;
}
}
?>

View File

@ -36,6 +36,8 @@ require_once(dirname(__FILE__) . '/options.php');
add_action('init', '__comicpress_init');
function __comicpress_init() {
global $comicpress;
foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $file) {
if (is_file($file)) { require_once($file); }
}
@ -81,26 +83,6 @@ function get_last_comic() {
}
function the_comic_img_tag($url, $type, $additional_parameters = array()) {
global $comicpress_options_admin;
$dimensions = array();
if (isset($comicpress_options_admin->comicpress_options["${type}_dimensions"])) {
list($width, $height) = explode("x", $comicpress_options_admin->comicpress_options["${type}_dimensions"]);
$dimensions = compact('width', 'height');
}
echo '<img src="' . $url . '" ';
foreach (array('width', 'height') as $field) {
if (!empty($dimensions[$field])) {
echo $field . '="' . $dimensions[$field] . '" ';
}
}
if (is_array($additional_parameters)) {
foreach ($additional_parameters as $parameter => $value) {
echo $parameter . '="' . $value . '" ';
}
}
echo "/>";
}
/**

View File

@ -2,9 +2,14 @@
require_once('PHPUnit/Framework.php');
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.php');
require_once(dirname(__FILE__) . '/../functions.php');
require_once(dirname(__FILE__) . '/../classes/ComicPress.inc');
class ComicPressTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->cp = new ComicPress();
}
class FunctionsTest extends PHPUnit_Framework_TestCase {
function providerTestGenerateComicTag() {
return array(
array(
@ -20,13 +25,9 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
* @dataProvider providerTestGenerateComicTag
*/
function testGenerateComicImgTag($dimensions) {
global $comicpress_options_admin;
$this->cp->comicpress_options['comic_dimensions'] = $dimensions;
$comicpress_options_admin->comicpress_options['comic_dimensions'] = $dimensions;
ob_start();
the_comic_img_tag("test.gif", "comic");
$source = ob_get_clean();
$source = $this->cp->get_comic_img_tag("test.gif", "comic");
if (count($parts = explode("x", $dimensions)) == 2) {
list($width, $height) = $parts;