Skip to content

Commit 994a3b8

Browse files
author
Emmanuel Kala
committed
* Closes #2343; Undefined variable error when a search is performed on the admin console
* Renamed some of the PHPUnit test cases
1 parent 00f856c commit 994a3b8

File tree

7 files changed

+81
-79
lines changed

7 files changed

+81
-79
lines changed

application/controllers/admin/reports.php

+68-69
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function index($page = 1)
6161
$status = "0";
6262
}
6363
}
64-
64+
6565
// Get Search Keywords (If Any)
6666
if (isset($_GET['k']))
6767
{
@@ -77,7 +77,7 @@ public function index($page = 1)
7777
// in the first 2 steps
7878
$keyword_raw = $this->input->xss_clean($keyword_raw);
7979

80-
$filter .= " AND (".$this->_get_searchstring($keyword_raw).")";
80+
$filter = " AND (".$this->_get_searchstring($keyword_raw).")";
8181
}
8282
else
8383
{
@@ -183,7 +183,8 @@ public function index($page = 1)
183183
$update->incident_verified = '0';
184184
$verify->verified_status = '0';
185185
}
186-
else {
186+
else
187+
{
187188
$update->incident_verified = '1';
188189
$verify->verified_status = '2';
189190
}
@@ -701,8 +702,7 @@ public function edit($id = FALSE, $saved = FALSE)
701702
}
702703

