Пример #1
0
<?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>
<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>