start migrating functions into comicpress class
This commit is contained in:
parent
a120fc059f
commit
9fe1ff034e
@ -24,6 +24,29 @@ class ComicPress {
|
|||||||
function init() {
|
function init() {
|
||||||
$this->load();
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -36,6 +36,8 @@ require_once(dirname(__FILE__) . '/options.php');
|
|||||||
add_action('init', '__comicpress_init');
|
add_action('init', '__comicpress_init');
|
||||||
|
|
||||||
function __comicpress_init() {
|
function __comicpress_init() {
|
||||||
|
global $comicpress;
|
||||||
|
|
||||||
foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $file) {
|
foreach (glob(dirname(__FILE__) . '/classes/*.inc') as $file) {
|
||||||
if (is_file($file)) { require_once($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()) {
|
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 "/>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,9 +2,14 @@
|
|||||||
|
|
||||||
require_once('PHPUnit/Framework.php');
|
require_once('PHPUnit/Framework.php');
|
||||||
require_once(dirname(__FILE__) . '/../../mockpress/mockpress.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() {
|
function providerTestGenerateComicTag() {
|
||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
@ -20,13 +25,9 @@ class FunctionsTest extends PHPUnit_Framework_TestCase {
|
|||||||
* @dataProvider providerTestGenerateComicTag
|
* @dataProvider providerTestGenerateComicTag
|
||||||
*/
|
*/
|
||||||
function testGenerateComicImgTag($dimensions) {
|
function testGenerateComicImgTag($dimensions) {
|
||||||
global $comicpress_options_admin;
|
$this->cp->comicpress_options['comic_dimensions'] = $dimensions;
|
||||||
|
|
||||||
$comicpress_options_admin->comicpress_options['comic_dimensions'] = $dimensions;
|
$source = $this->cp->get_comic_img_tag("test.gif", "comic");
|
||||||
|
|
||||||
ob_start();
|
|
||||||
the_comic_img_tag("test.gif", "comic");
|
|
||||||
$source = ob_get_clean();
|
|
||||||
|
|
||||||
if (count($parts = explode("x", $dimensions)) == 2) {
|
if (count($parts = explode("x", $dimensions)) == 2) {
|
||||||
list($width, $height) = $parts;
|
list($width, $height) = $parts;
|
Loading…
Reference in New Issue
Block a user