Skip to content

Commit

Permalink
Refactor: getEditArray() + unittests
Browse files Browse the repository at this point in the history
Finished refactor of getEditArray, that was partly refactored but not
consistent across classes.
Made sure unittests work again after refactor
  • Loading branch information
jeroenrnl committed Jan 1, 2013
1 parent 3acba05 commit 6d83a9b
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions php/UnitTests/importTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions php/UnitTests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</filter>
<php>
<var name="INSTANCE" value="zophtest" />
<var name="IMAGE_DIR" value="/data/images" />
</php>
<testsuites>
<testsuite name="Zoph">
Expand Down
2 changes: 2 additions & 0 deletions php/UnitTests/testSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
?>
3 changes: 2 additions & 1 deletion php/album.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion php/album.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion php/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion php/classes/language.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion php/classes/zophTable.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions php/config.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 8 additions & 13 deletions php/include.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion php/photo.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions php/saved_search.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"))));
Expand Down
2 changes: 1 addition & 1 deletion php/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)?>">
Expand Down

0 comments on commit 6d83a9b

Please sign in to comment.