diff --git a/composer.json b/composer.json index 58a9644d..bb7992c5 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "proengsoft/laravel-jsvalidation", + "name": "isrenato/laravel-js-validation", "type": "library", "description": "Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest", "keywords": [ @@ -42,21 +42,21 @@ }, "autoload": { "psr-4": { - "Proengsoft\\JsValidation\\": "src" + "Isrenato\\JsValidation\\": "src" } }, "autoload-dev": { "psr-4": { - "Proengsoft\\JsValidation\\Tests\\": "tests" + "Isrenato\\JsValidation\\Tests\\": "tests" } }, "extra": { "laravel": { "providers": [ - "Proengsoft\\JsValidation\\JsValidationServiceProvider" + "Isrenato\\JsValidation\\JsValidationServiceProvider" ], "aliases": { - "JsValidator": "Proengsoft\\JsValidation\\Facades\\JsValidatorFacade" + "JsValidator": "Isrenato\\JsValidation\\Facades\\JsValidatorFacade" } } }, diff --git a/public/js/jsvalidation.js b/public/js/jsvalidation.js index ed3ce1a6..2a13ac73 100644 --- a/public/js/jsvalidation.js +++ b/public/js/jsvalidation.js @@ -2599,7 +2599,7 @@ laravelValidation = { var param = typeof param === "string" && { url: param } || param; - if (laravelValidation.helpers.arrayEquals(previous.old, value) || previous.old === value) { + if ( previous.old === value ) { return previous.valid; } @@ -2932,25 +2932,6 @@ $.extend(true, laravelValidation, { return array_diff(arr1, arr2); }, - /** - * Check whether two arrays are equal to one another. - * - * @param arr1 - * @param arr2 - * @returns {*} - */ - arrayEquals: function (arr1, arr2) { - if (! $.isArray(arr1) || ! $.isArray(arr2)) { - return false; - } - - if (arr1.length !== arr2.length) { - return false; - } - - return $.isEmptyObject(this.arrayDiff(arr1, arr2)); - }, - /** * Makes element dependant from other. * @@ -3018,7 +2999,7 @@ $.extend(true, laravelValidation, { * @returns {RegExp} */ regexFromWildcard: function(name) { - var nameParts = name.split("[*]"); + var nameParts = name.split("[#]"); if (nameParts.length === 1) { nameParts.push(''); } diff --git a/src/Exceptions/PropertyNotFoundException.php b/src/Exceptions/PropertyNotFoundException.php index 73fa9261..1d56b82b 100644 --- a/src/Exceptions/PropertyNotFoundException.php +++ b/src/Exceptions/PropertyNotFoundException.php @@ -1,6 +1,6 @@ app = $app; - $this->setOptions($options); - } + /** + * The application instance. + * + * @var \Illuminate\Container\Container + */ + protected $app; - /** - * @param $options - * @return void - */ - protected function setOptions($options) - { - $options['disable_remote_validation'] = empty($options['disable_remote_validation']) ? false : $options['disable_remote_validation']; - $options['view'] = empty($options['view']) ? 'jsvalidation:bootstrap' : $options['view']; - $options['form_selector'] = empty($options['form_selector']) ? 'form' : $options['form_selector']; + /** + * Configuration options. + * + * @var array + */ + protected $options; - $this->options = $options; - } + /** + * Create a new Validator factory instance. + * + * @param \Illuminate\Container\Container $app + * @param array $options + */ + public function __construct($app, array $options = []) + { + $this->app = $app; + $this->setOptions($options); + } - /** - * Creates JsValidator instance based on rules and message arrays. - * - * @param array $rules - * @param array $messages - * @param array $customAttributes - * @param null|string $selector - * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator - */ - public function make(array $rules, array $messages = [], array $customAttributes = [], $selector = null) - { - $validator = $this->getValidatorInstance($rules, $messages, $customAttributes); + /** + * @param $options + * + * @return void + */ + protected function setOptions($options) + { + $options['disable_remote_validation'] = empty($options['disable_remote_validation']) ? false : $options['disable_remote_validation']; + $options['view'] = empty($options['view']) ? 'jsvalidation:bootstrap' : $options['view']; + $options['form_selector'] = empty($options['form_selector']) ? 'form' : $options['form_selector']; - return $this->validator($validator, $selector); - } + $this->options = $options; + } - /** - * Get the validator instance for the request. - * - * @param array $rules - * @param array $messages - * @param array $customAttributes - * @return \Illuminate\Validation\Validator - */ - protected function getValidatorInstance(array $rules, array $messages = [], array $customAttributes = []) - { - $factory = $this->app->make(ValidationFactory::class); + /** + * Creates JsValidator instance based on rules and message arrays. + * + * @param array $rules + * @param array $messages + * @param array $customAttributes + * @param null|string $selector + * + * @return \Isrenato\JsValidation\Javascript\JavascriptValidator + */ + public function make(array $rules, array $messages = [], array $customAttributes = [], $selector = null) + { + $validator = $this->getValidatorInstance($rules, $messages, $customAttributes); + return str_replace('[#]', '[*]', $this->validator($validator, $selector)->render()); + } - $data = $this->getValidationData($rules, $customAttributes); - $validator = $factory->make($data, $rules, $messages, $customAttributes); - $validator->addCustomAttributes($customAttributes); + /** + * Get the validator instance for the request. + * + * @param array $rules + * @param array $messages + * @param array $customAttributes + * + * @return \Illuminate\Validation\Validator + */ + protected function getValidatorInstance(array $rules, array $messages = [], array $customAttributes = []) + { + $factory = $this->app->make(ValidationFactory::class); - return $validator; - } + $data = $this->getValidationData($rules, $customAttributes); + $validator = $factory->make($data, $rules, $messages, $customAttributes); + $validator->addCustomAttributes($customAttributes); - /** - * Gets fake data when validator has wildcard rules. - * - * @param array $rules - * @return array - */ - protected function getValidationData(array $rules, array $customAttributes = []) - { - $attributes = array_filter(array_keys($rules), function ($attribute) { - return $attribute !== '' && mb_strpos($attribute, '*') !== false; - }); + return $validator; + } - $attributes = array_merge(array_keys($customAttributes), $attributes); - $data = array_reduce($attributes, function ($data, $attribute) { - Arr::set($data, $attribute, true); + /** + * Gets fake data when validator has wildcard rules. + * + * @param array $rules + * + * @return array + */ + protected function getValidationData(array $rules, array $customAttributes = []) + { + $attributes = array_filter(array_keys($rules), function ($attribute) { + return $attribute !== '' && mb_strpos($attribute, '*') !== false; + }); - return $data; - }, []); + $attributes = array_merge(array_keys($customAttributes), $attributes); + $attributes = str_replace('*', '#', $attributes); + $data = array_reduce($attributes, function ($data, $attribute) { + Arr::set($data, $attribute, true); - return $data; - } + return $data; + }, []); - /** - * Creates JsValidator instance based on FormRequest. - * - * @param $formRequest - * @param null $selector - * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - public function formRequest($formRequest, $selector = null) - { - if (! is_object($formRequest)) { - $formRequest = $this->createFormRequest($formRequest); + return $data; } - $rules = method_exists($formRequest, 'rules') ? $formRequest->rules() : []; + /** + * Creates JsValidator instance based on FormRequest. + * + * @param $formRequest + * @param null $selector + * + * @return \Isrenato\JsValidation\Javascript\JavascriptValidator + * + * @throws \Illuminate\Contracts\Container\BindingResolutionException + */ + public function formRequest($formRequest, $selector = null) + { + if (!is_object($formRequest)) { + $formRequest = $this->createFormRequest($formRequest); + } - $validator = $this->getValidatorInstance($rules, $formRequest->messages(), $formRequest->attributes()); + $rules = method_exists($formRequest, 'rules') ? $formRequest->rules() : []; - return $this->validator($validator, $selector); - } + $validator = $this->getValidatorInstance($rules, $formRequest->messages(), $formRequest->attributes()); - /** - * @param string|array $class - * @return array - */ - protected function parseFormRequestName($class) - { - $params = []; - if (is_array($class)) { - $params = empty($class[1]) ? $params : $class[1]; - $class = $class[0]; + return $this->validator($validator, $selector); } - return [$class, $params]; - } - - /** - * Creates and initializes an Form Request instance. - * - * @param string $class - * @return \Illuminate\Foundation\Http\FormRequest - * - * @throws \Illuminate\Contracts\Container\BindingResolutionException - */ - protected function createFormRequest($class) - { - /* - * @var $formRequest \Illuminate\Foundation\Http\FormRequest - * @var $request Request + /** + * @param string|array $class + * + * @return array */ - list($class, $params) = $this->parseFormRequestName($class); - - $request = $this->app->__get('request'); - $formRequest = $this->app->build($class, $params); - - if ($session = $request->getSession()) { - $formRequest->setLaravelSession($session); + protected function parseFormRequestName($class) + { + $params = []; + if (is_array($class)) { + $params = empty($class[1]) ? $params : $class[1]; + $class = $class[0]; + } + + return [$class, $params]; } - $formRequest->setUserResolver($request->getUserResolver()); - $formRequest->setRouteResolver($request->getRouteResolver()); - $formRequest->setContainer($this->app); - $formRequest->query = $request->query; - return $formRequest; - } - - /** - * Creates JsValidator instance based on Validator. - * - * @param \Illuminate\Validation\Validator $validator - * @param null|string $selector - * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator - */ - public function validator(Validator $validator, $selector = null) - { - return $this->jsValidator($validator, $selector); - } + /** + * Creates and initializes an Form Request instance. + * + * @param string $class + * + * @return \Illuminate\Foundation\Http\FormRequest + * + * @throws \Illuminate\Contracts\Container\BindingResolutionException + */ + protected function createFormRequest($class) + { + /* + * @var $formRequest \Illuminate\Foundation\Http\FormRequest + * @var $request Request + */ + list($class, $params) = $this->parseFormRequestName($class); + + $request = $this->app->__get('request'); + $formRequest = $this->app->build($class, $params); + + if ($session = $request->getSession()) { + $formRequest->setLaravelSession($session); + } + $formRequest->setUserResolver($request->getUserResolver()); + $formRequest->setRouteResolver($request->getRouteResolver()); + $formRequest->setContainer($this->app); + $formRequest->query = $request->query; + + return $formRequest; + } - /** - * Creates JsValidator instance based on Validator. - * - * @param \Illuminate\Validation\Validator $validator - * @param null|string $selector - * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator - */ - protected function jsValidator(Validator $validator, $selector = null) - { - $remote = ! $this->options['disable_remote_validation']; - $view = $this->options['view']; - $selector = is_null($selector) ? $this->options['form_selector'] : $selector; + /** + * Creates JsValidator instance based on Validator. + * + * @param \Illuminate\Validation\Validator $validator + * @param null|string $selector + * + * @return \Isrenato\JsValidation\Javascript\JavascriptValidator + */ + public function validator(Validator $validator, $selector = null) + { + return $this->jsValidator($validator, $selector); + } - $delegated = new DelegatedValidator($validator, new ValidationRuleParserProxy()); - $rules = new RuleParser($delegated, $this->getSessionToken()); - $messages = new MessageParser($delegated); + /** + * Creates JsValidator instance based on Validator. + * + * @param \Illuminate\Validation\Validator $validator + * @param null|string $selector + * + * @return \Proengsoft\JsValidation\Javascript\JavascriptValidator + */ + protected function jsValidator(Validator $validator, $selector = null) + { + $remote = !$this->options['disable_remote_validation']; + $view = $this->options['view']; + $selector = is_null($selector) ? $this->options['form_selector'] : $selector; - $jsValidator = new ValidatorHandler($rules, $messages); + $delegated = new DelegatedValidator($validator, new ValidationRuleParserProxy()); + $rules = new RuleParser($delegated, $this->getSessionToken()); + $messages = new MessageParser($delegated); - $manager = new JavascriptValidator($jsValidator, compact('view', 'selector', 'remote')); + $jsValidator = new ValidatorHandler($rules, $messages); - return $manager; - } + $manager = new JavascriptValidator($jsValidator, compact('view', 'selector', 'remote')); - /** - * Get and encrypt token from session store. - * - * @return null|string - */ - protected function getSessionToken() - { - $token = null; - if ($session = $this->app->__get('session')) { - $token = $session->token(); + return $manager; } - if ($encrypter = $this->app->__get('encrypter')) { - $token = $encrypter->encrypt($token); + /** + * Get and encrypt token from session store. + * + * @return null|string + */ + protected function getSessionToken() + { + $token = null; + if ($session = $this->app->__get('session')) { + $token = $session->token(); + } + + if ($encrypter = $this->app->__get('encrypter')) { + $token = $encrypter->encrypt($token); + } + + return $token; } - - return $token; } -} diff --git a/src/Remote/Resolver.php b/src/Remote/Resolver.php index 78a62d2a..41bbc078 100644 --- a/src/Remote/Resolver.php +++ b/src/Remote/Resolver.php @@ -1,11 +1,11 @@ setFacadeApplication($app); - $data = $facade->getFacadeRoot(); - - $this->assertEquals($expected, $data); - - /* - |------------------------------------------------------------ - | Cleanup - |------------------------------------------------------------ - */ - - $facade->setFacadeApplication(null); - unset($app); - unset($facade); - } -} diff --git a/tests/Javascript/JavascriptRulesTraitTest.php b/tests/Javascript/JavascriptRulesTraitTest.php deleted file mode 100644 index 2de52a14..00000000 --- a/tests/Javascript/JavascriptRulesTraitTest.php +++ /dev/null @@ -1,166 +0,0 @@ -mockTrait = $this->getMockForTrait(\Proengsoft\JsValidation\Javascript\JavascriptRulesTrait::class); - - $this->mockTrait->expects($this->any()) - ->method('getAttributeName') - ->will($this->returnArgument(0)); - } - - public function testRuleConfirmed() - { - $values = $this->callProtected('ruleConfirmed','field'); - $expected = ['field_confirmation', ['field']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleAfterDate() - { - $date = "10 September 2000"; - $values = $this->callProtected('ruleAfter','field',[$date]); - - $expected = ['field', [strtotime($date)]]; - - $this->assertEquals($expected,$values); - } - - public function testRuleAfterAttribute() - { - $date = "field2"; - $values = $this->callProtected('ruleAfter','field',[$date]); - - $expected = ['field', [$date]]; - - $this->assertEquals($expected,$values); - } - - public function testRuleBeforeDate() - { - $date = "10 September 2000"; - $values = $this->callProtected('ruleBefore','field',[$date]); - - $expected = ['field', [strtotime($date)]]; - - $this->assertEquals($expected,$values); - } - - public function testRuleBeforeAttribute() - { - $date = "field2"; - $values = $this->callProtected('ruleBefore','field',[$date]); - - $expected = ['field', [$date]]; - - $this->assertEquals($expected,$values); - } - - public function testRuleSame() - { - $values = $this->callProtected('ruleSame','field',['field2']); - $expected = ['field', ['field2']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleDifferent() - { - $values = $this->callProtected('ruleDifferent','field',['field2']); - $expected = ['field', ['field2']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleRequiredWith() - { - $values = $this->callProtected('ruleRequiredWith','field',['field2','field3']); - $expected = ['field', ['field2','field3']]; - - $this->assertEquals($expected,$values); - } - - - public function testRuleRequiredWithAll() - { - $values = $this->callProtected('ruleRequiredWithAll','field',['field2','field3']); - $expected = ['field', ['field2','field3']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleRequiredWithout() - { - $values = $this->callProtected('ruleRequiredWithout','field',['field2','field3']); - $expected = ['field', ['field2','field3']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleRequiredWithoutAll() - { - $values = $this->callProtected('ruleRequiredWithoutAll','field',['field2','field3']); - $expected = ['field', ['field2','field3']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleRequiredIf() - { - $values = $this->callProtected('ruleRequiredIf','field',['field2']); - $expected = ['field', ['field2']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleRequiredUnless() - { - $values = $this->callProtected('ruleRequiredUnless','field',['field2']); - $expected = ['field', ['field2']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleInArray() - { - $values = $this->callProtected('ruleInArray','field',['field.*']); - $expected = ['field', ['field.*']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleDistinct() - { - $values = $this->callProtected('ruleDistinct','field',[]); - $expected = ['field', ['field']]; - - $this->assertEquals($expected,$values); - } - - public function testRuleDimensions() - { - $values = $this->callProtected('ruleDimensions','field',['min_width=100','ratio=16/9']); - $expected = ['field', null]; - - $this->assertEquals($expected,$values); - } - - protected function callProtected($method, $attribute, $parameters = []) - { - $caller = function ($method, $attribute, $parameters) { - return $this->$method($attribute, $parameters); - }; - - $testCaller = $caller->bindTo($this->mockTrait, $this->mockTrait); - return $testCaller($method, $attribute, $parameters); - } -} diff --git a/tests/Javascript/JavascriptValidatorTest.php b/tests/Javascript/JavascriptValidatorTest.php deleted file mode 100644 index 723e8cdc..00000000 --- a/tests/Javascript/JavascriptValidatorTest.php +++ /dev/null @@ -1,295 +0,0 @@ -getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->getMock(); - - View::shouldReceive('make') - ->with('jsvalidation::bootstrap',['validator'=>['selector'=>'form']]) - ->once() - ->andReturn( - m::mock('Illuminate\Contracts\View\Factory') - ->shouldReceive('render') - ->once() - ->andReturn('return') - ->getMock()); - - - $validator = new JavascriptValidator($mockHandler); - - $txt=$validator->render(); - $this->assertEquals('return',$txt); - } - - public function testCustomOptions() - { - - $options = [ - 'selector' => 'form-test', - 'view' => 'jsvalidation::test', - 'remote' => false, - ]; - - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->getMock(); - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with($options['remote']); - View::shouldReceive('make') - ->with($options['view'],['validator'=>['selector'=>$options['selector']]]) - ->once() - ->andReturn( - m::mock('Illuminate\Contracts\View\Factory') - ->shouldReceive('render') - ->once() - ->andReturn('return') - ->getMock()); - - - $validator = new JavascriptValidator($mockHandler, $options); - - $txt=$validator->render(); - $this->assertEquals('return',$txt); - } - - public function testToArray() - { - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->setMethods(['validationData','setRemote']) - ->getMock(); - - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with(true) - ->willReturn([]); - - $mockHandler->expects($this->once()) - ->method('validationData') - ->with() - ->willReturn([]); - - $validator = new JavascriptValidator($mockHandler); - - $expected=['selector'=>'form']; - $viewData=$validator->toArray(); - $this->assertEquals($expected,$viewData); - } - - public function testGet() - { - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->setMethods(['validationData','setRemote']) - ->getMock(); - - $mockHandler->expects($this->once()) - ->method('validationData') - ->with() - ->willReturn([]); - - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with(true) - ->willReturn([]); - - - $validator = new JavascriptValidator($mockHandler); - - $this->assertEquals('form',$validator->selector); - } - - public function testGetException() - { - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->setMethods(['validationData','setRemote']) - ->getMock(); - - $mockHandler->expects($this->once()) - ->method('validationData') - ->with() - ->willReturn([]); - - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with(true) - ->willReturn([]); - - $validator = new JavascriptValidator($mockHandler); - - try { - $validator->property_not_found; - } - catch (PropertyNotFoundException $expected) { - $this->assertTrue(true); - return; - } - - $this->fail('An expected exception has not been raised.'); - } - - public function testIgnore() - { - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->setMethods(['validationData','setRemote']) - ->getMock(); - - $mockHandler->expects($this->once()) - ->method('validationData') - ->with() - ->willReturn([]); - - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with(true) - ->willReturn([]); - - $validator = new JavascriptValidator($mockHandler); - $validator->ignore('#no-validate'); - $expected=[ - 'selector'=>'form', - 'ignore' => '#no-validate' - ]; - $viewData=$validator->toArray(); - $this->assertEquals($expected,$viewData); - } - - public function testRemote() - { - $remote = true; - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->setMethods(['validationData','setRemote']) - ->getMock(); - - $mockHandler->expects($this->once()) - ->method('validationData') - ->with() - ->willReturn([]); - - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with($remote) - ->willReturn([]); - - $validator = new JavascriptValidator($mockHandler); - $validator->remote($remote); - $data = $validator->toArray(); - - $this->assertEquals(['selector'=>'form'],$data); - } - - public function testSometimes() - { - $remote = true; - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->setMethods(['validationData','sometimes','setRemote']) - ->getMock(); - - $mockHandler->expects($this->once()) - ->method('sometimes') - ->with('field','required') - ->willReturn([]); - - $mockHandler->expects($this->once()) - ->method('validationData') - ->with() - ->willReturn([]); - $mockHandler->expects($this->once()) - ->method('setRemote') - ->with($remote) - ->willReturn([]); - - $validator = new JavascriptValidator($mockHandler); - //$validator->remote(true); - $validator->sometimes('field','required'); - $data = $validator->toArray(); - $this->assertEquals(['selector'=>'form'],$data); - } - - public function testToString() - { - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->getMock(); - - View::shouldReceive('make') - ->with('jsvalidation::bootstrap', ['validator' => ['selector' => 'form']]) - ->once() - ->andReturn( - m::mock('Illuminate\Contracts\View\Factory') - ->shouldReceive('render') - ->once() - ->andReturn('return') - ->getMock()); - - - $validator = new JavascriptValidator($mockHandler); - - $txtRender = $validator->render(); - $txt = $validator->__toString(); - $this->assertEquals($txtRender, $txt); - } - - function store_error($error_number, $error_message) - { - $this->_last_error_number = $error_number; - $this->_last_error_message = $error_message; - } - - function assertError($error_message, $error_number = E_USER_ERROR) - { - $this->assertSame($error_message, $this->_last_error_message); - $this->assertSame($error_number, $this->_last_error_number); - } - - public function testToStringException() - { - set_error_handler([$this, 'store_error']); - $exception = new \Exception("Simulated exception for Testing"); - - $mockHandler = $this->getMockBuilder(ValidatorHandler::class) - ->disableOriginalConstructor() - ->getMock(); - $mockHandler->expects($this->once()) - ->method('validationData') - ->willThrowException($exception); - - View::shouldReceive('make') - ->with('jsvalidation::bootstrap', ['validator' => ['selector' => 'form']]) - ->once() - ->andReturn( - m::mock('Illuminate\Contracts\View\Factory') - ->shouldReceive('render') - ->once() - ->andReturn('return') - ->getMock()); - - $validator = new JavascriptValidator($mockHandler); - - $validator->__toString(); - $this->assertError($exception->__toString()); - } -} diff --git a/tests/Javascript/MessageParserTest.php b/tests/Javascript/MessageParserTest.php deleted file mode 100644 index fcbf932c..00000000 --- a/tests/Javascript/MessageParserTest.php +++ /dev/null @@ -1,129 +0,0 @@ -getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated->expects($this->once()) - ->method('getData') - ->willReturn($data); - - $delegated->expects($this->once()) - ->method('setData') - ->with($data); - - $delegated->expects($this->once()) - ->method('getMessage') - ->with($attribute,$rule) - ->willReturn("$attribute $rule"); - - $delegated->expects($this->once()) - ->method('makeReplacements') - ->with("$attribute $rule",$attribute,$rule, $params) - ->willReturn("$attribute $rule"); - - $parser = new MessageParser($delegated); - - $message = $parser->getMessage($attribute,$rule,$params); - - $this->assertEquals("$attribute $rule", $message); - } - - public function testGetMessageRequiredIf() - { - - $attribute = 'field'; - $rule = 'RequiredIf'; - $params=['field2','value2']; - $data = []; - $files = []; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated->expects($this->once()) - ->method('getData') - ->willReturn($data); - - $delegated->expects($this->exactly(2)) - ->method('setData') - ->with($this->logicalOr( - $this->equalTo([$params[0]=>$params[1]]), - $this->equalTo($data) - )); - - - $delegated->expects($this->once()) - ->method('getMessage') - ->with($attribute,$rule) - ->willReturn("$attribute $rule"); - - $delegated->expects($this->once()) - ->method('makeReplacements') - ->with("$attribute $rule",$attribute,$rule, $params) - ->willReturn("$attribute $rule"); - - $parser = new MessageParser($delegated); - - $message = $parser->getMessage($attribute,$rule,$params); - - $this->assertEquals("$attribute $rule", $message); - } - - public function testGetMessageFiles() - { - - $attribute = 'field'; - $rule = 'Image'; - $params=[]; - $data = []; - $files = []; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated->expects($this->once()) - ->method('getData') - ->willReturn($data); - - - $delegated->expects($this->once()) - ->method('hasRule') - ->with($attribute, ['Mimes', 'Image']) - ->willReturn(true); - - - $delegated->expects($this->once()) - ->method('getMessage') - ->with($attribute,$rule) - ->willReturn("$attribute $rule"); - - $delegated->expects($this->once()) - ->method('makeReplacements') - ->with("$attribute $rule",$attribute,$rule, $params) - ->willReturn("$attribute $rule"); - - $parser = new MessageParser($delegated); - - $message = $parser->getMessage($attribute,$rule,$params); - - $this->assertEquals("$attribute $rule", $message); - } -} diff --git a/tests/Javascript/RuleParserTest.php b/tests/Javascript/RuleParserTest.php deleted file mode 100644 index b0534307..00000000 --- a/tests/Javascript/RuleParserTest.php +++ /dev/null @@ -1,174 +0,0 @@ -getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - - $parser = new RuleParser($delegated, $token); - - $values = $parser->getRule($attribute, $rule, $parameters,'required'); - $expected = [$attribute,RuleParser::JAVASCRIPT_RULE,$parameters]; - - $this->assertEquals($expected, $values); - } - - public function testGetClientCustomRule() - { - $attribute = 'field'; - $rule = 'RequiredIf'; - $parameters = ['field2','value2']; - $token =null; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - - $parser = new RuleParser($delegated, $token); - - $values = $parser->getRule($attribute, $rule, $parameters, 'required_if:field2,value2'); - $expected = [$attribute,RuleParser::JAVASCRIPT_RULE,$parameters]; - - $this->assertEquals($expected, $values); - } - - public function testGetRemoteRule() - { - $attribute = 'field'; - $rule = 'ActiveUrl'; - $parameters = []; - $token ='my token'; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - - $parser = new RuleParser($delegated, $token); - - $values = $parser->getRule($attribute, $rule, $parameters,'active_url'); - $expected = [$attribute,RuleParser::REMOTE_RULE,[$attribute, $token, false]]; - - $this->assertEquals($expected, $values); - } - - public function testGetRemoteRuleArray() - { - $attribute = 'field.name.array'; - $attributeHtml = 'field[name][array]'; - $rule = 'ActiveUrl'; - $parameters = []; - $token ='my token'; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - - $parser = new RuleParser($delegated, $token); - - $values = $parser->getRule($attribute, $rule, $parameters,'active_url'); - $expected = [$attributeHtml,RuleParser::REMOTE_RULE,[$attributeHtml, $token, false]]; - - $this->assertEquals($expected, $values); - } - - public function testGetRules() - { - $expects = ['somefield'=>'required']; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated->expects($this->once()) - ->method('getRules') - ->willReturn($expects); - - - $parser = new RuleParser($delegated, null); - - $this->assertEquals($expects, $parser->getValidatorRules()); - } - - public function testGetRuleWithAttributeArray() - { - $attribute = 'field.key'; - $rule = 'Required'; - $parameters = []; - $token =null; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - - $parser = new RuleParser($delegated, $token); - - $values = $parser->getRule($attribute, $rule, $parameters,'required'); - $expected = ['field[key]',RuleParser::JAVASCRIPT_RULE,$parameters]; - - $this->assertEquals($expected, $values); - } - - public function testAddConditionalRules() - { - $attribute = 'field'; - $rule = 'Required'; - $parameters = []; - $token ='my token'; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated->expects($this->once()) - ->method('explodeRules') - ->with(['required']) - ->willReturn([['required']]); - - $parser = new RuleParser($delegated, $token); - - $parser->addConditionalRules($attribute,'required'); - $values = $parser->getRule($attribute, $rule, $parameters,'required'); - $expected = [$attribute,RuleParser::REMOTE_RULE,[$attribute, $token, true]]; - - $this->assertEquals($expected, $values); - } - - public function testParseNamedParameters() - { - $parameters = ['min_height=100','ratio=1/3']; - $token =null; - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - - $parser = new RuleParser($delegated, $token); - - $values = $parser->parseNamedParameters($parameters); - $expected = [ - 'min_height' =>100, - 'ratio' => '1/3', - ]; - - $this->assertEquals($expected, $values); - } -} diff --git a/tests/Javascript/ValidatorHandlerTest.php b/tests/Javascript/ValidatorHandlerTest.php deleted file mode 100644 index 5421f0e6..00000000 --- a/tests/Javascript/ValidatorHandlerTest.php +++ /dev/null @@ -1,234 +0,0 @@ -['required','array']]; - - $mockDelegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->setMethods(['getRules','hasRule','parseRule','getRule','isImplicit']) - ->getMock(); - - $mockDelegated->expects($this->any()) - ->method('getRules') - ->willReturn([$attribute=>[$rule]]); - - $mockDelegated->expects($this->any()) - ->method('hasRule') - ->with($attribute, ValidatorHandler::JSVALIDATION_DISABLE) - ->willReturn(false); - - $mockDelegated->expects($this->once()) - ->method('parseRule') - ->with($rule) - ->willReturn(['RequiredIf',['field2','value2']]); - - $mockDelegated->expects($this->once()) - ->method('isImplicit') - ->with('RequiredIf') - ->willReturn(false); - - - $mockRule = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\RuleParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $mockRule->expects($this->once()) - ->method('getRule') - ->with($attribute, 'RequiredIf', ['field2','value2']) - ->willReturn([$attribute, RuleParser::JAVASCRIPT_RULE, ['field2','value2']]); - - $mockMessages = $this->getMockBuilder('Proengsoft\JsValidation\Javascript\MessageParser') - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $mockMessages->expects($this->once()) - ->method('getMessage') - ->with($attribute, 'RequiredIf', ['field2','value2']) - ->willReturn('Field is required if'); - - - $handler = new ValidatorHandler($mockRule, $mockMessages); - $handler->setDelegatedValidator($mockDelegated); - - $data = $handler->validationData(); - $expected = [ - 'rules' => ['field'=>['laravelValidation'=>[['RequiredIf',['field2','value2'],'Field is required if',false]]]], - 'messages' => [], - ]; - - $this->assertEquals($expected, $data); - } - - public function testValidationDataDisabled() - { - $attribute = 'field'; - $rule = 'required_if:field2,value2|no_js_validation'; - - $rules = ['field'=>['required','array']]; - - $mockDelegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->setMethods(['getRules','hasRule','parseRule','getRule','isImplicit']) - ->getMock(); - - $mockDelegated->expects($this->any()) - ->method('getRules') - ->willReturn([$attribute=>explode('|',$rule)]); - - $mockDelegated->expects($this->any()) - ->method('hasRule') - ->with($attribute, ValidatorHandler::JSVALIDATION_DISABLE) - ->willReturn(true); - - $mockRule = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\RuleParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $mockMessages = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\MessageParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - - $handler = new ValidatorHandler($mockRule, $mockMessages); - $handler->setDelegatedValidator($mockDelegated); - - $data = $handler->validationData(); - $expected = [ - 'rules' => [], - 'messages' => [], - ]; - - $this->assertEquals($expected, $data); - } - - public function testSometimes() - { - $attribute = 'field'; - $rule = 'required_if:field2,value2'; - - $mockDelegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->setMethods(['getRules','hasRule','parseRule','getRule','isImplicit','sometimes','explodeRules']) - ->getMock(); - - $mockDelegated->expects($this->once()) - ->method('sometimes') - ->willReturn(null); - - - $mockDelegated->expects($this->any()) - ->method('getRules') - ->willReturn([$attribute=>[$rule]]); - - $mockDelegated->expects($this->any()) - ->method('hasRule') - ->with($attribute, ValidatorHandler::JSVALIDATION_DISABLE) - ->willReturn(false); - - $mockDelegated->expects($this->once()) - ->method('parseRule') - ->with($rule) - ->willReturn(['RequiredIf',['field2','value2']]); - - $mockDelegated->expects($this->once()) - ->method('isImplicit') - ->with('RequiredIf') - ->willReturn(false); - - - $mockRule = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\RuleParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $mockRule->expects($this->once()) - ->method('getRule') - ->with($attribute, 'RequiredIf', ['field2','value2']) - ->willReturn([$attribute, RuleParser::REMOTE_RULE, ['field2','value2']]); - - $mockMessages = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\MessageParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $mockMessages->expects($this->once()) - ->method('getMessage') - ->with($attribute, 'RequiredIf', ['field2','value2']) - ->willReturn('Field is required if'); - - - $handler = new ValidatorHandler($mockRule, $mockMessages); - $handler->setDelegatedValidator($mockDelegated); - $handler->sometimes($attribute, $rule); - - $data = $handler->validationData(); - $expected = [ - 'rules' => ['field'=>['laravelValidationRemote'=>[['RequiredIf',['field2','value2'],'Field is required if',false]]]], - 'messages' => [], - ]; - - $this->assertEquals($expected, $data); - } - - public function testDisableRemote() - { - $attribute = 'field'; - $rule = 'active_url'; - - $mockDelegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->setMethods(['getRules','hasRule','parseRule','getRule','isImplicit','sometimes','explodeRules']) - ->getMock(); - - $mockDelegated->expects($this->any()) - ->method('getRules') - ->willReturn([$attribute=>[$rule]]); - - $mockDelegated->expects($this->any()) - ->method('hasRule') - ->with($attribute, ValidatorHandler::JSVALIDATION_DISABLE) - ->willReturn(false); - - $mockDelegated->expects($this->once()) - ->method('parseRule') - ->with($rule) - ->willReturn(['ActiveUrl',['token',false,false]]); - - $mockRule = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\RuleParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $mockRule->expects($this->once()) - ->method('getRule') - ->with($attribute, 'ActiveUrl', ['token',false,false]) - ->willReturn([$attribute, RuleParser::REMOTE_RULE, ['token',false,false]]); - - $mockMessages = $this->getMockBuilder(\Proengsoft\JsValidation\Javascript\MessageParser::class) - ->setConstructorArgs([$mockDelegated] ) - ->getMock(); - - $handler = new ValidatorHandler($mockRule, $mockMessages); - $handler->setDelegatedValidator($mockDelegated); - $handler->setRemote(false); - //$handler->sometimes($attribute, $rule); - - $data = $handler->validationData(); - $expected = [ - 'rules' => [], - 'messages' => [], - ]; - - $this->assertEquals($expected, $data); - } -} diff --git a/tests/JsValidationServiceProviderTest.php b/tests/JsValidationServiceProviderTest.php deleted file mode 100644 index f6b0a2c4..00000000 --- a/tests/JsValidationServiceProviderTest.php +++ /dev/null @@ -1,162 +0,0 @@ -getMockForAbstractClass(\Illuminate\Contracts\Config\Repository::class, [],'',false); - $mockedConfig->expects($this->once()) - ->method('get') - ->with('jsvalidation.disable_remote_validation') - ->will($this->returnValue(true)); - $app['config']=$mockedConfig; - - $mockedValidator = $this->getMockForAbstractClass(\Illuminate\Contracts\Validation\Factory::class, [],'',false); - $mockedValidator->expects($this->once()) - ->method('extend') - ->will($this->returnValue(null)); - - $app['validator'] = $mockedValidator; - - $mock = $this->getMockBuilder(\Proengsoft\JsValidation\JsValidationServiceProvider::class) - ->setMethods(['loadViewsFrom','publishes','mergeConfigFrom']) - ->setConstructorArgs([$app]) - ->getMock(); - - return $mock; - } - - public function testBootstrapConfigs() - { - $app = []; - $app['path.config']=dirname(__FILE__.'/../config'); - $app['path.base']=dirname(__FILE__.'/../'); - $app['path.public']=dirname(__FILE__.'/../public'); - - $mock = $this->getMockedService($app); - - $mock->expects($this->at(1)) - ->method('publishes') - ->with([realpath(__DIR__.'/../config/jsvalidation.php')=>$app['path.config'].'/jsvalidation.php'], 'config'); - - $mock->boot(); - } - - public function testBootstrapViews() - { - $app = []; - $app['path.config']=dirname(__FILE__.'/../config'); - $app['path.base']=dirname(__FILE__.'/../'); - $app['path.public']=dirname(__FILE__.'/../public'); - - $mock = $this->getMockedService($app); - - $mock->expects($this->once()) - ->method('loadViewsFrom') - ->with(realpath(__DIR__.'/../resources/views'), 'jsvalidation'); - - - $mock->expects($this->at(3)) - ->method('publishes') - ->with( - [realpath(__DIR__.'/../resources/views')=>$app['path.base'].'/resources/views/vendor/jsvalidation'], - 'views' - ); - - $mock->boot(); - } - - public function testPublishAssets() - { - $app = []; - $app['path.config']=dirname(__FILE__.'/../config'); - $app['path.base']=dirname(__FILE__.'/../'); - $app['path.public']=dirname(__FILE__.'/../public'); - - $mock = $this->getMockedService($app); - - $mock->expects($this->at(4)) - ->method('publishes') - ->with( - [realpath(__DIR__.'/../public')=>$app['path.public'].'/vendor/jsvalidation'], - 'public' - ); - - $mock->boot(); - - } - - public function testPushMiddleware() - { - $app = []; - $app['path.config']=dirname(__FILE__.'/../config'); - $app['path.base']=dirname(__FILE__.'/../'); - $app['path.public']=dirname(__FILE__.'/../public'); - - $mockedConfig = $this->getMockForAbstractClass(\Illuminate\Contracts\Config\Repository::class, [],'',false); - $mockedConfig->expects($this->once()) - ->method('get') - ->with('jsvalidation.disable_remote_validation') - ->will($this->returnValue(false)); - $app['config']=$mockedConfig; - - $mockedValidator = $this->getMockForAbstractClass(\Illuminate\Contracts\Validation\Factory::class, [],'',false); - $mockedValidator->expects($this->once()) - ->method('extend') - ->will($this->returnValue(null)); - - $app['validator'] = $mockedValidator; - - - $mockKernel = $this->getMockForAbstractClass(\Illuminate\Contracts\Http\Kernel::class, [],'',true,true,true,['pushMiddleware']); - - $app[\Illuminate\Contracts\Http\Kernel::class] = $mockKernel; - - $mock = $this->getMockBuilder(\Proengsoft\JsValidation\JsValidationServiceProvider::class) - ->setConstructorArgs([$app]) - ->setMethods(['loadViewsFrom','publishes','mergeConfigFrom']) - ->getMock(); - - $mock->boot(); - - } - - public function testRegister() - { - $app = $this->getMockBuilder(\Illuminate\Contracts\Container\Container::class) - ->getMock(); - - $app->expects($this->once()) - ->method('singleton') - ->with('jsvalidator', $this->isInstanceOf(\Closure::class)) - ->willReturnCallback(function($name, $callback) { - $mockedConfig = $this->getMockForAbstractClass(\Illuminate\Contracts\Config\Repository::class, [],'',false); - $mockedConfig->expects($this->once()) - ->method('get') - ->with('jsvalidation') - ->will($this->returnValue([])); - - $newApp['config'] = $mockedConfig; - - $factory = $callback($newApp); - $this->assertInstanceOf(\Proengsoft\JsValidation\JsValidatorFactory::class, $factory); - }); - - - $mock = $this->getMockBuilder(\Proengsoft\JsValidation\JsValidationServiceProvider::class) - ->setConstructorArgs([$app]) - ->setMethods(['loadViewsFrom','publishes','mergeConfigFrom']) - ->getMock(); - - $mock->register(); - } - - public function testExtendValidator() - { - - } -} diff --git a/tests/JsValidatorFactoryTest.php b/tests/JsValidatorFactoryTest.php deleted file mode 100644 index 16b4c0fa..00000000 --- a/tests/JsValidatorFactoryTest.php +++ /dev/null @@ -1,261 +0,0 @@ -getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->setMethods(['addCustomAttributes']) - ->getMock(); - - $mockValidator->expects($this->once()) - ->method('addCustomAttributes') - ->with($customAttributes); - - $mockFactory = $this->getMockBuilder(\Illuminate\Contracts\Validation\Factory::class) - ->disableOriginalConstructor() - ->setMethods(['make','extend','extendImplicit','replacer']) - ->getMock(); - - $mockFactory->expects($this->once()) - ->method('make') - ->with($data, $rules, $messages, $customAttributes) - ->willReturn($mockValidator); - - - $app = $this->getMockBuilder(\Illuminate\Container\Container::class) - ->getMock(); - $app->expects($this->once()) - ->method('make') - ->with(\Illuminate\Contracts\Validation\Factory::class) - ->willReturn($mockFactory); - - return $app; - } - - public function testMake() - { - $rules=['name'=>'required']; - $messages = []; - $customAttributes = []; - $selector = null; - - $app = $this->mockedApp($rules, $messages, $customAttributes); - - $app->expects($this->at(1)) - ->method('__get') - ->with('session') - ->willReturn(null); - - $app->expects($this->at(2)) - ->method('__get') - ->with('encrypter') - ->willReturn(null); - - $options['disable_remote_validation'] = false; - $options['view'] = 'jsvalidation::bootstrap'; - $options['form_selector'] = 'form'; - - $factory = new JsValidatorFactory($app, $options); - - $jsValidator = $factory->make($rules, $messages, $customAttributes, $selector); - - $this->assertInstanceOf(\Proengsoft\JsValidation\Javascript\JavascriptValidator::class, $jsValidator); - } - - public function testMakeArrayRules() - { - $rules=['name.*'=>'required']; - $data['name']['*']=true; - $messages = []; - $customAttributes = []; - $selector = null; - - $app = $this->mockedApp($rules, $messages, $customAttributes, $data); - - $app->expects($this->at(1)) - ->method('__get') - ->with('session') - ->willReturn(null); - - $app->expects($this->at(2)) - ->method('__get') - ->with('encrypter') - ->willReturn(null); - - $options['disable_remote_validation'] = false; - $options['view'] = 'jsvalidation::bootstrap'; - $options['form_selector'] = 'form'; - - $factory = new JsValidatorFactory($app, $options); - - $jsValidator = $factory->make($rules, $messages, $customAttributes, $selector); - - $this->assertInstanceOf(\Proengsoft\JsValidation\Javascript\JavascriptValidator::class, $jsValidator); - } - - public function testMakeArrayRulesAndAttributes() - { - $rules=['name.*'=>'required']; - $data['name']['*']=true; - $data['name']['key0']=true; - $messages = []; - $customAttributes = ['name.*'=>'Name', 'name.key0'=>'Name Key 0']; - $selector = null; - - $app = $this->mockedApp($rules, $messages, $customAttributes, $data); - - $app->expects($this->at(1)) - ->method('__get') - ->with('session') - ->willReturn(null); - - $app->expects($this->at(2)) - ->method('__get') - ->with('encrypter') - ->willReturn(null); - - $options['disable_remote_validation'] = false; - $options['view'] = 'jsvalidation::bootstrap'; - $options['form_selector'] = 'form'; - - $factory = new JsValidatorFactory($app, $options); - - $jsValidator = $factory->make($rules, $messages, $customAttributes, $selector); - - $this->assertInstanceOf(\Proengsoft\JsValidation\Javascript\JavascriptValidator::class, $jsValidator); - } - - public function testMakeWithToken() - { - $rules=['name'=>'required']; - $messages = []; - $customAttributes = []; - $selector = null; - - $sessionMock = $this->getMockBuilder('stdObject') - ->setMethods(['token']) - ->getMock(); - $sessionMock->expects($this->once()) - ->method('token') - ->willReturn('token'); - - $app = $this->mockedApp($rules, $messages, $customAttributes); - - $app->expects($this->at(1)) - ->method('__get') - ->with('session') - ->willReturn($sessionMock); - - $encrypterMock = $this->getMockBuilder('stdObject') - ->setMethods(['encrypt']) - ->getMock(); - $encrypterMock->expects($this->once()) - ->method('encrypt') - ->with('token') - ->willReturn('encrypted token'); - - $app->expects($this->at(2)) - ->method('__get') - ->with('encrypter') - ->willReturn($encrypterMock); - - $options['disable_remote_validation'] = false; - $options['view'] = 'jsvalidation::bootstrap'; - $options['form_selector'] = 'form'; - - $factory = new JsValidatorFactory($app, $options); - - $jsValidator = $factory->make($rules, $messages, $customAttributes, $selector); - - $this->assertInstanceOf(\Proengsoft\JsValidation\Javascript\JavascriptValidator::class, $jsValidator); - } - - public function testCreateFromFormRequestInstance() - { - $rules=[]; - $messages = []; - $customAttributes = []; - $selector = null; - - $options['disable_remote_validation'] = false; - $options['view'] = 'jsvalidation::bootstrap'; - $options['form_selector'] = 'form'; - - $app = $this->mockedApp($rules, $messages, $customAttributes); - - $mockFormRequest=m::mock(\Illuminate\Foundation\Http\FormRequest::class); - $mockFormRequest->shouldReceive('rules')->once()->andReturn($rules); - $mockFormRequest->shouldReceive('messages')->once()->andReturn([]); - $mockFormRequest->shouldReceive('attributes')->once()->andReturn([]); - - - $factory = new JsValidatorFactory($app, $options); - - $jsValidator = $factory->formRequest($mockFormRequest, $selector); - - - $this->assertInstanceOf(\Proengsoft\JsValidation\Javascript\JavascriptValidator::class, $jsValidator); - } - - - public function testCreateFromFormRequestClassName() - { - $rules=[]; - $messages = []; - $customAttributes = []; - $selector = null; - - $options['disable_remote_validation'] = false; - $options['view'] = 'jsvalidation::bootstrap'; - $options['form_selector'] = 'form'; - - - $app = $this->mockedApp($rules, $messages, $customAttributes); - - $sessionMock = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class) - ->getMock(); - - - $mockedRequest = m::mock(\Symfony\Component\HttpFoundation\Request::class); - $mockedRequest->shouldReceive('getSession')->andReturn($sessionMock) - ->shouldReceive('getUserResolver')->andReturn(function(){}) - ->shouldReceive('getRouteResolver')->andReturn(function(){}); - - //$requestMock= $this->getMock('\Symfony\Component\HttpFoundation\Request',['getUserResolver']); - - $app->expects($this->at(0)) - ->method('__get') - ->with('request') - ->willReturn($mockedRequest); - - - $mockForm = $this->getMockForAbstractClass(\Illuminate\Foundation\Http\FormRequest::class,[],'',true,true,true,['messages','attributes']); - $mockForm->expects($this->once()) - ->method('messages') - ->willReturn([]); - $mockForm->expects($this->once()) - ->method('attributes') - ->willReturn([]); - - $app->expects($this->once()) - ->method('build') - ->with(\Proengsoft\JsValidation\Tests\StubFormRequest::class) - ->willReturn($mockForm); - - $factory = new JsValidatorFactory($app, $options); - - $jsValidator = $factory->formRequest([\Proengsoft\JsValidation\Tests\StubFormRequest::class] , $selector); - - $this->assertInstanceOf(\Proengsoft\JsValidation\Javascript\JavascriptValidator::class, $jsValidator); - } -} diff --git a/tests/Remote/ResolverTest.php b/tests/Remote/ResolverTest.php deleted file mode 100644 index 47c43e52..00000000 --- a/tests/Remote/ResolverTest.php +++ /dev/null @@ -1,97 +0,0 @@ -mockFactory = $this->getMockBuilder(\Illuminate\Validation\Factory::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->resolverObject = new Resolver($this->mockFactory); - } - - protected function getMockedTranslator() - { - $translator = $this->getMockBuilder(\Illuminate\Contracts\Translation\Translator::class) - ->getMock(); - - return $translator; - } - - public function testResolverIsClosure() - { - $resolver = $this->resolverObject->resolver('field'); - $this->assertInstanceOf('Closure', $resolver); - } - - public function testResolvesNewValidator() - { - $resolver = $this->resolverObject->resolver('field'); - - - $translator = $this->getMockedTranslator(); - $validator = $resolver($translator,[],[],[],[]); - - $this->assertInstanceOf(\Illuminate\Validation\Validator::class, $validator); - } - - public function testResolvesValidatorExists() - { - $translator = $this->getMockedTranslator(); - $resolverObject = new Resolver(new CustomValidatorStubTest($translator)); - - $resolver = $resolverObject->resolver('field'); - $translator = $this->getMockedTranslator(); - $validator = $resolver($translator,[],[],[],[]); - - $this->assertInstanceOf(\Illuminate\Validation\Validator::class, $validator); - } - - public function testValidatorIsClosure() - { - $resolver = $this->resolverObject->validatorClosure(); - $this->assertInstanceOf(\Closure::class, $resolver); - } - - public function testResolvesAndValidated() - { - $translator = $this->getMockedTranslator(); - $resolverObject = new Resolver(new CustomValidatorStubTest($translator)); - - $resolver = $resolverObject->resolver('field'); - - $translator = $this->getMockedTranslator(); - $validator = $resolver($translator, - ['field'=>'value', '_jsvalidation_validate_all'=>false], - ['field'=>'required'], - [], - [] - ); - $validator->setData(['field'=>'value', '_jsvalidation_validate_all'=>false]); - - $resolverValidator = $this->resolverObject->validatorClosure(); - - try { - $resolverValidator('_jsvalidation','field',[],$validator); - $this->fail('This test shloud throw Exception'); - } catch (\Illuminate\Validation\ValidationException $e){ - $response = $e->getResponse(); - $this->assertEquals('true',$response->getContent()); - $this->assertEquals(200, $response->getStatusCode()); - } catch (HttpResponseException $e){ - $response = $e->getResponse(); - $this->assertEquals('true',$response->getContent()); - $this->assertEquals(200, $response->getStatusCode()); - } - //$this->assertInstanceOf('Closure', $resolver); - } -} diff --git a/tests/Remote/ValidatorTest.php b/tests/Remote/ValidatorTest.php deleted file mode 100644 index ab487532..00000000 --- a/tests/Remote/ValidatorTest.php +++ /dev/null @@ -1,119 +0,0 @@ - 'active_url|required']; - $data = ['field' => 'http://www.google.com']; - $params= ['false']; - $validator = $this->getRealValidator($rules, [],$data); - - try { - $validator->validate('field',$params); - $this->fail(); - } catch (HttpResponseException $ex) { - $this->assertEquals(200, $ex->getResponse()->getStatusCode()); - $this->assertEquals('true', $ex->getResponse()->getContent()); - } - } - - public function testValidateRemoteRuleFails() - { - $rules = ['field' => 'active_url|required']; - $data = ['field' => 'http://nonexistentdomain']; - $params= ['false']; - $validator = $this->getRealValidator($rules, [],$data); - - try { - $validator->validate('field',$params); - $this->fail(); - } catch (ValidationException $ex) { - $this->assertEquals(200, $ex->getResponse()->getStatusCode()); - $this->assertEquals('["field active_url!"]', $ex->getResponse()->getContent()); - } catch (HttpResponseException $ex) { - $this->assertEquals(200, $ex->getResponse()->getStatusCode()); - $this->assertEquals('["field active_url!"]', $ex->getResponse()->getContent()); - } - } - - public function testValidateRemoteDisabled() - { - $rules = ['field' => 'active_url|required|alpha|no_js_validation']; - $data = ['field' => 'http://nonexistentdomain']; - $params= ['false']; - $validator = $this->getRealValidator($rules, [],$data); - - try { - $validator->validate('field',$params); - $this->fail(); - } catch (HttpResponseException $ex) { - $this->assertEquals(200, $ex->getResponse()->getStatusCode()); - $this->assertEquals('true', $ex->getResponse()->getContent()); - } - } - - public function testValidateRemoteAllFields() - { - $rules = ['field' => 'required|active_url|alpha']; - $data = ['field' => 'http://www.google.com']; - $params= ['true']; - $validator = $this->getRealValidator($rules, [],$data); - - try { - $validator->validate('field',$params); - $this->fail(); - } catch (ValidationException $ex) { - $this->assertEquals(200, $ex->getResponse()->getStatusCode()); - $this->assertEquals('["validation.alpha"]', $ex->getResponse()->getContent()); - } catch (HttpResponseException $ex) { - $this->assertEquals(200, $ex->getResponse()->getStatusCode()); - $this->assertEquals('["validation.alpha"]', $ex->getResponse()->getContent()); - } - } - - protected function getRealTranslator() - { - $messages = [ - 'validation.required' => ':attribute required!', - 'validation.active_url' => ':attribute active_url!' - ]; - - if (method_exists(Translator::class,'addLines')) { - $trans = new Translator( - new ArrayLoader(), 'en' - ); - $trans->addLines( $messages, 'en'); - } else { - $trans = new SymfonyTranslator('en', new MessageSelector()); - $trans->addLoader('array', new SymfonyArrayLoader()); - $trans->addResource('array', $messages , 'en', 'messages' ); - } - - return $trans; - } - - protected function getRealValidator($rules, $messages = [], $data = []) - { - $trans = $this->getRealTranslator(); - $laravelValidator = new LaravelValidator($trans, $data, $rules, $messages); - $laravelValidator->addExtension(ValidatorHandler::JSVALIDATION_DISABLE, function() { - return true; - }); - return new Validator($laravelValidator); - } -} diff --git a/tests/RemoteValidationMiddlewareTest.php b/tests/RemoteValidationMiddlewareTest.php deleted file mode 100644 index d12c2441..00000000 --- a/tests/RemoteValidationMiddlewareTest.php +++ /dev/null @@ -1,85 +0,0 @@ -getMockBuilder(\Illuminate\Contracts\Validation\Factory::class) - ->disableOriginalConstructor() - ->setMethods(['resolver','extend','make','extendImplicit','replacer']) - ->getMock(); - $mockedFactory->resolver = function(){}; - $mockedFactory->expects($this->once()) - ->method('resolver') - ->with($this->isInstanceOf(\Closure::class)); - - $mockedFactory->expects($this->once()) - ->method('extend') - ->with(Validator::EXTENSION_NAME, $this->isInstanceOf('Closure')); - - $mockedConfig = $this->getMockForAbstractClass(\Illuminate\Contracts\Config\Repository::class, [],'',false); - $mockedConfig->expects($this->once()) - ->method('get') - ->with('jsvalidation.remote_validation_field') - ->will($this->returnValue('_jsvalidation')); - - $mockedRequest = $this->getMockBuilder(\Illuminate\Http\Request::class) - ->disableOriginalConstructor() - ->setMethods(['has']) - ->getMock(); - - $mockedRequest->expects($this->once()) - ->method('has') - ->with('_jsvalidation') - ->willReturn(true); - - $stubClosure = function () {return true; }; - - $middleware = new RemoteValidationMiddleware($mockedFactory, $mockedConfig); - $result = $middleware->handle($mockedRequest, $stubClosure); - - $this->assertTrue($result); - } - - - public function testHandleShouldNotValidate() - { - $mockedFactory = $this->getMockBuilder(\Illuminate\Contracts\Validation\Factory::class) - ->disableOriginalConstructor() - ->getMock(); - - $mockedConfig = $this->getMockForAbstractClass(\Illuminate\Contracts\Config\Repository::class,[],'',false); - $mockedConfig->expects($this->once()) - ->method('get') - ->with('jsvalidation.remote_validation_field') - ->will($this->returnValue('_jsvalidation')); - - $mockedRequest = $this->getMockBuilder(\Illuminate\Http\Request::class) - ->disableOriginalConstructor() - ->setMethods(['has']) - ->getMock(); - - $mockedRequest->expects($this->once()) - ->method('has') - ->with('_jsvalidation') - ->willReturn(false); - - $stubClosure = function () {return true;}; - - $middleware = new RemoteValidationMiddleware($mockedFactory, $mockedConfig); - $result = $middleware->handle($mockedRequest, $stubClosure); - - $this->assertTrue($result); - } -} diff --git a/tests/Support/AccessProtectedTraitTest.php b/tests/Support/AccessProtectedTraitTest.php deleted file mode 100644 index 2964828b..00000000 --- a/tests/Support/AccessProtectedTraitTest.php +++ /dev/null @@ -1,63 +0,0 @@ -mockTrait = $this->getMockForTrait(\Proengsoft\JsValidation\Support\AccessProtectedTrait::class); - $this->stubInstance = new ProtectedClassStubTest(); - } - - public function testCreateProtectedCaller() - { - $stubInstance = $this->stubInstance; - $caller = function () use ($stubInstance) { - return $this->createProtectedCaller($stubInstance); - }; - - $testCaller = $caller->bindTo($this->mockTrait, $this->mockTrait); - - $this->assertInstanceOf('Closure', $testCaller()); - } - - public function testGetProtected() - { - $stubInstance = $this->stubInstance; - $caller = function () use ($stubInstance) { - return $this->getProtected($stubInstance,'protectedProperty'); - }; - - $testCaller = $caller->bindTo($this->mockTrait, $this->mockTrait); - - $this->assertTrue($testCaller()); - } - - public function testCallProtected() - { - $stubInstance = $this->stubInstance; - $caller = function () use ($stubInstance) { - return $this->callProtected($stubInstance,'protectedMethod'); - }; - - $testCaller = $caller->bindTo($this->mockTrait, $this->mockTrait); - - $this->assertTrue($testCaller()); - } -} diff --git a/tests/Support/DelegatedValidatorTest.php b/tests/Support/DelegatedValidatorTest.php deleted file mode 100644 index dab6376d..00000000 --- a/tests/Support/DelegatedValidatorTest.php +++ /dev/null @@ -1,377 +0,0 @@ -getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated = new DelegatedValidator($expected, $parser); - - $value = $delegated->getValidator(); - $this->assertEquals($expected, $value); - } - - /** - * Test getData method - */ - public function testGetData() - { - $expected = ['field'=>'data']; - $this->callValidatorMethod('getData', $expected); - } - - /** - * Test setData method - */ - public function testSetData() - { - $expected = ['field'=>'data']; - $this->callValidatorMethodWithArg('setData', $expected, null); - } - - /** - * Test Get the validation rules. - */ - public function testGetRules() - { - $expected = ['field'=>'required']; - - $this->callValidatorMethod('getRules', $expected); - } - - /** - * Test Sometimes method. - */ - public function testSometimes() - { - $expected = null; - - $this->callValidatorMethod('sometimes', $expected, [ - 'field', - 'required', - function () {}, - ]); - } - - /** - * Test Get the files under validation. - */ - public function testGetFiles() - { - $expected = ['field'=>'data']; - - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->setMethods(['getFiles']) - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $validator->expects($this->once()) - ->method('getFiles') - ->willReturn($expected); - - $delegated = new DelegatedValidator($validator, $parser); - $files = $delegated->getFiles(); - - $this->assertEquals($expected, $files); - } - - /** - * Test Get the files in Laravel >= 5.3.21 - */ - public function testGetFilesMethodNotExists() - { - $expected = []; - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - $validator->method($this->anything()) - ->willReturn($expected); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated = new DelegatedValidator($validator, $parser); - $files = $delegated->getFiles(); - - $this->assertEquals($expected, $files); - } - - /** - * Test Set the files under validation. - */ - public function testSetFiles() - { - $return = true; - $arg = []; - - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->setMethods(['setFiles']) - ->getMock(); - - $validator->expects($this->once()) - ->method('setFiles') - ->with($arg) - ->willReturn($return); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated = new DelegatedValidator($validator, $parser); - $result = $delegated->setFiles($arg); - - $this->assertEquals($return , $result); - } - - /** - * Test Set the files in Laravel >= 5.3.21 - */ - public function testSetFilesMethodNotExists() - { - $arg=[]; - - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - - $validator->method($this->anything()) - ->willReturn($validator); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated = new DelegatedValidator($validator, $parser); - $result = $delegated->setFiles($arg); - - $this->assertEquals($validator , $result); - } - - /** - * Test Explode rules. - * - */ - public function testExplodeRules() - { - $arg='required|url'; - $this->callValidatorProtectedMethod('explodeRules',$arg); - } - - /** - * Test if a given rule implies the attribute is required. - */ - public function testIsImplicit() - { - $this->callValidatorProtectedMethod('isImplicit'); - } - - /** - * Test Replace all error message place-holders with actual values. - */ - public function testMakeReplacements() - { - $this->callValidatorProtectedMethod('makeReplacements', ['message','attribute','rule',[]]); - } - - /** - * Test Replace all error message place-holders with actual object value. - */ - public function testMakeReplacementsObject() - { - $this->callValidatorProtectedMethod('makeReplacements', ['message','attribute','rule',(object) []]); - } - - /** - * Test if the given attribute has a rule in the given set. - * - */ - public function testHasRule() - { - $this->callValidatorProtectedMethod('hasRule', ['attribute',[]]); - } - - /** - * Test the validation message for an attribute and rule. - */ - public function testGetMessage() - { - $this->callValidatorProtectedMethod('getMessage', ['attribute','rule']); - } - - /** - * Test the validation message for object with attribute and rule. - */ - public function testGetMessageObject() - { - $this->callValidatorProtectedMethod('getMessage', ['attribute', (object) []]); - } - - /** - * Test extract the rule name and parameters from a rule. - */ - public function testParseRule() - { - $method = 'parseRule'; - $args = ['required']; - - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $parser->expects($this->any()) - ->method('parse') - ->willReturn(true); - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->setConstructorArgs([$validator, $parser]) - ->setMethods(['callProtected']) - ->getMock(); - - if (is_array($args)) { - $v = call_user_func_array([$delegated,$method], $args); - } else { - $v = $delegated->$method($args); - } - - $this->assertTrue($v); - } - - /** - * Test method calls to validator instance. - */ - public function testCall() - { - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->setMethods(['fakeMethod']) - ->disableOriginalConstructor() - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated = new DelegatedValidator($validator, $parser); - $validator->expects($this->once()) - ->method('fakeMethod') - ->with($this->isType('string')) - ->willReturn(true); - - $value= $delegated->__call('fakeMethod', ['param']); - - $this->assertTrue($value); - } - - /** - * Helper to test calls to dependant Validator object - * - * @param $method - * @param $return - * - * @return mixed - */ - private function callValidatorMethod($method, $return = null, $args = []) - { - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $validator->expects($this->once()) - ->method($method) - ->willReturn($return); - - $delegated = new DelegatedValidator($validator, $parser); - $value=call_user_func_array([$delegated, $method],$args); - - $this->assertEquals($return, $value); - } - - /** - * Helper to test calls to dependant Validator object with args - * - * @param $method - * @param $arg - * @param $return - * - * @return mixed - */ - private function callValidatorMethodWithArg($method, $arg= null, $return = null) - { - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $validator->expects($this->once()) - ->method($method) - ->with($arg) - ->willReturn($return); - - $delegated = new DelegatedValidator($validator, $parser); - - $value = $delegated->$method($arg); - $this->assertNull($value); - } - - /** - * Test if a given rule implies the attribute is required. - */ - private function callValidatorProtectedMethod($method, $args = null) - { - $validator = $this->getMockBuilder(\Illuminate\Validation\Validator::class) - ->disableOriginalConstructor() - ->getMock(); - - $parser = $this->getMockBuilder(\Proengsoft\JsValidation\Support\ValidationRuleParserProxy::class) - ->disableOriginalConstructor() - ->getMock(); - - $delegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->setConstructorArgs([$validator, $parser]) - ->setMethods(['callProtected']) - ->getMock(); - - $delegated->expects($this->once()) - ->method('callProtected') - ->with($this->isInstanceOf(\Closure::class), $method, $this->isType('array')) - ->willReturn(true); - - if (is_array($args)) { - $v = call_user_func_array([$delegated,$method],$args); - } else { - $v = $delegated->$method($args); - } - - $this->assertTrue($v); - } -} diff --git a/tests/Support/RuleListTraitTest.php b/tests/Support/RuleListTraitTest.php deleted file mode 100644 index b3038c07..00000000 --- a/tests/Support/RuleListTraitTest.php +++ /dev/null @@ -1,52 +0,0 @@ -mockTrait = $this->getMockForTrait(\Proengsoft\JsValidation\Support\RuleListTrait::class); - } - - public function testIsImplemented() { - $this->assertTrue($this->callProtected('isImplemented',['Required'])); - $this->assertFalse($this->callProtected('isImplemented',['NotImplementedRule'])); - } - - public function testIsRemoteRule() { - $this->assertTrue($this->callProtected('isRemoteRule',['ActiveUrl'])); - $this->assertFalse($this->callProtected('isRemoteRule',['RequiredIf'])); - } - - public function testIsDisableRule() { - $this->assertTrue($this->callProtected('isDisableRule',['NoJsValidation'])); - $this->assertFalse($this->callProtected('isDisableRule',['RequiredIf'])); - } - - public function testValidationDisabled() { - $this->assertTrue($this->callProtected('validationDisabled',[['NoJsValidation','Required']])); - $this->assertFalse($this->callProtected('validationDisabled',[['RequiredIf','ActiveUrl']])); - } - - public function testIsFileRule() { - $this->assertTrue($this->callProtected('isFileRule',['Mimes'])); - $this->assertTrue($this->callProtected('isFileRule',['Image'])); - $this->assertFalse($this->callProtected('isFileRule',['RequiredIf'])); - } - - protected function callProtected($method, $args = []) - { - $caller = function ($method, $args) { - return call_user_func_array([$this, $method], $args); - - }; - $testCaller = $caller->bindTo($this->mockTrait, $this->mockTrait); - - return $testCaller($method, $args); - } -} diff --git a/tests/Support/UseDelegatedValidatorTraitTest.php b/tests/Support/UseDelegatedValidatorTraitTest.php deleted file mode 100644 index acf8f3a4..00000000 --- a/tests/Support/UseDelegatedValidatorTraitTest.php +++ /dev/null @@ -1,21 +0,0 @@ -getMockForTrait(\Proengsoft\JsValidation\Support\UseDelegatedValidatorTrait::class); - $mockDelegated = $this->getMockBuilder(\Proengsoft\JsValidation\Support\DelegatedValidator::class) - ->disableOriginalConstructor() - ->getMock(); - - $mockTrait->setDelegatedValidator($mockDelegated); - $value = $mockTrait->getDelegatedValidator($mockDelegated); - - $this->assertEquals($mockDelegated, $value); - } -} diff --git a/tests/composer-5.4.json b/tests/composer-5.4.json deleted file mode 100644 index 10c4649e..00000000 --- a/tests/composer-5.4.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "require": { - "php": ">=5.6.4", - "illuminate/support": "5.4.*", - "illuminate/validation": "5.4.*", - "illuminate/contracts": "5.4.*", - "illuminate/view": "5.4.*", - "illuminate/config": "5.4.*", - "illuminate/http": "5.4.*", - "illuminate/translation": "5.4.*" - }, - "require-dev": { - "phpunit/phpunit": "^5.7", - "mockery/mockery": "^0.9.8" - }, - "autoload": { - "psr-4": { - "Proengsoft\\JsValidation\\": "src" - } - }, - "autoload-dev": { - "psr-4": { - "Proengsoft\\JsValidation\\Tests\\": "tests" - } - } -} diff --git a/tests/stubs/JsValidatorFactoryTest.php b/tests/stubs/JsValidatorFactoryTest.php deleted file mode 100644 index f7379016..00000000 --- a/tests/stubs/JsValidatorFactoryTest.php +++ /dev/null @@ -1,33 +0,0 @@ -'require'];} - public function messages(){return [];} - public function attributes(){return [];} - - public static function createFromBase() { - //$sessionMock = m::mock('Symfony\Component\HttpFoundation\Session\SessionInterface',[]); - $mockedRequest = m::mock(\Symfony\Component\HttpFoundation\Request::class); - $mockedRequest->shouldReceive('setSession') - ->shouldReceive('setUserResolver') - ->shouldReceive('setRouteResolver') - ->shouldReceive('messages')->andReturn([]) - ->shouldReceive('attributes')->andReturn([]); - return $mockedRequest; - } - } -} diff --git a/tests/stubs/ResolverTest.php b/tests/stubs/ResolverTest.php deleted file mode 100644 index ef1d89ec..00000000 --- a/tests/stubs/ResolverTest.php +++ /dev/null @@ -1,75 +0,0 @@ -resolver = function() use ($translator) { - $m = Mockery::mock('Illuminate\Validation\Validator[sometimes,getRules]',[$translator,[],[]]) - ->shouldAllowMockingMethod('sometimes'); - $m->shouldReceive('sometimes') - ->once(); - $m->shouldReceive('getRules') - ->andReturn(['field'=>['required']]); - return $m; - }; - } - - /** - * Create a new Validator instance. - * - * @param array $data - * @param array $rules - * @param array $messages - * @param array $customAttributes - * @return \Illuminate\Contracts\Validation\Validator - */ - public function make(array $data, array $rules, array $messages = [], array $customAttributes = []) - { - // TODO: Implement make() method. - } - - /** - * Register a custom validator extension. - * - * @param string $rule - * @param \Closure|string $extension - * @param string $message - * @return void - */ - public function extend($rule, $extension, $message = null) - { - // TODO: Implement extend() method. - } - - /** - * Register a custom implicit validator extension. - * - * @param string $rule - * @param \Closure|string $extension - * @param string $message - * @return void - */ - public function extendImplicit($rule, $extension, $message = null) - { - // TODO: Implement extendImplicit() method. - } - - /** - * Register a custom implicit validator message replacer. - * - * @param string $rule - * @param \Closure|string $replacer - * @return void - */ - public function replacer($rule, $replacer) - { - // TODO: Implement replacer() method. - } -}