diff --git a/app/Console/Commands/Inspire.php b/app/Console/Commands/Inspire.php deleted file mode 100644 index abb255d..0000000 --- a/app/Console/Commands/Inspire.php +++ /dev/null @@ -1,34 +0,0 @@ -comment(PHP_EOL.Inspiring::quote().PHP_EOL); - } - -} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php deleted file mode 100644 index 0c088c8..0000000 --- a/app/Console/Kernel.php +++ /dev/null @@ -1,29 +0,0 @@ -command('inspire') - ->hourly(); - } - -} diff --git a/app/Events/Event.php b/app/Events/Event.php deleted file mode 100644 index d59f769..0000000 --- a/app/Events/Event.php +++ /dev/null @@ -1,7 +0,0 @@ -auth = $auth; - $this->registrar = $registrar; - - $this->middleware('guest', ['except' => 'getLogout']); - } - -} diff --git a/app/Http/Controllers/Auth/PasswordController.php b/app/Http/Controllers/Auth/PasswordController.php deleted file mode 100644 index 3106193..0000000 --- a/app/Http/Controllers/Auth/PasswordController.php +++ /dev/null @@ -1,38 +0,0 @@ -auth = $auth; - $this->passwords = $passwords; - - $this->middleware('guest'); - } - -} diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php deleted file mode 100644 index 27b3f45..0000000 --- a/app/Http/Controllers/Controller.php +++ /dev/null @@ -1,11 +0,0 @@ -middleware('auth'); - } - - /** - * Show the application dashboard to the user. - * - * @return Response - */ - public function index() - { - return view('home'); - } - -} diff --git a/app/Http/Controllers/WelcomeController.php b/app/Http/Controllers/WelcomeController.php deleted file mode 100644 index 8a5ac6d..0000000 --- a/app/Http/Controllers/WelcomeController.php +++ /dev/null @@ -1,36 +0,0 @@ -middleware('guest'); - } - - /** - * Show the application welcome screen to the user. - * - * @return Response - */ - public function index() - { - return view('welcome'); - } - -} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php deleted file mode 100644 index 0a2addc..0000000 --- a/app/Http/Kernel.php +++ /dev/null @@ -1,32 +0,0 @@ - 'App\Http\Middleware\Authenticate', - 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', - 'guest' => 'App\Http\Middleware\RedirectIfAuthenticated', - ]; - -} diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php deleted file mode 100644 index 72a7613..0000000 --- a/app/Http/Middleware/Authenticate.php +++ /dev/null @@ -1,50 +0,0 @@ -auth = $auth; - } - - /** - * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed - */ - public function handle($request, Closure $next) - { - if ($this->auth->guest()) - { - if ($request->ajax()) - { - return response('Unauthorized.', 401); - } - else - { - return redirect()->guest('auth/login'); - } - } - - return $next($request); - } - -} diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php deleted file mode 100644 index dd5a867..0000000 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ /dev/null @@ -1,44 +0,0 @@ -auth = $auth; - } - - /** - * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed - */ - public function handle($request, Closure $next) - { - if ($this->auth->check()) - { - return new RedirectResponse(url('/home')); - } - - return $next($request); - } - -} diff --git a/app/Http/Middleware/VerifyCsrfToken.php b/app/Http/Middleware/VerifyCsrfToken.php deleted file mode 100644 index 750a39b..0000000 --- a/app/Http/Middleware/VerifyCsrfToken.php +++ /dev/null @@ -1,20 +0,0 @@ - 'Auth\AuthController', - 'password' => 'Auth\PasswordController', -]); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php deleted file mode 100644 index ff9d6f6..0000000 --- a/app/Providers/AppServiceProvider.php +++ /dev/null @@ -1,34 +0,0 @@ -app->bind( - 'Illuminate\Contracts\Auth\Registrar', - 'App\Services\Registrar' - ); - } - -} diff --git a/app/Providers/BusServiceProvider.php b/app/Providers/BusServiceProvider.php deleted file mode 100644 index f0d9be6..0000000 --- a/app/Providers/BusServiceProvider.php +++ /dev/null @@ -1,34 +0,0 @@ -mapUsing(function($command) - { - return Dispatcher::simpleMapping( - $command, 'App\Commands', 'App\Handlers\Commands' - ); - }); - } - - /** - * Register any application services. - * - * @return void - */ - public function register() - { - // - } - -} diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.php deleted file mode 100644 index 06e5799..0000000 --- a/app/Providers/ConfigServiceProvider.php +++ /dev/null @@ -1,23 +0,0 @@ - [ - 'EventListener', - ], - ]; - - /** - * Register any other events for your application. - * - * @param \Illuminate\Contracts\Events\Dispatcher $events - * @return void - */ - public function boot(DispatcherContract $events) - { - parent::boot($events); - - // - } - -} diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php deleted file mode 100644 index afa34c8..0000000 --- a/app/Providers/RouteServiceProvider.php +++ /dev/null @@ -1,44 +0,0 @@ -group(['namespace' => $this->namespace], function($router) - { - require app_path('Http/routes.php'); - }); - } - -} diff --git a/app/Services/Registrar.php b/app/Services/Registrar.php deleted file mode 100644 index 1035468..0000000 --- a/app/Services/Registrar.php +++ /dev/null @@ -1,39 +0,0 @@ - 'required|max:255', - 'email' => 'required|email|max:255|unique:users', - 'password' => 'required|confirmed|min:6', - ]); - } - - /** - * Create a new user instance after a valid registration. - * - * @param array $data - * @return User - */ - public function create(array $data) - { - return User::create([ - 'name' => $data['name'], - 'email' => $data['email'], - 'password' => bcrypt($data['password']), - ]); - } - -} diff --git a/app/User.php b/app/User.php deleted file mode 100644 index 2dae847..0000000 --- a/app/User.php +++ /dev/null @@ -1,34 +0,0 @@ - 'Illuminate\Support\Str', 'URL' => 'Illuminate\Support\Facades\URL', 'Validator' => 'Illuminate\Support\Facades\Validator', - 'View' => 'Illuminate\Support\Facades\View', - 'Image' => 'Intervention\Image\Facades\Image', + 'View' => 'Illuminate\Support\Facades\View', ), ); + diff --git a/app/config/database.php b/app/config/database.php index b5a34bc..4d18e36 100644 --- a/app/config/database.php +++ b/app/config/database.php @@ -54,9 +54,9 @@ 'mysql' => array( 'driver' => 'mysql', - 'host' => 'alonica.net', + 'host' => 'localhost', 'database' => 'modules', - 'username' => 'banana', + 'username' => 'root', 'password' => 'P455w0Rd!@£$%^&*', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', diff --git a/app/controllers/.gitkeep b/app/controllers/.gitkeep deleted file mode 100755 index e69de29..0000000 diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index e87012e..ca319e8 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -319,6 +319,27 @@ public function removeLecturer(){ )); } + public function backupDB(){ + + if(Auth::user()->rank < 3){ + return "Unauthorized Access."; + } + + $DBUSER="root"; + $DBPASSWD="P455w0Rd!@£$%^&*"; + $DATABASE="modules"; + + $filename = "backup-" . date("d-m-Y") . ".sql.gz"; + $mime = "application/x-gzip"; + + header( "Content-Type: " . $mime ); + header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); + + $cmd = "mysqldump -u $DBUSER --password=$DBPASSWD $DATABASE | gzip --best"; + + passthru( $cmd ); + } + /** * Function that receives a CSV file, and creates * users from it. @@ -422,4 +443,4 @@ public function uploadCSV(){ )); } } -} \ No newline at end of file +} diff --git a/app/controllers/DepartmentController.php b/app/controllers/DepartmentController.php index d082016..3e584d0 100644 --- a/app/controllers/DepartmentController.php +++ b/app/controllers/DepartmentController.php @@ -10,7 +10,7 @@ public function createDepartment() { 'shortname' => 'required', 'head' => 'required', 'description' => 'required', - 'facultyId' => 'required' + 'facultyId' => 'required|numeric' )); if($validator->fails()) { @@ -53,7 +53,7 @@ public function updateDepartment() { 'shortname' => 'required', 'head' => 'required', 'description' => 'required', - 'facultyId' => 'required' + 'facultyId' => 'required|numeric' )); if($validator->fails()) { @@ -87,4 +87,4 @@ public function updateDepartment() { } } -?> \ No newline at end of file +?> diff --git a/app/controllers/ElectiveController.php b/app/controllers/ElectiveController.php index ffd8197..ba71b09 100644 --- a/app/controllers/ElectiveController.php +++ b/app/controllers/ElectiveController.php @@ -357,18 +357,33 @@ public function loadClass() { } public function updateClass() { + $validator = Validator::make(Input::all(), + array( + 'classId' => 'required', + 'limit' => 'required|numeric' + )); - // Get the Class to update. - $class = Classes::where('classId', Input::get('classId'))->first(); + if($validator->fails()) { + + // If not inform user of errors. + return Response::json(array( + 'success' => false, + 'errors' => $validator->messages() + )); + } else { - // Update the class. - $class->classlimit = Input::get('limit'); - $class->save(); + // Get the Class to update. + $class = Classes::where('classId', Input::get('classId'))->first(); - return Response::json(array( - 'success' => true, - 'space' => ($class->classlimit - $class->classcurrent) - )); + // Update the class. + $class->classlimit = Input::get('limit'); + $class->save(); + + return Response::json(array( + 'success' => true, + 'space' => ($class->classlimit - $class->classcurrent) + )); + } } public function removeStudent() { @@ -438,42 +453,50 @@ public function removeStudent() { } - - // RIC -> ERRORS INBOUND :D - public function postElectiveNew(){ $inputData = Input::get('elecData'); parse_str($inputData, $formFields); - $elecData = array( - 'classlecturer' => $formFields['clect'], - 'classmodule' => $formFields['cmod'], - 'classlimit' => $formFields['climit'], - //'classtimes' => $formFields[''], + $moduleData = array( + 'classlecturer' => $formFields['classlecturer'], + 'classmodule' => $formFields['classmodule'], + 'classlimit' => $formFields['classlimit'], ); Validator::extend('ranked', function($attribute, $value, $parameters) { + // This is the correct way to do this. $coord = User::where('name', $value)->first(); - if($coord->rank <= 1){ + if($coord && $coord->rank < 1){ return false; } - return false; + return true; }); + Validator::extend('indep', function($attribute, $value, $parameters) + { + // This is the correct way to do this. + $mod = Modules::find($value); + if($mod && $mod->departmentid !== Auth::user()->department){ + return false; + } + + return true; + }); + $rules = array( - 'classlecturer' => 'required|max:50|exists:users,name|ranked', - 'classmodule' => 'required|exists:modules,mshorttitle', - 'classlimit' => 'required|min:10|max:30', - //'classtimes' => 'required|', + 'classmodule' => 'required|exists:modules,mid|indep', + 'classlecturer' => 'required|exists:users,name|ranked', + 'classlimit' => 'required|integer|between:5,30', ); - + $messages = [ 'ranked' => "This user can't coordinate this class.", + 'indep' => "This module is not in your department.", ]; - $validator = Validator::make($elecData,$rules,$messages); + $validator = Validator::make($moduleData,$rules,$messages); if($validator->fails()){ return Response::json(array( @@ -481,13 +504,13 @@ public function postElectiveNew(){ 'errors' => $validator->getMessageBag()->toArray() )); } else { - - if(Classes::create($elecData)){ - Session::flash('global', 'You have created the elective "'. $elecData['classmodule'].'".'); + $moduleData['classlecturer'] = User::where('name', $moduleData['classlecturer'])->first()->id; + if(Classes::create($moduleData)){ + Session::flash('global', 'You have created an elective.'); //return success message return Response::json(array( 'success' => true, - 'mName' => $elecData['classmodule'] + 'mName' => Modules::find($moduleData['classmodule'])->mshorttitle )); } } @@ -497,36 +520,45 @@ public function postElectiveChange(){ $inputData = Input::get('elecData'); parse_str($inputData, $formFields); - $elecData = array( - 'mfulltitle' => $formFields['mname'], - //add the rest - ); + $moduleData = array( + 'classlecturer' => $formFields['classlecturer'], + 'classmodule' => $formFields['classmodule'], + 'classlimit' => $formFields['classlimit'], + ); Validator::extend('ranked', function($attribute, $value, $parameters) { + // This is the correct way to do this. $coord = User::where('name', $value)->first(); - if($coord->rank <= 1){ - return true; - } + if($coord && $coord->rank < 1){ + return false; + } - return false; + return true; }); + Validator::extend('indep', function($attribute, $value, $parameters) + { + // This is the correct way to do this. + $mod = Modules::find($value); + if($mod && $mod->departmentid !== Auth::user()->department){ + return false; + } + + return true; + }); + + $rules = array( - 'mfulltitle' => 'required|max:50|unique:modules,mfulltitle,'.$formFields['mcode'].',mcode', - 'mshorttitle' => 'required|max:50|unique:modules,mshorttitle,'.$formFields['mcode'].',mcode', - 'mdescription' => 'required|min:30', - 'mcode' => 'required|min:7|max:8|alpha_num|unique:modules,mcode,'.$formFields['mcode'].',mcode', - 'mfieldofstudy' => 'required|max:100', - 'mcoordinator' => 'required|exists:users,name|ranked', - 'mlevel' => 'required|in:Fundamental,Intermediate,Advanced,Expert', - 'mcredits' => 'required|integer|between:5,25', - 'mid' => 'required|exists:modules,mid', - 'departmentid' => 'required', + 'classmodule' => 'required|exists:modules,mid|indep', + 'classlecturer' => 'required|exists:users,name|ranked', + 'classlimit' => 'required|integer|between:5,30', ); $messages = [ 'ranked' => "This user can't coordinate this class.", + 'indep' => "This module is not in your department.", + ]; $validator = Validator::make($moduleData,$rules,$messages); @@ -539,29 +571,25 @@ public function postElectiveChange(){ )); } else { - $mod = Modules::where('mid', $moduleData['mid'])->first(); - - $mod->mfulltitle = $moduleData['mfulltitle']; - $mod->mshorttitle = $moduleData['mshorttitle']; - $mod->mdescription = $moduleData['mdescription']; - $mod->mcode = $moduleData['mcode']; - $mod->mfieldofstudy = $moduleData['mfieldofstudy']; - $mod->mcoordinator = $moduleData['mcoordinator']; - $mod->mlevel = $moduleData['mlevel']; - $mod->mcredits = $moduleData['mcredits']; - $mod->departmentid = $moduleData['departmentid']; + $elec = Classes::where('classid', $formFields['classid'])->first(); + + $elec->classmodule = $moduleData['classmodule']; + $elec->classlecturer = User::where('name', $moduleData['classlecturer'])->first()->id; + $elec->classlimit = $moduleData['classlimit']; - if($mod->save()){ - Session::flash('global', 'You have edited the module "'. $moduleData['mfulltitle'].'".'); + if($elec->save()){ + Session::flash('global', 'You have edited a module.'); //return success message return Response::json(array( 'success' => true, - 'mName' => $moduleData['mfulltitle'] + 'mName' => Modules::find($moduleData['classmodule'])->mshorttitle )); } } } + + public function getElectives(){ if(Auth::check()){ if (Auth::user()->rank >= 2) @@ -603,7 +631,7 @@ function printClassList($classId) { fputcsv($f, $line, $delimiter); } } - } - + } + } -?> \ No newline at end of file +?> diff --git a/app/controllers/ModuleController.php b/app/controllers/ModuleController.php index 5d2981c..2ffeb9a 100644 --- a/app/controllers/ModuleController.php +++ b/app/controllers/ModuleController.php @@ -22,7 +22,7 @@ public function postModuleNew(){ { // This is the correct way to do this. $coord = User::where('name', $value)->first(); - if($coord->rank < 1){ + if(!$coord && $coord->rank < 1){ return false; } @@ -85,7 +85,7 @@ public function postModuleChange(){ Validator::extend('ranked', function($attribute, $value, $parameters) { $coord = User::where('name', $value)->first(); - if($coord->rank < 1){ + if($coord && $coord->rank < 1){ return false; } @@ -155,74 +155,6 @@ public function getModules(){ } } - public function getImage($modCode){ - - $cacheKey = md5($modCode); - - $image = Cache::remember($cacheKey, 3600, function() use ($modCode) { - // start making our image (this assumes your original image is within "app/storage/img") - $colors = array('#00c6ff', '#f39c12', '#ff0000', '#49E035'); - $color = $colors[array_rand($colors)]; - $img = Image::canvas(384, 384, $color); - $img->insert(public_path('images/layout.png'), 'top-left', 5, 0); - - $mod = Modules::where('mcode', $modCode); - - if($mod->count()){ - $mod = $mod->first(); - - $img->text($mod->department->name(), 192, 250, function($font) { - $font->file(public_path('fonts/segoeui.ttf')); - $font->size(30); - $font->color('#fff'); - $font->align('center'); - }); - - $img->text($mod->mshorttitle, 192, 320, function($font) { - $font->file(public_path('fonts/segoeui.ttf')); - $font->size(25); - $font->color('#fff'); - $font->align('center'); - }); - - } elseif ($modCode == 'newMod') { - $img->text('Create new Module!', 192, 300, function($font) { - $font->file(public_path('fonts/segoeui.ttf')); - $font->size(30); - $font->color('#fff'); - $font->align('center'); - }); - } elseif ($modCode == 'newElec') { - $img->text('Create new Elective!', 192, 300, function($font) { - $font->file(public_path('fonts/segoeui.ttf')); - $font->size(30); - $font->color('#fff'); - $font->align('center'); - }); - } else { - $img->text('Error: Module not Found!', 192, 300, function($font) { - $font->file(public_path('fonts/segoeui.ttf')); - $font->size(30); - $font->color('#fff'); - $font->align('center'); - }); - } - - // return the image as a JPG - return $img->encode('jpg'); - }); - - // return the image - $headers = [ - 'Content-Type' => 'image/jpeg', - 'Content-Disposition' => 'inline', - 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', - 'Pragma' => 'public', - 'Etag' => md5($image), - ]; - - return Response::make($image, 200, $headers)->setTtl((60 * 30)); - } public function postElectiveNew(){ @@ -230,7 +162,7 @@ public function postElectiveNew(){ $inputData = Input::get('elecData'); parse_str($inputData, $formFields); $moduleData = array( - 'classlecturer' => User::where('name', $formFields['classlecturer'])->first()->id, + 'classlecturer' => $formFields['classlecturer'], 'classmodule' => $formFields['classmodule'], 'classlimit' => $formFields['classlimit'], ); @@ -238,22 +170,34 @@ public function postElectiveNew(){ Validator::extend('ranked', function($attribute, $value, $parameters) { // This is the correct way to do this. - $coord = User::find($value); - if($coord->rank < 1){ + $coord = User::where('name', $value)->first(); + if($coord && $coord->rank < 1){ return false; } return true; }); + Validator::extend('indep', function($attribute, $value, $parameters) + { + // This is the correct way to do this. + $mod = Modules::find($value); + if($mod && $mod->departmentid !== Auth::user()->department){ + return false; + } + + return true; + }); + $rules = array( - 'classmodule' => 'required|exists:modules,mid', - 'classlecturer' => 'required|exists:users,id|ranked', + 'classmodule' => 'required|exists:modules,mid|indep', + 'classlecturer' => 'required|exists:users,name|ranked', 'classlimit' => 'required|integer|between:5,30', ); $messages = [ 'ranked' => "This user can't coordinate this class.", + 'indep' => "This module is not in your department.", ]; $validator = Validator::make($moduleData,$rules,$messages); @@ -290,21 +234,35 @@ public function postElectiveChange(){ { // This is the correct way to do this. $coord = User::find($value); - if($coord->rank < 1){ + if($coord && $coord->rank < 1){ return false; } return true; }); + Validator::extend('indep', function($attribute, $value, $parameters) + { + // This is the correct way to do this. + $mod = Modules::find($value); + if($mod && $mod->departmentid !== Auth::user()->department){ + return false; + } + + return true; + }); + + $rules = array( - 'classmodule' => 'required|exists:modules,mid', + 'classmodule' => 'required|exists:modules,mid|indep', 'classlecturer' => 'required|exists:users,id|ranked', 'classlimit' => 'required|integer|between:5,30', ); $messages = [ 'ranked' => "This user can't coordinate this class.", + 'indep' => "This module is not in your department.", + ]; $validator = Validator::make($moduleData,$rules,$messages); @@ -335,4 +293,4 @@ public function postElectiveChange(){ } } -?> \ No newline at end of file +?> diff --git a/app/database/.gitignore b/app/database/.gitignore deleted file mode 100755 index 9b1dffd..0000000 --- a/app/database/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.sqlite diff --git a/app/lang/en/reminders.php b/app/lang/en/reminders.php index e2e24e5..e42148e 100755 --- a/app/lang/en/reminders.php +++ b/app/lang/en/reminders.php @@ -21,6 +21,4 @@ "sent" => "Password reminder sent!", - "reset" => "Password has been reset!", - ); diff --git a/app/lang/en/validation.php b/app/lang/en/validation.php index 648516e..b03b926 100755 --- a/app/lang/en/validation.php +++ b/app/lang/en/validation.php @@ -27,7 +27,6 @@ "string" => "The :attribute must be between :min and :max characters.", "array" => "The :attribute must have between :min and :max items.", ), - "boolean" => "The :attribute field must be true or false.", "confirmed" => "The :attribute confirmation does not match.", "date" => "The :attribute is not a valid date.", "date_format" => "The :attribute does not match the format :format.", @@ -71,7 +70,6 @@ ), "unique" => "The :attribute has already been taken.", "url" => "The :attribute format is invalid.", - "timezone" => "The :attribute must be a valid zone.", /* |-------------------------------------------------------------------------- diff --git a/app/routes.php b/app/routes.php index b37873f..c7ef38b 100755 --- a/app/routes.php +++ b/app/routes.php @@ -51,7 +51,7 @@ */ Route::post('/elective-new', array( 'as' => 'elective-new-post', - 'uses' => 'ModuleController@postElectiveNew' + 'uses' => 'ElectiveController@postElectiveNew' )); /* @@ -60,17 +60,15 @@ Route::post('/elective-change', array( 'as' => 'elective-change-post', - 'uses' => 'ModuleController@postElectiveChange' + 'uses' => 'ElectiveController@postElectiveChange' )); - - }); - + /* | Register to elective. */ - + Route::post('/account/register-elective', array( 'as' => 'register-elective', 'uses' => 'ElectiveController@postRegisterElective' @@ -79,12 +77,17 @@ /* | Unregister to elective. */ - + Route::post('/account/unregister-elective', array( 'as' => 'unregister-elective', 'uses' => 'ElectiveController@postUnregisterElective' )); + Route::any('/db/backup', array( + 'as' => 'database-backup', + 'uses' => 'AccountController@backupDB' + )); + /* | Save Timetable */ diff --git a/app/storage/img/layout.png b/app/storage/img/layout.png deleted file mode 100755 index bec5159..0000000 Binary files a/app/storage/img/layout.png and /dev/null differ diff --git a/app/tests/HODViewTest.php b/app/tests/HODViewTest.php index 8c8a642..3ad293e 100644 --- a/app/tests/HODViewTest.php +++ b/app/tests/HODViewTest.php @@ -4,7 +4,7 @@ class HODViewTest extends TestCase { // Define user login credentials. private $username = 'hod'; - private $password = 'abc123'; + private $password = 'password'; public function testController() { // Log in so we have an authenticated user. @@ -12,101 +12,176 @@ public function testController() { $this->assertRedirectedTo('/'); // Create a module to test with. - $module = $this->createModule(); + $d = array('mname' => 'name123', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 5, + 'melective' => true); + $module = $this->createModule($d, true); + + // Try to create a module with incorrect syntax. + $d = array('mname' => 'name123', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 'five', + 'melective' => true); + $this->createModule($d, false); + // Update the module. - $module = $this->updateModule($module->mid); + $d = array('mname' => 'name12345', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 5, + 'melective' => true, + 'mid' => $module->mid); + $module = $this->updateModule($module->mid, $d, true); + + // Try to update the module with incorrect syntax. + $d = array('mname' => 'name12345', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 'five', + 'melective' => true, + 'mid' => $module->mid); + $this->updateModule($module->mid, $d, false); // Now create an elective of that module. - //$elective = $this->createElective($module->mid); + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 10); + $elective = $this->createElective($module->mid, $d, true); + + // Now try creating an elective with incorrect syntax. + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 'ten'); + $this->createElective($module->mid, $d, false); + + // Add a request to the module. + $module->mrequests = '["20"]'; + $module->save(); + + // Check if hod can see request. + $crawler = $this->client->request('GET', '/'); + $this->assertTrue($this->client->getResponse()->isOk()); + $this->assertCount(1, $crawler->filter('p:contains("1 student has requested a new class.")')); // Now update an elective. - //$elective = $this->updateElective($elective->classid); + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 10, + 'classid' => $elective->classid); + $elective = $this->updateElective($elective->classid, $d, true); + + // Try to update elective with bad syntax. + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 'ten', + 'classid' => $elective->classid); + $this->updateElective($elective->classid, $d, false); // Create test lecturer. - $lecturer = $this->createLecturer(); + $lecturer = $this->createLecturer(true); + + // Try to create test lecturer with bad syntax. + $this->createLecturer(false); // Remove the lecturer. $this->removeLecturer($lecturer->id); // Delete dummy data. + $elective->delete(); $module->delete(); - //$elective->delete(); } /** * Function that creates a module */ - protected function createModule() { + protected function createModule($d, $expected) { $data = ''; - $d = array('mname' => 'name123', - 'mshorttitle' => 'short123', - 'mdescription' => str_random(60), - 'mcode' => 'abc1234', - 'mfieldofstudy' => 'abc123', - 'mcoordinator' => 'lecturer', - 'mlevel' => 'Fundamental', - 'mcredits' => 5, - 'melective' => true); foreach($d as $key => $value) { $data = $data.$key.'='.$value.'&'; } $response = $this->call('POST', '/module-new', ['modData' => $data]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + if($expected) { + $this->assertEquals(true, $json->success); - // Return the module we just created. - return Modules::where('mfulltitle', $json->mName)->first(); + // Return the module we just created. + return Modules::where('mfulltitle', $json->mName)->first(); + } else { + $this->assertEquals(true, $json->fail); + } } /** * Function that updates a module */ - protected function updateModule($mid) { + protected function updateModule($mid, $d, $expected) { $data = ''; - $d = array('mname' => 'name12345', - 'mshorttitle' => 'short123', - 'mdescription' => str_random(60), - 'mcode' => 'abc1234', - 'mfieldofstudy' => 'abc123', - 'mcoordinator' => 'lecturer', - 'mlevel' => 'Fundamental', - 'mcredits' => 5, - 'melective' => true, - 'mid' => $mid); foreach($d as $key => $value) { $data = $data.$key.'='.$value.'&'; } $response = $this->call('POST', '/module-change', ['modData' => $data]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + if($expected) { + $this->assertEquals(true, $json->success); - // Get the module we just updated. - $m = Modules::where('mid', $mid)->first(); + // Get the module we just updated. + $m = Modules::where('mid', $mid)->first(); - // Verify that the change was made. - $this->assertEquals('name12345', $m->mfulltitle); + // Verify that the change was made. + $this->assertEquals('name12345', $m->mfulltitle); - // Now return the module. - return $m; + // Now return the module. + return $m; + } else { + $this->assertEquals(true, $json->fail); + } } /** * Function that creates a lecturer. */ - protected function createLecturer() { - $response = $this->call('POST', '/account/create-lecturer', ['name' => 'phpunitLecturer', + protected function createLecturer($expected) { + if ($expected) { + $response = $this->call('POST', '/account/create-lecturer', ['name' => 'phpunitLecturer', + 'username' => 'phpunit123', + 'email' => 'phpunit@email.com']); + + $json = json_decode($response->getContent()); + $this->assertEquals($expected, $json->success); + + // Return the lecturer we just created. + return User::find($json->id); + } else { + $response = $this->call('POST', '/account/create-lecturer', ['name' => 'phpunitLecturer', 'username' => 'phpunit123', - 'email' => 'phpunit@email.com']); + 'email' => 'phpunitemail.com']); - $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); - - // Return the lecturer we just created. - return User::find($json->id); + $json = json_decode($response->getContent()); + $this->assertEquals($expected, $json->success); + } } /** @@ -122,21 +197,47 @@ protected function removeLecturer($id) { /** * Function that creates an elective for a specified module. */ - protected function createElective($mid) { + protected function createElective($mid, $d, $expected) { $data = ''; - $d = array('classlecturer' => 'lecturer', - 'classmodule' => $mid, - 'classlimit' => 10); foreach($d as $key => $value) { $data = $data.$key.'='.$value.'&'; } // TODO: Once elective creation is resolved change path below. - $response = $this->call('POST', '/module-new', ['elecData' => $data]); + $response = $this->call('POST', '/elective-new', ['elecData' => $data]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + if($expected) { + $this->assertEquals(true, $json->success); - // Return the Class we just created. - return Classes::where('classmodule', $mid)->first(); + // Return the Class we just created. + return Classes::where('classmodule', $mid)->first(); + } else { + $this->assertEquals(true, $json->fail); + } + } + + /** + * Function that updates a module + */ + protected function updateElective($id, $d, $expected) { + $data = ''; + foreach($d as $key => $value) { + $data = $data.$key.'='.$value.'&'; + } + $response = $this->call('POST', '/elective-change', ['elecData' => $data]); + + $json = json_decode($response->getContent()); + if($expected) { + $this->assertEquals(true, $json->success); + + // Get the module we just updated. + $c = Classes::where('classid', $id)->first(); + + // Now return the class. + return $c; + } else { + $this->assertEquals(true, $json->fail); + } } } + diff --git a/app/tests/LecturerViewTest.php b/app/tests/LecturerViewTest.php index 75b48d6..c9810e3 100644 --- a/app/tests/LecturerViewTest.php +++ b/app/tests/LecturerViewTest.php @@ -4,7 +4,7 @@ class LecturerViewTest extends TestCase { // Define user login credentials. private $username = 'lecturer'; - private $password = 'abc123'; + private $password = 'password'; public function testController() { // Log in so we have an authenticated user. @@ -37,7 +37,10 @@ public function testController() { $this->loadClass($class->classid); // Update class. - $this->updateClass($class->classid); + $this->updateClass($class->classid, true, 5); + + // Update class with incorrect values. + $this->updateClass($class->classid, false, 'five'); // Remove student from class. $this->removeStudent($class->classid, $student->id); @@ -61,11 +64,13 @@ protected function loadClass($id, $expected = 1) { /** * Function that updates a class. */ - protected function updateClass($id) { - $response = $this->call('POST', '/account/update-class', ['classId' => $id, 'limit' => 5]); + protected function updateClass($id, $expected, $updateVal) { + $response = $this->call('POST', '/account/update-class', ['classId' => $id, 'limit' => $updateVal]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); - $this->assertEquals(4, $json->space); + $this->assertEquals($expected, $json->success); + if($expected) { + $this->assertEquals(4, $json->space); + } } diff --git a/app/tests/SignInTest.php b/app/tests/SignInTest.php index cf25dbb..bf99fab 100644 --- a/app/tests/SignInTest.php +++ b/app/tests/SignInTest.php @@ -3,16 +3,12 @@ class SignInTest extends TestCase { // Define user login credentials. - private $username = 'R00103567'; - private $password = 'fr1ck0ff'; - - // Define crawler. - private $crawler; + private $username = 'student'; + private $password = 'password'; /** * Test if the signIn page works correctly. */ - public function testSignInPage() - { + public function testSignInPage() { // Load the page and check it loads correctly. $this->client->request('GET', '/account/signin'); $this->assertTrue($this->client->getResponse()->isOk()); @@ -21,11 +17,17 @@ public function testSignInPage() /** * Test if the signIn form works correctly. */ - public function testSignInForm() - { + public function testSignInForm() { $response = $this->action('POST', 'AccountController@postSignIn', ['username' => $this->username, 'password' => $this->password]); $this->assertRedirectedTo('/'); } + /** + * Test if the sign in form fails with incorrect credentials. + */ + public function testFailSignInForm() { + $response = $this->action('POST', 'AccountController@postSignIn', ['username' => $this->username, 'password' => 'badpassword']); + $this->assertRedirectedTo('/account/signin'); + } } diff --git a/app/tests/StudentViewTest.php b/app/tests/StudentViewTest.php index b81d816..053ae44 100644 --- a/app/tests/StudentViewTest.php +++ b/app/tests/StudentViewTest.php @@ -1,10 +1,10 @@ createDummyClass($elective->mid); // Try registering to elective. - $this->register($elective->mid); + $this->register($elective->mid, true); + + // Now try registering to the same elective again. + $this->register($elective->mid, false); + + // Check if registered class shows in users profile. + $crawler = $this->client->request('GET', '/'); + $this->assertTrue($this->client->getResponse()->isOk()); + $this->assertCount(1, $crawler->filter('h3:contains("'. $elective->mshorttitle .'")')); + + // Load timetable for class. + $crawler = $this->client->request('GET', '/timetables/'.$class->classid); + $this->assertTrue($this->client->getResponse()->isOk()); // Now unregister from elective. - $this->unregister($elective->mid); + $this->unregister($elective->mid, true); + + // Try to unregister from the same elective. + $this->unregister($elective->mid, false); // Now request a new class. - $this->request($elective->mid); + $this->request($elective->mid, true); + + // Request again. + $this->request($elective->mid, false); // Delete dummy data. $class->delete(); @@ -34,28 +52,28 @@ public function testController() { /** * Function that registers user to elective. */ - protected function register($id) { + protected function register($id, $expected) { $response = $this->call('POST', '/account/register-elective', ['electiveId' => $id]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + $this->assertEquals($expected, $json->success); } /** * Function that unregisters user to elective. */ - protected function unregister($id) { + protected function unregister($id, $expected) { $response = $this->call('POST', '/account/unregister-elective', ['electiveId' => $id]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + $this->assertEquals($expected, $json->success); } /** * Function that requests a new class for elective. */ - protected function request($id) { + protected function request($id, $expected) { $response = $this->call('POST', '/account/request-elective', ['electiveId' => $id]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + $this->assertEquals($expected, $json->success); } /** @@ -81,7 +99,8 @@ protected function createDummyElective() { protected function createDummyClass($id) { return Classes::create(array( 'classlecturer' => 1, - 'classmodule' => $id, - 'classlimit' => 25)); + 'classmodule' => $id, + 'classlimit' => 25)); } } + diff --git a/app/tests/TechnicianViewTest.php b/app/tests/TechnicianViewTest.php index b366193..9e7e96d 100644 --- a/app/tests/TechnicianViewTest.php +++ b/app/tests/TechnicianViewTest.php @@ -4,7 +4,7 @@ class TechnicianViewTest extends TestCase { // Define user login credentials. private $username = 'technician'; - private $password = 'abc123'; + private $password = 'password'; public function testController() { // Log in so we have an authenticated user. @@ -12,32 +12,106 @@ public function testController() { $this->assertRedirectedTo('/'); // Create a module to test with. - $module = $this->createModule(); + $d = array('mname' => 'name123', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 5, + 'melective' => true); + $module = $this->createModule($d, true); + + // Try to create a module with incorrect syntax. + $d = array('mname' => 'name123', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 'five', + 'melective' => true); + $this->createModule($d, false); + // Update the module. - $module = $this->updateModule($module->mid); + $d = array('mname' => 'name12345', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 5, + 'melective' => true, + 'mid' => $module->mid); + $module = $this->updateModule($module->mid, $d, true); + + // Try to update the module with incorrect syntax. + $d = array('mname' => 'name12345', + 'mshorttitle' => 'short123', + 'mdescription' => str_random(60), + 'mcode' => 'abc1234', + 'mfieldofstudy' => 'abc123', + 'mcoordinator' => 'lecturer', + 'mlevel' => 'Fundamental', + 'mcredits' => 'five', + 'melective' => true, + 'mid' => $module->mid); + $this->updateModule($module->mid, $d, false); // Now create an elective of that module. - //$elective = $this->createElective($module->mid); + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 10); + $elective = $this->createElective($module->mid, $d, true); + + // Now try creating an elective with incorrect syntax. + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 'ten'); + $this->createElective($module->mid, $d, false); // Now update an elective. - //$elective = $this->updateElective($elective->classid); + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 10, + 'classid' => $elective->classid); + $elective = $this->updateElective($elective->classid, $d, true); + + // Try to update elective with bad syntax. + $d = array('classlecturer' => 'lecturer', + 'classmodule' => $module->mid, + 'classlimit' => 'ten', + 'classid' => $elective->classid); + $this->updateElective($elective->classid, $d, false); // Create test faculty. - $faculty = $this->createFaculty(); + $faculty = $this->createFaculty(true); + + // Create faculty with bad syntax. + $this->createFaculty(false); // Update the faculty. $faculty = $this->updateFaculty($faculty->facultyid); // Create test department. - $department = $this->createDepartment(); + $department = $this->createDepartment(true); + + // Try creating test department with incorrect syntax. + $this->createDepartment(false); // Update the department. - $department = $this->updateDepartment($department->departmentid); + $department = $this->updateDepartment($department->departmentid, true); + + // Try updating department with incorrect syntax. + $this->updateDepartment($department->departmentid, false); // Delete dummy data. + $elective->delete(); $module->delete(); - //$elective->delete(); $faculty->delete(); $department->delete(); @@ -46,60 +120,49 @@ public function testController() { /** * Function that creates a module */ - protected function createModule() { + protected function createModule($d, $expected) { $data = ''; - $d = array('mname' => 'name123', - 'mshorttitle' => 'short123', - 'mdescription' => str_random(60), - 'mcode' => 'abc1234', - 'mfieldofstudy' => 'abc123', - 'mcoordinator' => 'lecturer', - 'mlevel' => 'Fundamental', - 'mcredits' => 5, - 'melective' => true); foreach($d as $key => $value) { $data = $data.$key.'='.$value.'&'; } $response = $this->call('POST', '/module-new', ['modData' => $data]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + if($expected) { + $this->assertEquals(true, $json->success); - // Return the module we just created. - return Modules::where('mfulltitle', $json->mName)->first(); + // Return the module we just created. + return Modules::where('mfulltitle', $json->mName)->first(); + } else { + $this->assertEquals(true, $json->fail); + } } /** * Function that updates a module */ - protected function updateModule($mid) { + protected function updateModule($mid, $d, $expected) { $data = ''; - $d = array('mname' => 'name12345', - 'mshorttitle' => 'short123', - 'mdescription' => str_random(60), - 'mcode' => 'abc1234', - 'mfieldofstudy' => 'abc123', - 'mcoordinator' => 'lecturer', - 'mlevel' => 'Fundamental', - 'mcredits' => 5, - 'melective' => true, - 'mid' => $mid); foreach($d as $key => $value) { $data = $data.$key.'='.$value.'&'; } $response = $this->call('POST', '/module-change', ['modData' => $data]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + if($expected) { + $this->assertEquals(true, $json->success); - // Get the module we just updated. - $m = Modules::where('mid', $mid)->first(); + // Get the module we just updated. + $m = Modules::where('mid', $mid)->first(); - // Verify that the change was made. - $this->assertEquals('name12345', $m->mfulltitle); + // Verify that the change was made. + $this->assertEquals('name12345', $m->mfulltitle); - // Now return the module. - return $m; + // Now return the module. + return $m; + } else { + $this->assertEquals(true, $json->fail); + } } /** @@ -139,59 +202,108 @@ protected function updateFaculty($id) { /** * Function that creates a Department. */ - protected function createDepartment() { - $response = $this->call('POST', '/account/create-department', ['name' => 'phpunitDepartment', - 'shortname' => 'phpunitDepartment', - 'head' => 'headofdepartment', - 'description' => str_random(60), - 'facultyId' => 1]); + protected function createDepartment($expected) { + if($expected) { + $response = $this->call('POST', '/account/create-department', ['name' => 'phpunitDepartment', + 'shortname' => 'phpunitDepartment', + 'head' => 'headofdepartment', + 'description' => str_random(60), + 'facultyId' => 1]); - $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + $json = json_decode($response->getContent()); + $this->assertEquals($expected, $json->success); + + // Return the we just created. + return Departments::find($json->departmentId); + } else { + $response = $this->call('POST', '/account/create-department', ['name' => 'phpunitDepartment', + 'shortname' => 'phpunitDepartment', + 'head' => 'headofdepartment', + 'description' => str_random(30), + 'facultyId' => 'one']); - // Return the we just created. - return Departments::find($json->departmentId); + $json = json_decode($response->getContent()); + $this->assertEquals($expected, $json->success); + } } /** * Function that updates specified department. */ - protected function updateDepartment($id) { - $response = $this->call('POST', '/account/update-department', ['name' => 'phpunitDepartment123', - 'shortname' => 'phpunitDepartment', - 'head' => 'headofdepartment', - 'description' => str_random(60), - 'facultyId' => 1, - 'id' => $id]); + protected function updateDepartment($id, $expected) { + if($expected) { + $response = $this->call('POST', '/account/update-department', ['name' => 'phpunitDepartment123', + 'shortname' => 'phpunitDepartment', + 'head' => 'headofdepartment', + 'description' => str_random(60), + 'facultyId' => 1, + 'id' => $id]); + + $json = json_decode($response->getContent()); + $this->assertEquals(true, $json->success); + + // Verify that the change was made. + $d = Departments::find($id); + $this->assertEquals('phpunitDepartment123', $d->departmentname); + + return $d; + } else { + $response = $this->call('POST', '/account/update-department', ['name' => 'phpunitDepartment123', + 'shortname' => 'phpunitDepartment', + 'head' => 'headofdepartment', + 'description' => str_random(60), + 'facultyId' => 'one', + 'id' => $id]); + + $json = json_decode($response->getContent()); + $this->assertEquals(false, $json->success); + } + } - $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + /** + * Function that creates an elective for a specified module. + */ + protected function createElective($mid, $d, $expected) { + $data = ''; + foreach($d as $key => $value) { + $data = $data.$key.'='.$value.'&'; + } + // TODO: Once elective creation is resolved change path below. + $response = $this->call('POST', '/elective-new', ['elecData' => $data]); - // Verify that the change was made. - $d = Departments::find($id); - $this->assertEquals('phpunitDepartment123', $d->departmentname); + $json = json_decode($response->getContent()); + if($expected) { + $this->assertEquals(true, $json->success); - return $d; + // Return the Class we just created. + return Classes::where('classmodule', $mid)->first(); + } else { + $this->assertEquals(true, $json->fail); + } } /** - * Function that creates an elective for a specified module. + * Function that updates a module */ - protected function createElective($mid) { + protected function updateElective($id, $d, $expected) { $data = ''; - $d = array('classlecturer' => 'lecturer', - 'classmodule' => $mid, - 'classlimit' => 10); foreach($d as $key => $value) { $data = $data.$key.'='.$value.'&'; } - // TODO: Once elective creation is resolved change path below. - $response = $this->call('POST', '/module-new', ['elecData' => $data]); + $response = $this->call('POST', '/elective-change', ['elecData' => $data]); $json = json_decode($response->getContent()); - $this->assertEquals(true, $json->success); + if($expected) { + $this->assertEquals(true, $json->success); - // Return the Class we just created. - return Classes::where('classmodule', $mid)->first(); + // Get the module we just updated. + $c = Classes::where('classid', $id)->first(); + + // Now return the class. + return $c; + } else { + $this->assertEquals(true, $json->fail); + } } } + diff --git a/app/views/account/password.blade.php b/app/views/account/password.blade.php index fdba4ed..fd66b59 100755 --- a/app/views/account/password.blade.php +++ b/app/views/account/password.blade.php @@ -28,7 +28,7 @@