Jump to content

timtamboy63

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

timtamboy63's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey people, I recently decided to try out PHPUnit, and I'm trying to write a test for my Config class, but I have no idea what to test. Here's the code for my class: <?php /** * Config class - manages reading the configuration from the set config files (for both the global config file and components) * The global config file must be an ini (unless the implementation of Config::get() is changed), and the component config files are all XML files * * @version 1.0 * @author Chintan Parikh * * Changelist: */ class Config { /** * The location of the config directory */ const CONFIG_DIRECTORY = 'config/'; /** * The location of the component directory (must be under the config directory) */ const COMPONENT_DIRECTORY = 'components/'; /** * The filename of the global config file (located inside the config directry) */ const GLOBAL_CONFIG = 'config.ini'; /** * Gets a config item from the global config file and returns it */ public function get($item) { $config = parse_ini_file(self::CONFIG_DIRECTORY . self::GLOBAL_CONFIG); return $config[$item]; } /** * Gets all config items from a component xml file */ public function getComponent($component) { $config = array(); $xml = simplexml_load_file(self::CONFIG_DIRECTORY . self::COMPONENT_DIRECTORY . $component . '.config.shel'); $vars = get_object_vars($xml); foreach ($vars as $key=>$value) { $name = $key; } if (!empty($name)) { // Remove the comments field (uncessary, and we don't need it)) unset($xml->$name->comment); $config[$name] = get_object_vars($xml->$name); } return $vars; } } Can anyone give me examples of what I should be testing, and if possible, some example PHPUnit code? Cheers!
  2. Hey guys, I joined just too ask this question, but I am starting to like php so I may stick around, Anyway, here's what im trying to do: Basically, ive got my form printing out some default fields, and then checking the db for any additional fields it has to print out. This bit works fine, i can easily get it to print out the additional fields from the database. I can also add the columns needed to the databsae where the users are stored. The problem im having is parsing the additional values from the additional forms into the database. Might be easier if I give you some more info. 1:In my database, i have two tables, users and profile. All the users are stored in the table users The table profile is for any additional fields the admin wants to add to the registration page. As I said earilier, I can get the fields to print out no problem.(ive also got the required columns added in table users. I can't work out how to parse them into a sql query. Heres the code for my reg page so far(it doesnt parse the additional values from the registration form. <?php include_once('includes/header.php'); if(isset($_POST['submitted'])){ //if they've submitted the form, then dbconnect(); $user=mysql_real_escape_string($_POST['reg_user']); //first santize the input $pass=md5(mysql_real_escape_string($_POST['reg_pass'])); $email=mysql_real_escape_string($_POST['reg_email']); $usernametaken="SELECT * FROM users WHERE username = '$user'"; //check if the username is taken $queryresult=mysql_query("$usernametaken"); $row = mysql_fetch_array($queryresult); if($row['username']!=""){ //if it is, tell the user to register under a different name and show them the reg form print "Username Taken, please use another username"; include('includes/regform.php'); } else{ $query="INSERT INTO users VALUES('', '$user', '$pass', '$email', '0')"; mysql_query("$query"); dbclose(); print "Thank you for registering " . $user . ". Please Login Below"; include('index.php'); //show them the login so they can log in } } else{ //if they havent submitted the form include('includes/regform.php'); //print out the form } include_once('includes/footer.php'); ?> Im trying to get it to parse the additional values submitted by the registration form, but i can't work out how to. If it helps, here's my registration form(regform.php): <script language="javascript" src="js/checkform.js"></script> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return checkregform(this);"> Username:<br /> <input type="text" name="reg_user" /><br /> Password:<br /> <input type="password" name="reg_pass" /><br /> Repeat Password:<br /> <input type="password" name="reg_passrepeat" /><br /> Email:<br /> <input type="text" name="reg_email" /><br /> Repeat Email:<br /> <input type="text" name="reg_emailrepeat" /><br /> <?php dbconnect(); $query="SELECT * FROM profile"; $regform_queryresult=mysql_query("$query") or die(mysql_error()); while($regforms=mysql_fetch_array($regform_queryresult)){ print $regforms['name'] . "<br />"; print "<input type=\"text\" name=\""; print $regforms['name']; print "\" /><br />"; } dbclose(); ?> <input type="hidden" name="submitted" /><br /> <input type="submit" name="reg" value="Register!" /> </form> If you did read through all that thanks If you can help me, thanks a tonne
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.