Пример #1
0
 public function setUp()
 {
     Connections::add('mockconn', array('object' => new MockSource()));
     $schema = new Schema(array('fields' => array('id' => 'int', 'title' => 'string', 'body' => 'text')));
     MockPost::config(array('meta' => array('connection' => 'mockconn', 'key' => 'id', 'locked' => true), 'schema' => $schema));
     $this->_record = new Record(array('model' => 'lithium\\tests\\mocks\\data\\MockPost'));
 }
Пример #2
0
 public function testLazyMetadataInit()
 {
     MockPost::config(array('schema' => new Schema(array('fields' => array('id' => array('type' => 'integer'), 'name' => array('type' => 'string'), 'label' => array('type' => 'string'))))));
     $this->assertIdentical('mock_posts', MockPost::meta('source'));
     $this->assertIdentical('name', MockPost::meta('title'));
     $this->assertEmpty(MockPost::meta('unexisting'));
     $config = array('schema' => new Schema(array('fields' => array('id' => array('type' => 'integer'), 'name' => array('type' => 'string'), 'label' => array('type' => 'string')))), 'initializers' => array('source' => function ($self) {
         return Inflector::tableize($self::meta('name'));
     }, 'name' => function ($self) {
         return Inflector::singularize('CoolPosts');
     }, 'title' => function ($self) {
         static $i = 1;
         return 'label' . $i++;
     }));
     MockPost::reset();
     MockPost::config($config);
     $this->assertIdentical('cool_posts', MockPost::meta('source'));
     $this->assertIdentical('label1', MockPost::meta('title'));
     $this->assertNotIdentical('label2', MockPost::meta('title'));
     $this->assertIdentical('label1', MockPost::meta('title'));
     $meta = MockPost::meta();
     $this->assertIdentical('label1', $meta['title']);
     $this->assertIdentical('CoolPost', MockPost::meta('name'));
     MockPost::reset();
     unset($config['initializers']['title']);
     $config['initializers']['source'] = function ($self) {
         return Inflector::underscore($self::meta('name'));
     };
     MockPost::config($config);
     $this->assertIdentical('cool_post', MockPost::meta('source'));
     $this->assertIdentical('name', MockPost::meta('title'));
     $this->assertIdentical('CoolPost', MockPost::meta('name'));
     MockPost::reset();
     MockPost::config($config);
     $expected = array('class' => 'lithium\\tests\\mocks\\data\\MockPost', 'connection' => false, 'key' => 'id', 'name' => 'CoolPost', 'title' => 'name', 'source' => 'cool_post');
     $this->assertEqual($expected, MockPost::meta());
 }
Пример #3
0
 public function testModelWithNoBackend()
 {
     $this->assertEqual('mock-source', MockPost::meta('connection'));
     MockPost::config(array('connection' => false));
     $this->assertFalse(MockPost::meta('connection'));
     $schema = array('id' => array('type' => 'integer'), 'author_id' => array('type' => 'integer'), 'title' => array('type' => 'string'), 'body' => array('type' => 'text'));
     MockPost::overrideSchema($schema);
     $this->assertEqual($schema, MockPost::schema());
     $post = MockPost::create(array('title' => 'New post'));
     $this->assertTrue($post instanceof \lithium\data\Entity);
     $this->assertEqual('New post', $post->title);
     $this->expectException('/Connection name not defined/');
     $post->save();
 }
Пример #4
0
	public function testModelWithNoBackend() {
		$this->assertEqual('mock-source', MockPost::meta('connection'));
		MockPost::config(array('connection' => false));
		$this->assertFalse(MockPost::meta('connection'));
		$schema = MockPost::schema();

		MockPost::overrideSchema($this->_altSchema);
		$this->assertEqual($this->_altSchema, MockPost::schema());

		$post = MockPost::create(array('title' => 'New post'));
		$this->assertTrue($post instanceof Entity);
		$this->assertEqual('New post', $post->title);
		MockPost::overrideSchema($schema);

		$this->expectException('/Connection name not defined/');
		$post->save();
	}
Пример #5
0
 public function testModelWithNoBackend()
 {
     $this->assertEqual('mock-source', MockPost::meta('connection'));
     $this->expectException('/^The data connection `invalid` is not configured.$/');
     MockPost::config(array('connection' => 'invalid'));
 }