Esempio n. 1
0
 public function testFromModel()
 {
     $dbTest = new DBTest();
     $dbTest->setUp();
     $form = $this->Form->from('PersonModelTest')->where(array('person_id' => 1))->make();
     $actual = '<form><input name="person_id" value="1" type="hidden"/><label>name<input name="name" value="Person One" type="text"/></label><label>age<input name="age" value="30" type="number"/></label><input type="submit" value="send"/></form>';
     $this->assertEquals($actual, $form);
     $form = $this->Form->from('PersonModelTest')->where(array('person_id' => 1))->with(array('name'))->make();
     $actual = '<form><label>name<input name="name" value="Person One" type="text"/></label><input type="submit" value="send"/></form>';
     $this->assertEquals($actual, $form);
     $form = $this->Form->from('PersonModelTest')->where(array('person_id' => 1))->without(array('age'))->make();
     $actual = '<form><input name="person_id" value="1" type="hidden"/><label>name<input name="name" value="Person One" type="text"/></label><input type="submit" value="send"/></form>';
     $this->assertEquals($actual, $form);
     $form = $this->Form->from('PersonModelTest')->blank()->make();
     $actual = '<form><label>person_id<input name="person_id" value="" type="text"/></label><label>name<input name="name" value="" type="text"/></label><label>age<input name="age" value="" type="text"/></label><input type="submit" value="send"/></form>';
     $this->assertEquals($actual, $form);
     //TEST INSERT
     $_POST['name'] = 'Test Person';
     $_POST['age'] = 15;
     $id = $this->Form->from('PersonModelTest')->post();
     $result = $dbTest->DB->query('SELECT name,age FROM discophp_test_person WHERE person_id=?', $id);
     $this->assertEquals(1, $result->rowCount());
     //TEST UPDATE
     $_POST['person_id'] = $id;
     $_POST['name'] = 'Test Person1';
     $this->Form->from('PersonModelTest')->post();
     $row = $dbTest->DB->query('SELECT name FROM discophp_test_person WHERE person_id=?', $id)->fetch();
     $this->assertEquals('Test Person1', $row['name']);
     //TEST SELECT MENU
     $data = array('r' => 'red', 'g' => 'green');
     $select = $this->Form->selectMenu($data, 'color', 'g');
     $actual = '<select name="color"><option value="r">red</option><option value="g" selected="selected">green</option></select>';
     $this->assertEquals($actual, $select);
     $data = $dbTest->DB->query('SELECT person_id AS option_value,name AS option_text FROM discophp_test_person ORDER BY person_id LIMIT 2');
     $select = $this->Form->selectMenu($data, 'names');
     $actual = '<select name="names"><option value="1">Person One</option><option value="2">Person Two</option></select>';
     $this->assertEquals($actual, $select);
     //TEST RADIO BUTTONS
     $data = array('r' => 'red', 'g' => 'green');
     $radio = $this->Form->radioButtons($data, 'color', 'g');
     $actual = '<label>red<input name="color" value="r" type="radio"/></label><label>green<input name="color" value="g" type="radio" checked="checked"/></label>';
     $this->assertEquals($actual, $radio);
     $data = $dbTest->DB->query('SELECT person_id AS button_value,name AS button_text FROM discophp_test_person ORDER BY person_id LIMIT 2');
     $radio = $this->Form->radioButtons($data, 'names');
     $actual = '<label>Person One<input name="names" value="1" type="radio"/></label><label>Person Two<input name="names" value="2" type="radio"/></label>';
     $this->assertEquals($actual, $radio);
     $dbTest->tearDown();
 }
