Permalink
Browse files

Refactor: getEditArray() + unittests

Finished refactor of getEditArray, that was partly refactored but not
consistent across classes.
Made sure unittests work again after refactor
  • Loading branch information...
1 parent 3acba05 commit 6d83a9bb3c01154daec870334420ffe5cf97a6c6 @jeroenrnl committed Jan 1, 2013
@@ -53,6 +53,7 @@ private static function createTestImage($name, $bg, $fg) {
*/
public function testImportImages($id, $name, $bg, $fg) {
+ user::setCurrent(new user(1));
if(file_exists(conf::get("path.images") . "/" . $name)) {
unlink(conf::get("path.images") . "/" . $name);
}
@@ -11,6 +11,7 @@
</filter>
<php>
<var name="INSTANCE" value="zophtest" />
+ <var name="IMAGE_DIR" value="/data/images" />
</php>
<testsuites>
<testsuite name="Zoph">
@@ -57,4 +57,6 @@
require_once("PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php");
require_once("databaseTest.inc.php");
+user::setCurrent(new user(1));
+conf::set("path.images", IMAGE_DIR);
?>
View
@@ -264,7 +264,8 @@ function getTotalPhotoCount($user = null) {
return album::getCountFromQuery($sql);
}
- public function getEditArray(user $user = null) {
+ public function getEditArray() {
+ $user=user::getCurrent();
if($this->is_root()) {
$parent=array (
translate("parent album"),
View
@@ -78,7 +78,7 @@
<form action="album.php">
<input type="hidden" name="_action" value="<?php echo $action ?>">
<input type="hidden" name="album_id" value="<?php echo $album->get("album_id") ?>">
- <?php echo create_edit_fields($album->getEditArray($user)) ?>
+ <?php echo create_edit_fields($album->getEditArray()) ?>
<input type="submit" value="<?php echo translate($action, 0) ?>">
</form>
View
@@ -78,7 +78,7 @@
<form action="category.php">
<input type="hidden" name="_action" value="<?php echo $action ?>">
<input type="hidden" name="category_id" value="<?php echo $category->get("category_id") ?>">
- <?php echo create_edit_fields($category->getEditArray($user)) ?>
+ <?php echo create_edit_fields($category->getEditArray()) ?>
<input type="submit" value="<?php echo translate($action, 0) ?>">
</form>
<?php
@@ -282,7 +282,7 @@ public static function httpAccept() {
*/
function translate($str, $error=true){
global $lang;
- if(get_class($lang)=="language") {
+ if($lang instanceof language) {
return $lang->translate($str, $error);
} else {
return $str;
@@ -362,7 +362,7 @@ public function getDisplayArray() {
* @param user Unused, but some of the decendant classes do.
* @return array of field names and HTML text input fields
*/
- public function getEditArray(user $user=null) {
+ public function getEditArray() {
if (!$this->fields) { return; }
$field_lengths = get_field_lengths($this->table_name);
View
@@ -29,8 +29,11 @@
// DB_HOST, DB_NAME, DB_USER, DB_PASS and DB_PREFIX have been moved to
// zoph.ini. The location can be set by the next config item:
-
- define('INI_FILE', "/etc/zoph.ini");
+
+ // INI FILE is already defined when using CLI and when running UnitTests
+ if(!defined("INI_FILE")) {
+ define('INI_FILE', "/etc/zoph.ini");
+ }
define('THUMB_SIZE', 120);
define('MID_SIZE', 480);
View
@@ -20,20 +20,15 @@
* @todo return false should change into an exception
*/
- function zophAutoload($class) {
- $file="classes/" . $class . ".inc.php";
- if(file_exists($file)) {
- require_once($file);
- } else {
- $file="interfaces/" . $class . ".inc.php";
- if(file_exists($file)) {
- require_once($file);
- } else {
- return false;
- }
- }
+ function zophAutoloadClass($class) {
+ @include_once("classes/" . $class . ".inc.php");
+ }
+
+ function zophAutoloadInterface($interface) {
+ @include_once("interfaces/" . $interface . ".inc.php");
}
- spl_autoload_register("zophAutoload");
+ spl_autoload_register("zophAutoloadClass");
+ spl_autoload_register("zophAutoloadInterface");
require_once("exception.inc.php");
require_once("variables.inc.php");
View
@@ -971,7 +971,7 @@ function get_camera_display_array() {
translate("comment") => $this->get("comment"));
}
- public function getEditArray(user $user = null) {
+ public function getEditArray() {
return array(
"Title" => create_text_input("title", $this->title),
"Date" => create_text_input("date", $this->date_taken),
View
@@ -50,15 +50,16 @@ function getPhotoCount($user = null) {
// This should be created some time, but might slow down too much
}
- public function getEditArray(user $user = null) {
+ public function getEditArray() {
+ $user=user::getCurrent();
$edit_array=array();
$edit_array[]=array(
translate("Name"),
create_text_input("name", $this->get("name"),40,64));
- if($user instanceof user && $user->is_admin()) {
+ if($user->is_admin()) {
$edit_array[]=array (
translate("Owner"),
create_pulldown("owner", $this->get("owner"), template::createSelectArray(user::getRecords("user", "user_name"), array("user_name"))));
View
@@ -70,7 +70,7 @@
<form>
<input type="hidden" name="search_id" value="<?php echo $search->get("search_id") ?>">
- <?php echo create_edit_fields($search->getEditArray($user)) ?>
+ <?php echo create_edit_fields($search->getEditArray()) ?>
<input type="hidden" name="search" value="<?php echo $url ?>">
<input type="hidden" name="_action" value="<?php echo $action?>">
<input type="submit" name="_button" value="<?php echo translate($action,0)?>">

0 comments on commit 6d83a9b

Please sign in to comment.