Пример #1
0
 public function testMetaInformation()
 {
     $expected = array('class' => 'lithium\\tests\\mocks\\data\\MockPost', 'name' => 'MockPost', 'key' => 'id', 'title' => 'title', 'source' => 'mock_posts', 'connection' => 'mock-source', 'initialized' => true);
     MockPost::__init();
     $this->assertEqual($expected, MockPost::meta());
     $expected = array('class' => 'lithium\\tests\\mocks\\data\\MockComment', 'name' => 'MockComment', 'key' => 'comment_id', 'title' => 'comment_id', 'source' => 'mock_comments', 'connection' => 'mock-source', 'initialized' => true);
     $this->assertEqual($expected, MockComment::meta());
     $expected += array('foo' => 'bar');
     $this->assertEqual($expected, MockComment::meta('foo', 'bar'));
     $expected += array('bar' => true, 'baz' => false);
     $this->assertEqual($expected, MockComment::meta(array('bar' => true, 'baz' => false)));
 }
Пример #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 = 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();
	}
Пример #4
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();
 }
Пример #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'));
 }