public function testSettingNestedObjectDefaults() { $schema = MockPost::schema()->append(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']); }
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; }
public function testDelete() { $record = MockPost::create(array('id' => 5), array('exists' => true)); $result = $record->delete(); $this->assertEqual('delete', $result['query']->type()); $this->assertEqual('mock_posts', $result['query']->source()); $this->assertEqual(array('id' => 5), $result['query']->conditions()); }
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()); }