public function testMethods() { // Clear validations \model\ValidationService::Clear(); $appSettings = $this->setupAppsettings(); // Create app mockup object with properties $appMockup = new \stdClass(); $appMockup->htmlView = new \stdClass(); // Create ctrl helper class $ctrlHelper = new \model\CtrlHelperService($appMockup, $appSettings); // Ctrl to string method $CtrlString = $ctrlHelper->CtrlToString(new \controller\PageCtrl($ctrlHelper)); $this->assertEquals("page", $CtrlString); // ProcessUrl method // $ctrlHelper->ProcessUrl('/page/leading/somewhere'); Not testable // Execute controller method $ctrlHelper->ExecuteController(new DummyClass(), "DummyMethod", ["someParam"]); // A new flashmessage should be added. $this->assertTrue(\model\FlashMessageService::DoesExist()); // Clear flashmessage \model\FlashMessageService::Clear(); $riskyFile = '/etc/passwd'; // Load methods $this->assertFalse($ctrlHelper->LoadController($riskyFile)); $this->assertFalse($ctrlHelper->LoadBLLModel($riskyFile)); $this->assertFalse($ctrlHelper->LoadDALModel($riskyFile)); $this->assertFalse($ctrlHelper->LoadService($riskyFile)); $this->assertFalse($ctrlHelper->LoadView($riskyFile)); // Create methods $this->assertFalse($ctrlHelper->CreateController($riskyFile)); $this->assertFalse($ctrlHelper->CreateBLLModel($riskyFile)); $this->assertFalse($ctrlHelper->CreateDALModel($riskyFile)); $this->assertFalse($ctrlHelper->CreateService($riskyFile)); $this->assertFalse($ctrlHelper->CreateView($riskyFile)); }
public function testConstructorWithFaultyValues() { $user = new User("not an int", "someusername", "firstname", "surname", "password", true, true, "", true); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $user = new User(12, "someusernameweawioeawioeuawoiduioawuoiawioeawoidjioawjeoiawjdoiajwoe", "firstname", "surname", "password", true, true, "", true); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $user = new User(12, "someusername", "firstnameweawioeawioeuawoiduioawuoiawioeawoidjioawjeoiawjdoiajwoe", "surname", "password", true, true, "", true); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $user = new User(12, "someusername", "firstnameweawioeawioeuawoiduioawuoiawioeawoidjioawjeoiawjdoiajwoe", "surname", "password", true, true, "", true); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $user = new User(12, "someusername", "firstname", "surnameweawioeawioeuawoiduioawuoiawioeawoidjioawjeoiawjdoiajwoe", "password", true, true, "", true); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $user = new User(12, "someusername", "firstname", "surname", "passwordweawioeawioeuawoiduioawuoiawioeawoidjioawjeoiawjdoiajwoe", true, true, "", true); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); }
public function testConstructor() { // Clear validations \model\ValidationService::Clear(); $appSettings = new AppSettings(['defaultController' => 'SomeCtrlerjaoijaiowjeioawjieojawoijtioajwirjaiwjeipajwpejapwepoawopr', 'defaultMethod' => 'Index', 'controllerPath' => '../app/controller/', 'controllerNamespace' => 'controller\\', 'modelPath' => '../app/model/', 'modelNamespace' => 'model\\', 'viewPath' => '../app/view/', 'viewNamespace' => 'view\\']); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $appSettings = new AppSettings(['defaultController' => 'SomeCtrl', 'defaultMethod' => 'Indexrjaoijaiowjeioawjieojawoijtioajwirjaiwjeipajwpejapwepoawopr', 'controllerPath' => '../app/controller/', 'controllerNamespace' => 'controller\\', 'modelPath' => '../app/model/', 'modelNamespace' => 'model\\', 'viewPath' => '../app/view/', 'viewNamespace' => 'view\\']); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); // Clear validations \model\ValidationService::Clear(); $appSettings = new AppSettings(['defaultController' => 'SomeCtrl', 'defaultMethod' => 'Index', 'controllerPath' => '/var/temp/someEvilfile.php', 'controllerNamespace' => 'controller\\', 'modelPath' => '/etc/passwd', 'modelNamespace' => 'model\\', 'viewPath' => '/etc/sudoers.d', 'viewNamespace' => 'view\\']); // Should be valid but still secure $this->assertTrue(\model\ValidationService::IsValid()); $this->assertEquals('../app/someEvilfile.php/', $appSettings->GetControllerPath()); $this->assertEquals('../app/passwd/', $appSettings->GetModelPath()); $this->assertEquals('../app/sudoers.d/', $appSettings->GetViewPath()); // Check that the rest of the get methods return correct values $this->assertEquals('SomeCtrl', $appSettings->GetDefaultController()); $this->assertEquals('Index', $appSettings->GetDefaultMethod()); $this->assertEquals('controller\\', $appSettings->GetControllerNamespace()); $this->assertEquals('model\\', $appSettings->GetModelNamespace()); $this->assertEquals('view\\', $appSettings->GetViewNamespace()); }
public function testMethods() { // Clear validations \model\ValidationService::Clear(); $page = new Page(12, 'Really nice HEÄDER', 'content', 'authorName'); $page->GenerateSlug(); $this->assertEquals("really-nice-header", $page->GetSlug()); }
public function testIsValidString() { // Clear validations \model\ValidationService::Clear(); $modelBll = new ModelBLL(); // Assert string value $this->assertEquals(true, $modelBll->IsValidString("someName", "string")); // Assert int value $this->assertEquals(true, $modelBll->IsValidString("someName", 1)); // Assert float value $this->assertEquals(true, $modelBll->IsValidString("someName", 1.5)); // Assert object value $this->assertEquals(false, $modelBll->IsValidString("someName", new \stdClass())); // Assert bool value $this->assertEquals(false, $modelBll->IsValidString("someName", false)); // Assert null value $this->assertEquals(false, $modelBll->IsValidString("someName", null)); // Assert options $this->assertEquals(false, $modelBll->IsValidString("someName", "string", ['maxLength' => 2])); $this->assertEquals(false, $modelBll->IsValidString("someName", "string", ['minLength' => 20])); $this->assertEquals(false, $modelBll->IsValidString("someName", "<>>><><£\$@£")); $this->assertEquals(false, $modelBll->IsValidString("someName", "abc123", ['regex' => '/[^a-z]/i'])); // Should not be valid $this->assertFalse(\model\ValidationService::IsValid()); }