<?php $invalidUser = array("userName" => "Thugnificent", "picture" => "../images/thugnificent.jpg", "firstName" => "Otis", "lastName" => "Jenkins", "address" => "123 Thug Lane", "neighborhood" => "Woodcrest", "dateOfBirth" => "1989-01", "gender" => "male", "comedy" => "checked", "email" => "thugnasty.gmail.com", "phone" => "(210) 555 - 5555", "url" => "https://otis_jenkins/facebook.com"); $userDataTest11 = new UserData($invalidUser); $test2 = empty($userDataTest11->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for email is: " . $userDataTest11->getError('email') . "<br>"; echo "The object is: {$userDataTest11}<br>"; ?> <h2>It should have an error when the email isnt in the format (xxx) xxx - xxxx</h2> <?php $invalidUser = array("userName" => "Thugnificent", "picture" => "../images/thugnificent.jpg", "firstName" => "Otis", "lastName" => "Jenkins", "address" => "123 Thug Lane", "neighborhood" => "Woodcrest", "dateOfBirth" => "1989-01", "gender" => "male", "comedy" => "checked", "email" => "*****@*****.**", "phone" => "2105555555", "url" => "https://otis_jenkins/facebook.com"); $userDataTest12 = new UserData($invalidUser); $test2 = empty($userDataTest12->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for phone is: " . $userDataTest12->getError('phone') . "<br>"; echo "The object is: {$userDataTest12}<br>"; ?> <h2>It should have an error when the url isnt in the format http:// or https://text.com</h2> <?php $invalidUser = array("userName" => "Thugnificent", "picture" => "../images/thugnificent.jpg", "firstName" => "Otis", "lastName" => "Jenkins", "address" => "123 Thug Lane", "neighborhood" => "Woodcrest", "dateOfBirth" => "1989-01", "gender" => "male", "comedy" => "checked", "email" => "*****@*****.**", "phone" => "(210) 555 - 5555", "url" => "otis_jenkins/facebook.com"); $userDataTest13 = new UserData($invalidUser); $test2 = empty($userDataTest13->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test2; echo "The error for url is: " . $userDataTest13->getError('url') . "<br>"; echo "The object is: {$userDataTest13}<br>"; ?> </body> </html>
<?php include_once "../models/UserData.class.php"; ?> <h2>It should create a valid UserData object when all input is provided</h2> <?php $validTest = array("userName" => "josht1234", "password" => "Green123", "confirmedpw" => "Green123", "email" => "*****@*****.**", "dob" => "2015-12-12", "hockUser" => "mop", "color" => "#00FF00", "gender" => "male"); $s1 = new UserData($validTest); echo "{$s1}<br>"; $test2 = empty($s1->getErrors()) ? '' : 'Failed: It should not have errors when valid input is provided<br>'; echo $test2; if ($test2 != "") { echo implode("|", $s1->getErrors()); } ?> <h2>It should extract the parameters that went in</h2> <?php $props = $s1->getParameters(); print_r($props); ?> <h2>Here is an example of a bunch of bad input and all the errors it will throw</h2> <?php $validTest = array("userName" => "as asdfioj \$", "password" => "green", "confirmedpw" => "green123", "email" => "", "dob" => "", "hockUser" => "", "color" => "#00FF00", "gender" => ""); $s1 = new UserData($validTest); $props = $s1->getParameters(); print_r($props); echo "<br>"; echo implode("<br>", $s1->getErrors());
<h2>It should have an error when the phone number is invalid</h2> <?php $invalidPhoneTest = array("phone" => "abc-def-ghij"); $s12 = new UserData($invalidPhoneTest); $test12 = empty($s12->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test12; echo "The error for phone is: " . $s12->getError('phone') . "<br>"; echo "The object is: {$s12}<br>"; ?> <h2>It should have an error when the favorite color is empty</h2> <?php $invalidFavColorTest = array("fav_color" => ""); $s13 = new UserData($invalidFavColorTest); $test13 = empty($s13->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test13; echo "The error for fav_color is: " . $s13->getError('fav_color') . "<br>"; echo "The object is: {$s13}<br>"; ?> <h2>It should have an error when the favorite color is invalid</h2> <?php $invalidFavColorTest = array("fav_color" => "#xyz123"); $s14 = new UserData($invalidFavColorTest); $test14 = empty($s14->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>'; echo $test14; echo "The error for fav_color is: " . $s14->getError('fav_color') . "<br>"; echo "The object is: {$s14}<br>"; ?> </body> </html>