703704
// Combine Everything
704-
$incident_arr = array
705-
(
705+
$incident_arr = array(
706706
'location_id' => $incident->location->id,
707707
'form_id' => $incident->form_id,
708708
'locale' => $incident->locale,
@@ -806,7 +806,7 @@ public function edit($id = FALSE, $saved = FALSE)
806806
/**
807807
* Download Reports in CSV format
808808
*/
809-
function download()
809+
public function download()
810810
{
811811
// If user doesn't have access, redirect to dashboard
812812
if ( ! admin::permissions($this->user, "reports_download"))
@@ -847,17 +847,20 @@ function download()
847847
if (!empty($_POST['from_date']) OR !empty($_POST['to_date']))
848848
{
849849
// Valid FROM Date?
850-
if (empty($_POST['from_date']) OR (strtotime($_POST['from_date']) > strtotime("today"))) {
850+
if (empty($_POST['from_date']) OR (strtotime($_POST['from_date']) > strtotime("today")))
851+
{
851852
$post->add_error('from_date','range');
852853
}
853854

854855
// Valid TO date?
855-
if (empty($_POST['to_date']) OR (strtotime($_POST['to_date']) > strtotime("today"))) {
856+
if (empty($_POST['to_date']) OR (strtotime($_POST['to_date']) > strtotime("today")))
857+
{
856858
$post->add_error('to_date','range');
857859
}
858860

859861
// TO Date not greater than FROM Date?
860-
if (strtotime($_POST['from_date']) > strtotime($_POST['to_date'])) {
862+
if (strtotime($_POST['from_date']) > strtotime($_POST['to_date']))
863+
{
861864
$post->add_error('to_date','range_greater');
862865
}
863866
}
@@ -894,9 +897,10 @@ function download()
894897
$filter .= ") ";
895898

896899
// Report Date Filter
897-
if (!empty($post->from_date) AND !empty($post->to_date))
900+
if ( ! empty($post->from_date) AND !empty($post->to_date))
898901
{
899-
$filter .= " AND ( incident_date >= '" . date("Y-m-d H:i:s",strtotime($post->from_date)) . "' AND incident_date <= '" . date("Y-m-d H:i:s",strtotime($post->to_date)) . "' ) ";
902+
$filter .= " AND ( incident_date >= '" . date("Y-m-d H:i:s",strtotime($post->from_date))
903+
. "' AND incident_date <= '" . date("Y-m-d H:i:s",strtotime($post->to_date)) . "' ) ";
900904
}
901905

902906
// Retrieve reports
@@ -1121,7 +1125,7 @@ public function upload()
11211125
* @param bool|string $saved
11221126
*/
11231127

1124-
function translate( $id = false, $saved = false )
1128+
public function translate( $id = false, $saved = FALSE)
11251129
{
11261130
$this->template->content = new View('admin/reports_translate');
11271131
$this->template->content->title = Kohana::lang('ui_admin.translate_reports');
@@ -1152,23 +1156,17 @@ function translate( $id = false, $saved = false )
11521156

11531157

11541158
// Setup and initialize form field names
1155-
$form = array
1156-
(
1159+
$form = array(
11571160
'locale' => '',
11581161
'incident_title' => '',
11591162
'incident_description' => ''
11601163
);
1164+
11611165
// Copy the form as errors, so the errors will be stored with keys corresponding to the form field names
11621166
$errors = $form;
11631167
$form_error = FALSE;
1164-
if ($saved == 'saved')
1165-
{
1166-
$form_saved = TRUE;
1167-
}
1168-
else
1169-
{
1170-
$form_saved = FALSE;
1171-
}
1168+
1169+
$form_saved = ($saved == 'saved')? TRUE : FALSE;
11721170

11731171
// Locale (Language) Array
11741172
$this->template->content->locale_array = Kohana::config('locale.all_languages');
@@ -1233,7 +1231,7 @@ function translate( $id = false, $saved = false )
12331231
}
12341232
else
12351233
{
1236-
if ( $id )
1234+
if ($id)
12371235
{
12381236
// Retrieve Current Incident
12391237
$incident_l = ORM::factory('incident_lang', $id)->where('incident_id', $incident_id)->find();
@@ -1267,7 +1265,7 @@ function translate( $id = false, $saved = false )
12671265
/**
12681266
* Save newly added dynamic categories
12691267
*/
1270-
function save_category()
1268+
public function save_category()
12711269
{
12721270
$this->auto_render = FALSE;
12731271
$this->template = "";
@@ -1300,7 +1298,6 @@ function save_category()
13001298

13011299
echo json_encode(array("status"=>"saved", "id"=>$category->id));
13021300
}
1303-
13041301
else
13051302

13061303
{
@@ -1317,36 +1314,42 @@ function save_category()
13171314
* Delete Photo
13181315
* @param int $id The unique id of the photo to be deleted
13191316
*/
1320-
function deletePhoto ( $id )
1317+
public function deletePhoto ($id)
13211318
{
13221319
$this->auto_render = FALSE;
13231320
$this->template = "";
13241321

1325-
if ( $id )
1322+
if ($id)
13261323
{
13271324
$photo = ORM::factory('media', $id);
13281325
$photo_large = $photo->media_link;
13291326
$photo_medium = $photo->media_medium;
13301327
$photo_thumb = $photo->media_thumb;
13311328

1332-
if(file_exists(Kohana::config('upload.directory', TRUE).$photo_large))
1329+
if (file_exists(Kohana::config('upload.directory', TRUE).$photo_large))
13331330
{
13341331
unlink(Kohana::config('upload.directory', TRUE).$photo_large);
1335-
}elseif(Kohana::config("cdn.cdn_store_dynamic_content") AND valid::url($photo_large)){
1332+
}
1333+
elseif (Kohana::config("cdn.cdn_store_dynamic_content") AND valid::url($photo_large))
1334+
{
13361335
cdn::delete($photo_large);
13371336
}
13381337

1339-
if(file_exists(Kohana::config('upload.directory', TRUE).$photo_medium))
1338+
if (file_exists(Kohana::config('upload.directory', TRUE).$photo_medium))
13401339
{
13411340
unlink(Kohana::config('upload.directory', TRUE).$photo_medium);
1342-
}elseif(Kohana::config("cdn.cdn_store_dynamic_content") AND valid::url($photo_medium)){
1341+
}
1342+
elseif (Kohana::config("cdn.cdn_store_dynamic_content") AND valid::url($photo_medium))
1343+
{
13431344
cdn::delete($photo_medium);
13441345
}
13451346

1346-
if(file_exists(Kohana::config('upload.directory', TRUE).$photo_thumb))
1347+
if (file_exists(Kohana::config('upload.directory', TRUE).$photo_thumb))
13471348
{
13481349
unlink(Kohana::config('upload.directory', TRUE).$photo_thumb);
1349-
}elseif(Kohana::config("cdn.cdn_store_dynamic_content") AND valid::url($photo_thumb)){
1350+
}
1351+
elseif (Kohana::config("cdn.cdn_store_dynamic_content") AND valid::url($photo_thumb))
1352+
{
13501353
cdn::delete($photo_thumb);
13511354
}
13521355

@@ -1360,8 +1363,7 @@ function deletePhoto ( $id )
13601363
// Dynamic categories form fields
13611364
private function _new_categories_form_arr()
13621365
{
1363-
return array
1364-
(
1366+
return array(
13651367
'category_name' => '',
13661368
'category_description' => '',
13671369
'category_color' => '',
@@ -1406,26 +1408,26 @@ private function _stroke_width_array()
14061408
}
14071409

14081410
// Javascript functions
1409-
private function _color_picker_js()
1411+
private function _color_picker_js()
14101412
{
1411-
return "<script type=\"text/javascript\">
1412-
$(document).ready(function() {
1413-
$('#category_color').ColorPicker({
1414-
onSubmit: function(hsb, hex, rgb) {
1415-
$('#category_color').val(hex);
1416-
},
1417-
onChange: function(hsb, hex, rgb) {
1418-
$('#category_color').val(hex);
1419-
},
1420-
onBeforeShow: function () {
1421-
$(this).ColorPickerSetColor(this.value);
1422-
}
1423-
})
1424-
.bind('keyup', function(){
1425-
$(this).ColorPickerSetColor(this.value);
1426-
});
1427-
});
1428-
</script>";
1413+
return "<script type=\"text/javascript\">
1414+
$(document).ready(function() {
1415+
$('#category_color').ColorPicker({
1416+
onSubmit: function(hsb, hex, rgb) {
1417+
$('#category_color').val(hex);
1418+
},
1419+
onChange: function(hsb, hex, rgb) {
1420+
$('#category_color').val(hex);
1421+
},
1422+
onBeforeShow: function () {
1423+
$(this).ColorPickerSetColor(this.value);
1424+
}
1425+
})
1426+
.bind('keyup', function(){
1427+
$(this).ColorPickerSetColor(this.value);
1428+
});
1429+
});
1430+
</script>";
14291431
}
14301432

14311433
private function _date_picker_js()
@@ -1502,33 +1504,30 @@ private function _get_searchstring($keyword_raw)
15021504

15031505
$keywords = explode(' ', $keyword_raw);
15041506

1505-
if (is_array($keywords) && !empty($keywords))
1507+
if (is_array($keywords) AND !empty($keywords))
15061508
{
15071509
array_change_key_case($keywords, CASE_LOWER);
15081510
$i = 0;
15091511

1510-
foreach($keywords as $value)
1512+
foreach ($keywords as $value)
15111513
{
1512-
if (!in_array($value,$stop_words) && !empty($value))
1514+
if (!in_array($value,$stop_words) AND !empty($value))
15131515
{
1514-
$chunk = mysql_real_escape_string($value);
1515-
if ($i > 0) {
1516+
$chunk = $this->db->escape_str($value);
1517+
if ($i > 0)
1518+
{
15161519
$or = ' OR ';
15171520
}
1518-
$where_string = $where_string.$or."incident_title LIKE '%$chunk%' OR incident_description LIKE '%$chunk%' OR location_name LIKE '%$chunk%'";
1521+
$where_string = $where_string
1522+
.$or
1523+
."incident_title LIKE '%$chunk%' OR incident_description LIKE '%$chunk%' OR location_name LIKE '%$chunk%'";
15191524
$i++;
15201525
}
15211526
}
15221527
}
1523-
1524-
if ($where_string)
1525-
{
1526-
return $where_string;
1527-
}
1528-
else
1529-
{
1530-
return "1=1";
1531-
}
1528+
1529+
// Return
1530+
return (!empty($where_string)) ? $where_string : "1=1";
15321531
}
15331532

15341533
private function _csv_text($text)

application/controllers/main.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ public function __construct()
9696
$site_name = Kohana::config('settings.site_name');
9797

9898
// Get banner image and pass to the header
99-
if(Kohana::config('settings.site_banner_id') != NULL){
99+
if (Kohana::config('settings.site_banner_id') != NULL)
100+
{
100101
$banner = ORM::factory('media')->find(Kohana::config('settings.site_banner_id'));
101102
$this->template->header->banner = url::convert_uploaded_to_abs($banner->media_link);
102-
}else{
103+
}
104+
else
105+
{
103106
$this->template->header->banner = NULL;
104107
}
105108

@@ -149,7 +152,7 @@ public function __construct()
149152
// add copyright info
150153
$this->template->footer->site_copyright_statement = '';
151154
$site_copyright_statement = trim(Kohana::config('settings.site_copyright_statement'));
152-
if($site_copyright_statement != '')
155+
if ($site_copyright_statement != '')
153156
{
154157
$this->template->footer->site_copyright_statement = $site_copyright_statement;
155158
}

tests/phpunit/classes/models/Alert_Model_Test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php defined('SYSPATH') or die('No direct script access allowed.');
22
/**
3-
* Unit test for the alerts model
3+
* Alert_Model Unit test
44
*
55
* PHP version 5
66
* LICENSE: This source file is subject to LGPL license

tests/phpunit/classes/models/Country_Model_Test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php defined('SYSPATH') or die('No direct script access.');
22
/**
3-
* Country Model Unit Test
3+
* Country_Model Test
44
*
55
* @package Ushahidi
66
* @category Unit Tests
77
* @author Ushahidi Team
88
* @copyright (c) Ushahidi Inc 2008-2011
99
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
1010
*/
11-
class Country_Model_Test extends PHPUnit_Framework_TestCase {
11+
class Country_ModelTest extends PHPUnit_Framework_TestCase {
1212

1313
/**
1414
* Tests CountyModel::get_country_by_name

tests/phpunit/classes/models/User_Model_Test.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* @copyright (c) 2008-2011 Ushahidi Inc <http://www.ushahidi.com>
99
* @license For license information, see License.txt
1010
*/
11-
class Unit_Model_Test extends PHPUnit_Framework_TestCase {
11+
class User_Model_Test extends PHPUnit_Framework_TestCase {
1212

1313
/**
1414
* Provides dummy data for testing User_Model::custom_validate
1515
* @dataProvider
1616
*/
17-
public function providerCustomValidate()
17+
public function provider_custom_validate()
1818
{
1919
return array(array(
2020
array(
@@ -42,9 +42,9 @@ public function providerCustomValidate()
4242
* Tests User_Model::custom_validate
4343
*
4444
* @test
45-
* @dataProvider providerCustomValidate
45+
* @dataProvider provider_custom_validate
4646
*/
47-
public function testCustomValidate($valid, $invalid)
47+
public function test_custom_validate($valid, $invalid)
4848
{
4949
// Test with valid data
5050
$response = User_Model::custom_validate($valid);

0 commit comments

Comments
 (0)