I am a little upset at the moment, my 10.4 virtualbox install of Ubuntu is bugging out on me. I had implemented the get functions in 7.2 and was in the process of getting SimpleTest to work in eclipse, but the GUI isn't even working. I still need to go back and perform unit tests on the other exercises, so I might just start from a fresh install of 11.10. I will update this post once I go through the entire process again.
Update:
I restarted the assignment and got it working. Here are my answers.
Exercise 7.1:
Person.php violates cirterion 5 because it adds a new Person with null values. It is just the default admin account, but it still exists.
Person.php also violates criterion 6 because the first name and the first phone number are redundant with the primary key.
Exercise 7.2:
Here are all of the shift getters:
function get_shift_month($id){
return substr($id,0,2);
}
function get_shift_day($id){
return substr($id,3,2);
}
function get_shift_year($id){
return substr($id,6,2);
}
function get_shift_start($id){
if (substr($id, 11, 1) == "-")
return substr($id,9,2);
else return substr($id,9,1);
}
function get_shift_end($id){
if (substr($id,11,1)=="-")
return substr($id,12,2);
else return substr($id,11,2);
}
Here are the unit tests that I added:
$this->assertTrue(get_shift_month($s2->get_id()) == "02");
$this->assertTrue(get_shift_day($s2->get_id()) == "25");
$this->assertTrue(get_shift_year($s2->get_id()) == "08");
$this->assertTrue(get_shift_start($s2->get_id()) == "15");
$this->assertTrue(get_shift_end($s2->get_id()) == "18");
Success! No errors or failures (aside from the failure that was present in the original source code)
Exercise 7.3:
First, I made changes to dbInstall.php so I wouldn't forget to add it later:
...
include_once('dbPersons.php');
include_once('dbMonths.php')
// connect
$connected=connect();
if (!$connected) echo("not connected...<br />");
echo("connected...<br />");
echo("database selected...<br />");
// setup all of the tables
setup_dbWeeks();
echo("dbWeeks added...<br />");
//MONTHS
setup_dbMonths();
echo("dbMonths added...<br />")
//SCHEDULE
...
Then, I made my dbMonths.php file.
<?php
include_once('Month.php');
include_once('dbDates.php');
function setup_dbMonths() {
connect();
mysql_query("DROP TABLE IF EXISTS dbMonths");
$result=mysql_query("CREATE TABLE dbMonths (id CHAR(8) NOT NULL, dates TEXT, name VARCHAR(14), weekday_start VARCHAR(9), days TEXT, timestamp DATETIME, PRIMARY KEY (id))");
if(!$result)
echo mysql_error();
mysql_close();
}
/**
* Inserts a month into the db
* @param $m the month to insert
*/
function insert_dbMonths($m) {
if (! $m instanceof Month) {
die ("Invalid argument for dbMonths->add_month function call");
}
connect();
$query = "SELECT * FROM dbMonths WHERE id =\"".$m->get_id()."\"";
$result = mysql_query ($query);
if(mysql_num_rows($result)!=0) {
delete_dbMonths($w);
connect();
}
$query="INSERT INTO dbMonths VALUES
(\"".$m->get_id()."\",".get_dates_text($m->get_dates()).",\"".
$m->get_name()."\",\"".
$m->get_weekday_start()."\",\"".
$m->get_timestamp()."\",\"".
$m->get_days()."\")";
$result=mysql_query($query);
mysql_close();
if (!$result) {
echo ("unable to insert into dbMonths: ".$m->get_id(). mysql_error());
return false;
}
else foreach($m->get_dates() as $i)
insert_dbMonths($i);
return true;
}
...
This file is fairly large. I order to avoid swamping this post in code, I will not post the rest
Finally, the testdbMonths.php file:
<?php
include_once(dirname(__FILE__).'/../database/dbMonths.php');
class testdbMonths extends UnitTestCase {
function testdbMonthsModule() {
$m=new Month("02","08");
$this->assertTrue(insert_dbMonths($m));
$m=new Month("03","08");
$this->assertTrue(update_dbMonths($m));
$m=get_dbMonths("03-31-08");
$this->assertTrue($m->get_name()=="March 2008");
$this->assertTrue(delete_dbMonths($m));
echo "testdbMonths complete";
}
}
?>
No tests fail or report any errors; however, dbInstall.php does not print that dbMonths was installed correctly.
No comments:
Post a Comment