Ejemplo n.º 1
0
class ArtistLink extends PicoraActiveRecord
{
}
/*
	TO DO
		- test addition of WHERE conditions with :params
		- test that order / where conditions work if defined in the addRelationship method, and in the dynamically created methods
		- test manually specified table names
		- test validations
		- try saving records that come from has_one, has_many, belongs_to relationships to see if they contain to many columns
*/
PicoraActiveRecord::addRelationship('Album', 'has_many', 'Track', 'album_id', array('dependent' => true));
PicoraActiveRecord::addRelationship('Artist', 'has_one', 'Bio', 'bio_id', array('dependent' => true));
PicoraActiveRecord::addRelationship('Track', 'belongs_to', 'Album', 'album_id', array('counter' => 'track_count'));
PicoraActiveRecord::addRelationship('Artist', 'has_and_belongs_to_many', 'Album', 'ArtistLink', 'artist_id', 'album_id');
PicoraActiveRecord::addRelationship('Album', 'has_and_belongs_to_many', 'Artist', 'ArtistLink', 'album_id', 'artist_id');
abstract class TestPicoraActiveRecord extends PicoraTest
{
    public function testBasics()
    {
        $a = PicoraActiveRecord::build('Album');
        $this->assertFalse($a->id);
        $a = PicoraActiveRecord::build('Album', array('name' => 'Dark Side of the Moon', 'artist' => 'Pink Floyd', 'time' => '43:23', 'track_count' => 0));
        $this->assertFalse($a->id);
        $this->assertEqual($a->name, 'Dark Side of the Moon');
        $this->assertEqual($a->time, '43:23');
        $this->assertTrue($a->save());
        $this->assertEqual($a->id, 1);
        $b = PicoraActiveRecord::create('Album', array('name' => 'Piper at the Gates of Dawn', 'artist' => 'Pink Floyd', 'time' => '42:10', 'track_count' => 0));
        $this->assertEqual($b->id, 2);
        $this->assertEqual($b->name, 'Piper at the Gates of Dawn');