Inheritance: extends lithium\tests\mocks\data\MockBase
Exemple #1
0
 public function tearDown()
 {
     Connections::remove('mockconn');
     MockPost::reset();
     MockComment::reset();
     MockMongoPost::reset();
 }
Exemple #2
0
 public function testRelationFromFieldName()
 {
     MockPost::bind('hasMany', 'MockTag');
     $this->assertEqual('MockComment', MockPost::relations('mock_comments')->name());
     $this->assertEqual('MockTag', MockPost::relations('mock_tags')->name());
     $this->assertEqual('MockPost', MockComment::relations('mock_post')->name());
     $this->assertNull(MockPost::relations('undefined'));
 }
 public function testCustomFindMethods()
 {
     print_r(MockPost::findFirstById());
 }
 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->assertIdentical(null, 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->assertFalse('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());
 }
 public function testRespondsToInstanceMethod()
 {
     $this->assertFalse(MockPost::respondsTo('foo_Bar_Baz'));
     MockPost::instanceMethods(array('foo_Bar_Baz' => function ($entity) {
     }));
     $this->assertTrue(MockPost::respondsTo('foo_Bar_Baz'));
 }
Exemple #6
0
 /**
  * Tests that varying `count` syntaxes all produce the same query operation (i.e.
  * `Model::count(...)`, `Model::find('count', ...)` etc).
  *
  * @return void
  */
 public function testCountSyntax()
 {
     $base = MockPost::count(array('email' => '*****@*****.**'));
     $query = $base['query'];
     $this->assertEqual('read', $query->type());
     $this->assertEqual('count', $query->calculate());
     $this->assertEqual(array('email' => '*****@*****.**'), $query->conditions());
     $result = MockPost::find('count', array('conditions' => array('email' => '*****@*****.**')));
     $this->assertEqual($query, $result['query']);
     $result = MockPost::count(array('conditions' => array('email' => '*****@*****.**')));
     $this->assertEqual($query, $result['query']);
 }
 public function tearDown()
 {
     unset($this->query);
     MockPost::reset();
     MockComment::reset();
 }
Exemple #8
0
	public function testSettingNestedObjectDefaults() {
		$this->skipIf(!MockMongoConnection::enabled(), 'MongoDb not enabled.');

		MockPost::$connection = new MockMongoConnection();
		$schema = MockPost::schema();

		MockPost::overrideSchema($schema + array('nested.value' => array(
			'type' => 'string',
			'default' => 'foo'
		)));
		$this->assertEqual('foo', MockPost::create()->nested->value);

		$data = array('nested' => array('value' => 'bar'));
		$this->assertEqual('bar', MockPost::create($data)->nested->value);

		MockPost::overrideSchema($schema);
		MockPost::$connection = null;
	}
Exemple #9
0
 public function testValidateWithRequiredNull()
 {
     $validates = array('title' => 'A custom message here for empty titles.', 'email' => array(array('notEmpty', 'message' => 'email is empty.', 'required' => null)));
     $post = MockPost::create(array('title' => 'post title'));
     $post->validates(array('rules' => $validates));
     $this->assertNotEmpty($post->errors());
     $post->sync(1);
     $post->validates(array('rules' => $validates));
     $this->assertEmpty($post->errors());
 }