Esempio n. 2
0
 public static function setUpBeforeClass()
 {
     self::$userX = array('LoginName' => 'MisterX', 'DisplayName' => '*****@*****.**', 'HomeDir' => '/dev/null/shibboleth/MisterX');
     self::$userY = array('LoginName' => 'MisterY', 'DisplayName' => '*****@*****.**', 'HomeDir' => '/dev/null/shibboleth/MisterY');
     self::$userZ = array('LoginName' => 'MisterZ', 'DisplayName' => '*****@*****.**', 'HomeDir' => '/dev/null/shibboleth/MisterZ');
     self::cleanUpDatabase();
     //in case tearDownAfter was not called due to error
     DB::addUser(self::$userX['LoginName'], self::$userX['DisplayName'], self::$userX['HomeDir']);
 }
Esempio n. 3
0
        $this->assertTrue(sizeof(search_dvd($this->the_title)) > 0, "{$this->the_title} should be in db");
    }
    public function testGetDVDsForGenre()
    {
        $this->assertTrue(sizeof(get_dvds_for_genre($this->genre)) > 0, "Should be dvd's in the {$this->genre} genre");
    }
    public function testGetAllGenres()
    {
        $this->assertTrue(sizeof(get_all_genres()) > 0, "There should be genres!");
        $this->assertTrue(is_numeric(array_search($this->genre, get_all_genres())), "{$this->genre} should be there");
    }
    public function testGetDVDByTitle()
    {
        $this->assertTrue(sizeof(get_dvd_by_title($this->the_title)) > 0, "there should be a dvd with title {$this->the_title}");
    }
    public function testAddDeleteGenre()
    {
        $all_genres = get_all_genres();
        $this->assertTrue(sizeof($all_genres) > 0, "there should be genres");
        $this->assertTrue(is_numeric(array_search($this->genre, $all_genres)), "{$this->genre} must be there");
    }
    public function testAddDeleteDVD()
    {
        $many_all = get_all("dvd");
        $this->assertTrue(sizeof($many_all) > 0, "should be at least one dvd in the db");
        $it = get_dvd_by_title($this->the_title);
        $this->assertEqual($it['title'], $this->the_title);
    }
}
$test = new DBTest();
$test->run(new TextReporter());
Esempio n. 4
0
 function testSorting()
 {
     $this->getDB();
     $requestedIDs = $this->db->queryValues('SELECT ID FROM Test ORDER BY RANDOM()');
     $this->assertTrue(count($requestedIDs) > 2);
     $this->assertEquals($requestedIDs, array_unique($requestedIDs));
     $objects = DBTest::get($requestedIDs);
     $this->assertType('array', $objects);
     $this->assertEquals(count($objects), count($requestedIDs));
     $foundIDs = array();
     foreach ($objects as $o) {
         $this->assertType('object', $o);
         $foundIDs[] = $o->ID;
     }
     sort($foundIDs);
     sort($requestedIDs);
     $this->assertEquals($foundIDs, array_unique($foundIDs));
     $this->assertEquals(array(), array_diff($requestedIDs, $foundIDs));
     $this->assertTrue(usort($objects, array('DBTest', 'defaultSortFunction')));
 }
Esempio n. 5
0
    private function dbConnect()
    {
        $this->mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_BASE);
        echo 'host: ' . DB_HOST . '<br>';
        echo 'user: '******'<br>';
        echo 'password: '******'<br>';
        echo 'db: ' . DB_BASE . '<br>';
        if ($this->mysqli->connect_errno > 0) {
            die('Unable to connect to database [' . $this->mysqli->connect_error . ']');
        }
    }
    //get customers
    public function getCustomers()
    {
        $query = "SELECT distinct c.customerNumber, c.customerName, c.email, c.address, c.city, c.state, c.postalCode, c.country FROM customers c order by c.customerNumber desc";
        if ($r = $this->mysqli->query($query)) {
            echo 'no of rows: ' . $r->num_rows . '<br>';
            if ($r->num_rows > 0) {
                $result = array();
                while ($row = $r->fetch_assoc()) {
                    echo $row['customerName'] . '<br>.';
                    $result[] = $row;
                }
            }
        } else {
            die('There was an error running the query [' . $this->mysqli->error . ']');
        }
    }
}
$test = new DBTest();
$test->getCustomers();