public function testCallStatic() { $result = Fixtures::methodName('fixture_test', array('parameter' => 'value'), 'param'); $expected = array('method' => 'methodName', 'params' => array(array('parameter' => 'value'), 'param')); $this->assertEqual($expected, $this->_callable->call[0]); }
public function testNodeWithNonStrictMode() { Fixtures::save('db'); extract($this->_models); $result = Set::extract(Aco::node('root/printers/refill/unexisting', false), '/id'); $expected = ['9', '6', '1']; $this->assertEqual($expected, $result); }
public function testOneToManyUsingSameKeyName() { Fixtures::drop('db', array('galleries')); $fixture = Fixtures::get('db', 'galleries'); $fixture->alter('change', 'id', array('to' => 'gallery_id')); Fixtures::save('db', array('galleries')); Galleries::reset(); Galleries::config(array('meta' => array('connection' => $this->_connection, 'key' => 'gallery_id'))); $opts = array('conditions' => array('Galleries.gallery_id' => 1)); $query = new Query($opts + array('type' => 'read', 'model' => 'lithium\\tests\\fixture\\model\\gallery\\Galleries', 'source' => 'galleries', 'alias' => 'Galleries', 'with' => array('Images'))); $galleries = $this->_db->read($query); $this->assertCount(3, $galleries->first()->images); }
/** * Dropping the test database */ public function tearDown() { Fixtures::clear('db'); }
/** * Prove that two distinct models each having a different connection to a different * database are working independently upon the correct databases. */ public function testSwitchingDatabaseDistinctModels() { $connection1 = $this->_connection; $connection2 = $this->_connection . '_alternative'; $connectionConfig1 = Connections::get($connection1, array('config' => true)); $connectionConfig2 = Connections::get($connection2, array('config' => true)); parent::connect($connection2); $this->skipIf(!$connectionConfig2, "The `'{$connection2}' connection is not available`."); $this->skipIf(!$this->with(array('MySql', 'PostgreSql', 'Sqlite3'))); $bothInMemory = $connectionConfig1['database'] == ':memory:'; $bothInMemory = $bothInMemory && $connectionConfig2['database'] == ':memory:'; $this->skipIf($bothInMemory, 'Cannot use two connections with in memory databases'); Fixtures::save('db_alternative'); Galleries::config(array('meta' => array('connection' => $connection1))); Images::config(array('meta' => array('connection' => $connection1))); $galleriesCountOriginal = Galleries::find('count'); $imagesCountOriginal = Images::find('count'); $gallery = Galleries::create(array('name' => 'record_in_db')); $gallery->save(); $image = Images::find('first', array('conditions' => array('id' => 1))); $image->delete(); Galleries::config(array('meta' => array('connection' => $connection2))); $expected = $galleriesCountOriginal; $result = Galleries::find('count'); $this->assertEqual($expected, $result); $expected = $imagesCountOriginal - 1; $result = Images::find('count'); $this->assertEqual($expected, $result); Fixtures::clear('db_alternative'); }
public function testAllowOnTheFlyPrivilege() { Fixtures::save('db'); $this->assertFalse(Permission::check('Micheal', 'tpsReports', ['publish'])); $this->assertTrue(Permission::allow('Micheal', 'tpsReports', ['publish'])); $this->assertTrue(Permission::check('Micheal', 'tpsReports', ['publish'])); $this->assertTrue(Permission::check('Micheal', 'root/tpsReports', ['publish'])); $this->assertTrue(Permission::check('Micheal', 'root/tpsReports/update', ['publish'])); }
public function testSerializingCollection() { Fixtures::save('db'); $data = Images::find('all'); $this->skipIf(!$data, 'Fixtures not applied/available.'); $result = true; try { $data = serialize($data); $data = unserialize($data); } catch (Exception $e) { $result = false; $data = array(); } $this->assertTrue($result); $expected = 'Amiga 1200'; foreach ($data as $item) { $result = $item->title; break; } $this->assertEqual($expected, $result); }
public function testCreate() { Fixtures::create('db', ['comment', 'image']); Comment::actsAs('Tree', ['scope' => ['image_id']]); $root1 = Comment::create(['image_id' => 1]); $root1->save(); $root2 = Comment::create(['image_id' => 2]); $root2->save(); $neighbor1 = Comment::create(['image_id' => 1]); $neighbor1->save(); $idField = Comment::key(); $subelement1 = Comment::create(['image_id' => 1, 'parent_id' => $neighbor1->{$idField}]); $subelement1->save(); $entities = Comment::find('all', ['order' => ['id' => 'asc']]); $expected = ['1' => ['id' => '1', 'image_id' => '1', 'body' => null, 'parent_id' => null, 'lft' => '1', 'rght' => '2', 'published' => 'N'], '2' => ['id' => '2', 'image_id' => '2', 'body' => null, 'parent_id' => null, 'lft' => '1', 'rght' => '2', 'published' => 'N'], '3' => ['id' => '3', 'image_id' => '1', 'body' => null, 'parent_id' => null, 'lft' => '3', 'rght' => '6', 'published' => 'N'], '4' => ['id' => '4', 'image_id' => '1', 'body' => null, 'parent_id' => '3', 'lft' => '4', 'rght' => '5', 'published' => 'N']]; $this->assertEqual($expected, $entities->data()); }
/** * Dropping the test database */ public function tearDown() { Fixtures::clear('db'); Galleries::reset(); }