public function testPropertyAccess() { $entity = new Entity(array('model' => 'lithium\\tests\\mocks\\data\\MockPost', 'exists' => false)); $this->assertEqual('lithium\\tests\\mocks\\data\\MockPost', $entity->model()); $this->assertFalse($entity->exists()); $entity = new Entity(array('exists' => true)); $this->assertTrue($entity->exists()); $expected = array('exists' => true, 'data' => array(), 'update' => array(), 'increment' => array()); $this->assertEqual($expected, $entity->export()); }
/** * Creates an HTML form, and optionally binds it to a data object which contains information on * how to render form fields, any data to pre-populate the form with, and any validation errors. * Typically, a data object will be a `Record` object returned from a `Model`, but you can * define your own custom objects as well. For more information on custom data objects, see * `lithium\template\helper\Form::$_binding`. * * @see lithium\template\helper\Form::$_binding * @see lithium\data\Entity * @param object $binding * @param array $options * @return string Returns a `<form />` open tag with the `action` attribute defined by either * the `'action'` or `'url'` options (defaulting to the current page if none is * specified), the HTTP method is defined by the `'method'` option, and any HTML * attributes passed in `$options`. */ public function create(\lithium\data\Entity $binding = null, array $options = array()) { $defaults = array('url' => $this->_context->request()->params, 'type' => null, 'action' => null, 'method' => $binding ? $binding->exists() ? 'put' : 'post' : 'post'); list(, $options, $template) = $this->_defaults(__FUNCTION__, null, $options); list($scope, $options) = $this->_options($defaults, $options); $_binding =& $this->_binding; $method = __METHOD__; $params = compact('scope', 'options', 'binding'); $filter = function ($self, $params, $chain) use($method, $template, $defaults, &$_binding) { $scope = $params['scope']; $options = $params['options']; $_binding = $params['binding']; $append = null; if ($scope['type'] == 'file') { if (strtolower($scope['method']) == 'get') { $scope['method'] = 'post'; } $options['enctype'] = 'multipart/form-data'; } if (!in_array(strtolower($scope['method']), array('get', 'post'))) { $append = $self->hidden('_method', array('value' => strtoupper($scope['method']))); $scope['method'] = 'post'; } $url = $scope['action'] ? array('action' => $scope['action']) : $scope['url']; $options['method'] = strtolower($scope['method']); return $self->invokeMethod('_render', array($method, $template, compact('url', 'options', 'append'))); }; return $this->_filter($method, $params, $filter); }