diff --git a/.gitignore b/.gitignore index e8c0aa0..f5ce85f 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ application/logs/* application/cache/* application/config/*.php httpdocs/media/.sass-cache/ +httpdocs/.htaccess /vendor \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index ba7adb4..3a7698a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,24 +1,19 @@ language: php - php: - 5.3 - -before_install: - - "git submodule update --init --recursive" - +services: + - mysql before_script: - - "pear channel-discover pear.phing.info" - - "pear install phing/phing" - - "phpenv rehash" - - "composer install" - -script: "phing test" + - composer install --no-interaction --prefer-source # Have to prefer source or hit github rate limit + - git submodule update --init --recursive + - mkdir application/cache application/logs + - chmod 777 application/cache application/logs + # db setup + - mysql -e 'create database pingapp_test;' + - ./minion --task=migrations:run --up + # webserver setup + - php -S localhost:8000 httpdocs/index.php & + - sleep 3 -notifications: - irc: - channels: - - "irc.freenode.org#kohana" - template: - - "%{repository}/%{branch} (%{commit}) - %{author}: %{message}" - - "Build details: %{build_url}" - email: false +script: + - /vendor/bin/phpunit -c application/tests/phpunit.xml \ No newline at end of file diff --git a/README.md b/README.md index f37156b..e3d687f 100644 --- a/README.md +++ b/README.md @@ -98,3 +98,7 @@ The default login credentials are admin / westgate ### Designers Please refer to PING's [Design Guide](https://github.com/ushahidi/pingapp/blob/master/README-DESIGN-GUIDE.md) + +### Tests + +Coming soon... \ No newline at end of file diff --git a/application/classes/Controller/Person.php b/application/classes/Controller/Person.php index d5f1ade..1c28fa4 100644 --- a/application/classes/Controller/Person.php +++ b/application/classes/Controller/Person.php @@ -63,7 +63,7 @@ public function action_edit() { // 1. Save Names $person->values($post, array( - 'first_name', 'last_name', + 'name', )); $person->check($extra_validation); @@ -131,8 +131,7 @@ public function action_edit() if ( $person->loaded() ) { $post = array( - 'first_name' => $person->first_name, - 'last_name' => $person->last_name, + 'name' => $person->name, ); // Get Person Contacts @@ -230,7 +229,7 @@ public function action_ajax_list() $this->auto_render = FALSE; // Data table columns - $columns = array('first_name', 'status', 'pings', 'last_name'); + $columns = array('name', 'status', 'pings', 'last_name'); $pings = DB::select('cp.person_id', array(DB::expr('COUNT(pings.id)'), 'pings')) ->from('pings') @@ -241,7 +240,6 @@ public function action_ajax_list() ->group_by('cp.person_id'); $query = ORM::factory('Person') - ->select(array(DB::expr('CONCAT(person.first_name, " ", person.last_name)'), 'name')) ->select('pings.pings') ->join(array($pings, 'pings'), 'LEFT') ->on('person.id', '=', 'pings.person_id') diff --git a/application/classes/Model/Person.php b/application/classes/Model/Person.php index ecbee30..0a61fb3 100644 --- a/application/classes/Model/Person.php +++ b/application/classes/Model/Person.php @@ -42,15 +42,13 @@ class Model_Person extends ORM { public function rules() { return array( - 'first_name' => array( + 'name' => array( array('not_empty'), array('min_length', array(':value', 2)), - array('max_length', array(':value', 100)), + array('max_length', array(':value', 150)), ), - 'last_name' => array( - array('not_empty'), - array('min_length', array(':value', 2)), - array('max_length', array(':value', 100)), + 'status' => array( + array('in_array', array(':value', array('ok', 'notok', 'unknown')) ), ), ); } diff --git a/application/classes/PingApp/Form.php b/application/classes/PingApp/Form.php index e5d5ac3..9fe98a6 100644 --- a/application/classes/PingApp/Form.php +++ b/application/classes/PingApp/Form.php @@ -49,12 +49,12 @@ public static function people($user) { $people = $user->people ->where('parent_id', '=', 0) - ->order_by('first_name', 'ASC') + ->order_by('name', 'ASC') ->find_all(); foreach ($people as $person) { - $array[$person->id] = $person->first_name.' '.$person->last_name; + $array[$person->id] = $person->name; } } diff --git a/application/migrations/1/20131001090904.php b/application/migrations/1/20131001090904.php new file mode 100644 index 0000000..2e7deed --- /dev/null +++ b/application/migrations/1/20131001090904.php @@ -0,0 +1,75 @@ +query(NULL, "ALTER TABLE `people` ADD `name` VARCHAR(150) NULL DEFAULT NULL AFTER `user_id`;"); + + // Migrate names to new column + $this->_migrate_old(); + + // Drop old columns + $db->query(NULL, "ALTER TABLE `people` DROP `first_name`;"); + $db->query(NULL, "ALTER TABLE `people` DROP `last_name`;"); + } + + /** + * Run queries needed to remove this migration + * + * @param Kohana_Database $db Database connection + */ + public function down(Kohana_Database $db) + { + // Restore first_name and last_name + $db->query(NULL, "ALTER TABLE `people` ADD `first_name` VARCHAR(100) NULL DEFAULT NULL AFTER `user_id`;"); + $db->query(NULL, "ALTER TABLE `people` ADD `last_name` VARCHAR(100) NULL DEFAULT NULL AFTER `first_name`;"); + + // Migrate names back to old columns + $this->_un_migrate_old(); + + // Drop name column + $db->query(NULL, "ALTER TABLE `people` DROP `name`;"); + } + + + /** + * Migrate Old People + * @return void + */ + private function _migrate_old() + { + $people = ORM::factory('Person') + ->find_all(); + + foreach ($people as $person) + { + $person->name = $person->first_name.' '.$person->last_name; + $person->save(); + } + } + + /** + * UnMigrate Old People + * @return void + */ + private function _un_migrate_old() + { + $people = ORM::factory('Person') + ->find_all(); + + foreach ($people as $person) + { + $name = explode(' ', $person->name); + $person->first_name = $name[0]; + $person->last_name = (isset($name[1])) ? $name[1] : ''; + $person->save(); + } + } +} diff --git a/application/tests/classes/models/PersonModelTest.php b/application/tests/classes/models/PersonModelTest.php new file mode 100644 index 0000000..7af4789 --- /dev/null +++ b/application/tests/classes/models/PersonModelTest.php @@ -0,0 +1,118 @@ + + * @package Ushahidi\Application\Tests + * @copyright Ushahidi - http://www.ushahidi.com + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License Version 3 (GPLv3) + */ + +class PersonModelTest extends Unittest_TestCase { + /** + * Provider for test_validate_valid + * + * @access public + * @return array + */ + public function provider_validate_valid() + { + return array( + array( + // Valid person data + array( + 'name' => 'Joe Schmoe', + 'status' => 'ok', + ) + ), + array( + // Valid person data + array( + 'name' => 'Bill Murray', + 'status' => 'notok', + ) + ), + array( + // Valid person data + array( + 'name' => 'Miley Cyrus', + 'status' => 'unknown', + ) + ) + ); + } + + /** + * Provider for test_validate_invalid + * + * @access public + * @return array + */ + public function provider_validate_invalid() + { + return array( + array( + // Invalid person data set 1 - No Data + array() + ), + array( + // Invalid person data set 2 - Missing Name + array( + 'status' => 'ok', + ) + ), + array( + // Invalid person data set 4 - Invalid status + array( + 'name' => 'Batcave Chris', + 'status' => 'not okay', + ) + ) + ); + } + + /** + * Test Validate Valid Entries + * + * @dataProvider provider_validate_valid + * @return void + */ + public function test_validate_valid($set) + { + $person = ORM::factory('Person'); + $person->values($set); + + try + { + $person->check(); + } + catch (ORM_Validation_Exception $e) + { + $this->fail('This entry qualifies as invalid when it should be valid: '. json_encode($e->errors('models'))); + } + } + + /** + * Test Validate Invalid Entries + * + * @dataProvider provider_validate_invalid + * @return void + */ + public function test_validate_invalid($set) + { + $person = ORM::factory('Person'); + $person->values($set); + + try + { + $person->check(); + } + catch (ORM_Validation_Exception $e) + { + return; + } + + $this->fail('This entry qualifies as valid when it should be invalid'); + } +} \ No newline at end of file diff --git a/application/tests/phpunit.xml b/application/tests/phpunit.xml new file mode 100644 index 0000000..259bc96 --- /dev/null +++ b/application/tests/phpunit.xml @@ -0,0 +1,7 @@ + + + + ./ + + + \ No newline at end of file diff --git a/application/views/pages/person/edit.php b/application/views/pages/person/edit.php index 97c1794..fe8a0b2 100644 --- a/application/views/pages/person/edit.php +++ b/application/views/pages/person/edit.php @@ -1,5 +1,5 @@ loaded() ): ?> -

Secondary Contact For: first_name.' '.$parent->last_name; ?>

+

Secondary Contact For: name; ?>

@@ -27,10 +27,7 @@ Name
- "first_name", "placeholder" => "First Name", "required" => "required")); ?> -
-
- "last_name", "placeholder" => "Last Name", "required" => "required")); ?> + "name", "placeholder" => "Full Name", "required" => "required")); ?>
diff --git a/application/views/pages/person/view.php b/application/views/pages/person/view.php index 026e07d..da50c97 100644 --- a/application/views/pages/person/view.php +++ b/application/views/pages/person/view.php @@ -1,4 +1,4 @@ -

first_name.' '.$person->last_name; ?>

+

name; ?>

Edit =1.2", "phing/phing": "dev-master", + "twilio/sdk": "dev-master" - } -} + }, + "config": { + "bin-dir": "bin/" + } +} \ No newline at end of file