Skip to content

Commit

Permalink
Merge pull request #43 from proengsoft/feature/multiple-forms
Browse files Browse the repository at this point in the history
easy setup of multiple forms
  • Loading branch information
torrentalle committed Aug 10, 2015
2 parents dd57ce3 + 3df9175 commit e61b048
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ public function validator(ValidatorContract $validator, $selector = null)
*/
protected function createValidator(ValidatorContract $validator, $selector = null)
{
if (!empty($selector)) {
$this->manager->setSelector($selector);
}

$this->manager->selector($selector);
$this->manager->setValidator($validator);

return $this->manager;
Expand Down
31 changes: 27 additions & 4 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public function setValidator(ValidatorContract $validator)
*/
public function render($view = null, $selector = null)
{
$view = is_null($view) ? $this->view : $view;
$this->setSelector(is_null($selector) ? $this->selector : $selector);
$this->view($view );
$this->selector($selector);

return View::make($view, ['validator' => $this->getViewData()])
return View::make($this->view, ['validator' => $this->getViewData()])
->render();
}

Expand Down Expand Up @@ -126,11 +126,34 @@ protected function getViewData()

/**
* Set the form selector to validate.
*
* @param string $selector
* @deprecated
*/
public function setSelector($selector)
{
$this->selector = $selector;
}

/**
* Set the form selector to validate.
* @param string $selector
* @return Manager
*/
public function selector($selector)
{
$this->selector = is_null($selector) ? $this->selector : $selector;
return $this;
}

/**
* Set the view to render Javascript Validations.
* @param string $view
* @return Manager
*/
public function view($view)
{
$this->view = is_null($view) ? $this->view : $view;
return $this;
}
}

6 changes: 5 additions & 1 deletion tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testMake() {
->andReturn(
m::mock('Illuminate\Contracts\Validation\Validator')
);
$this->mockedJs->shouldReceive('setSelector')->once()->andReturn('form');
$this->mockedJs->shouldReceive('selector')->once()->andReturn('form');

$js=$this->factory->make($rules,[],[],'form');

Expand All @@ -59,6 +59,7 @@ public function testFormRequestFromInstance() {
$mockFormRequest->shouldReceive('rules')->once()->andReturn($rules);
$mockFormRequest->shouldReceive('messages')->once()->andReturn([]);
$mockFormRequest->shouldReceive('attributes')->once()->andReturn([]);
$this->mockedJs->shouldReceive('selector')->once()->andReturn('form');

$this->mockedFactory->shouldReceive('make')
->once()
Expand All @@ -67,6 +68,7 @@ public function testFormRequestFromInstance() {
m::mock('Illuminate\Contracts\Validation\Validator')
);


$js=$this->factory->formRequest($mockFormRequest);

$this->assertInstanceOf('Proengsoft\JsValidation\Manager',$js);
Expand Down Expand Up @@ -95,6 +97,8 @@ public function testFormRequestException() {
public function testValidator()
{
$validator=m::mock('Illuminate\Contracts\Validation\Validator');
$this->mockedJs->shouldReceive('selector')->once()->andReturn('form');

$js=$this->factory->validator($validator);
$this->assertInstanceOf('Proengsoft\JsValidation\Manager',$js);

Expand Down

0 comments on commit e61b048

Please sign in to comment.