Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.idea

vendor
composer.lock
composer.phar
Resources/public/js/fp_js_validator.js
/node_modules

package-lock.json
node_modules

Tests/app/var
Tests/app/public/bundles
Tests/app/public/build
cypress/plugins
cypress
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ install:
- docker-compose build --parallel webserver php-fpm
- docker-compose up -d webserver php-fpm
- docker-compose exec php-fpm composer install --no-interaction
- docker-compose exec php-fpm Tests/app/bin/console assets:install -v Tests/app || Tests/app/bin/console assets:install -v Tests/app
- docker-compose exec php-fpm Tests/app/bin/console assets:install -v Tests/app
- docker-compose exec -w /application/Tests/app php-fpm npm i
- docker-compose exec -w /application/Tests/app php-fpm npm run build
- docker-compose exec php-fpm npm ci
- docker-compose exec php-fpm npm i

script:
- docker-compose exec php-fpm npm run test
60 changes: 21 additions & 39 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,42 @@ Contributing
cd /path/to/your/projects
git clone https://github.com/formapro/JsFormValidatorBundle.git
```
2) Install vendors
2) Install vendors via docker
```bash
cd JsFormValidatorBundle
php composer.phar install --dev
docker-compose up -d
docker exec -it PHP-CONTAINER-NAME bash
composer install --dev
```
3) Install assests
```bash
Tests/app/console assets:install Tests/app
```
4) Fix permissions
```bash
sudo chmod -R 0777 Tests/app/cache Tests/app/logs Resources/public/js/fp_js_validator.js
```
5) Create a new virtual host and set the ```Tests/app``` directory as a root
6) Restart apache
4) Create var folder and set permissions
```bash
sudo service apache2 restart
mkdir Tests/app/var
sudo chmod -R 0777 Tests/app/var
```
7) Copy the ```Tests/app/Resources/local_config.php.tpl``` file as local_config.php
8) Open this file and change the host name to your own
9) Run selenium. If you do not have it yet:
3) Install assests
```bash
curl http://selenium.googlecode.com/files/selenium-server-standalone-2.33.0.jar > selenium.jar
java -jar selenium.jar
npm i

cd Tests/app/
./bin/console assets:install Tests/app/public
npm run build
```
10) Run tests
4) Run tests
```bash
phpunit
npm run test
```

## Tests

Basically the bundle covered by functional selenium tests
Basically the bundle covered by unit jest's test and e2e cypress test.
The main test case is placed in ```Tests/Functional/MainFunctionalTest.php```
It calls pages which are defined in ```Tests/TestBundles/DefaultTestBundle```

The main idea of most tests is:
1) create an action ```mytestAction``` in ```Tests/TestBundles/DefaultTestBundle/Controller/FunctionalTestsController.php``` with a form that has specified list of validation rules
1.1) use a general route to call this action ```test/{controller}/{type}/{js}```
1.2) so, in your action you can get the ```$type``` and ```$js``` parameters
1.3) ```type``` variable can be used to check if the form should be filled out with valid or invalid data (1/0)
1.4) ```js``` variable - to check if JS should be enabled or disabled (1/0)
2) bind valid values to the form (call with ```type = 1```)
3) call this form with disabled JS (native Symfony validation) and get the list of errors ```test/mytest/1/0``` (1 - form is valid, 0 - js is disabled)
4) call the form with enabled JS (here works our bundle) and get list of errors ```test/mytest/1/1``` (1 - form is valid, 1- js is enabled)
5) compare errors from #3 and #4 steps - they should be equal
6) bind invalid values to the form (call with ```type = 0```)
7) repeat steps #3, #4, #5 (```test/mytest/0/0``` and ```test/mytest/0/0```)
Unit tests are placed in main resource folder with suffix ```.test.js```
e2e test is placed in cypress folder in project root ```cypress/integration/form_spec.js```

[How to run tests on a real project](Resources/doc/4.md)
The main idea of unit tests is covered constrain logic.
The main idea of e2e test is visit route with example form with all symfony constraint and find used error messages.

## Javascripts

All the javascripts placed in the ```Resources/pulic/js``` folder
All of them are merged and included by assetic bundle for the dev/test environments.
The ```/Resources/public/js/fp_js_validator.js``` file is a merged library that uses as main included file.
Thera no reason to edit this file becauset it is updated automatically each time when you run dev/test
All of them are merged and included by assets command to the dev/test environments.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ Or if you do not want to unexpected problems better to use exact version.
$ composer require "fp/jsformvalidator-bundle":"v1.6.*"
```

### 1.2 Enable javascript libraries<a name="p_1_3"></a>
### 1.2 Enable javascript libraries

There are two ways to initialize javascript's files for this library.
You can create a new entry in the webpack or import the main file into your javascript.

#### 1.2.1 Add FpJsFormValidatorBundle to webpack.config.js
```diff
Encore
...
.addEntry('search', './assets/js/search.js')
+ .addEntry('FpJsFormElement', './vendor/fp/jsformvalidator-bundle/Fp/JsFormValidatorBundle/Resources/public/js/FpJsFormValidator.js')
.addEntry('app', './assets/js/app.js')
+ .addEntry('FpJsFormElement', './vendor/fp/jsformvalidator-bundle/Fp/JsFormValidatorBundle/Resources/public/js/FpJsFormValidatorWithJqueryInit.js')
...
.configureBabel(null, {
useBuiltIns: 'usage',
Expand All @@ -42,15 +45,24 @@ Encore
;
```

#### 1.3.2 Include the javascripts to your template
And include new entry in your template
```diff
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
+ {{ encore_entry_script_tags('FpJsFormElement') }}
{{ encore_entry_script_tags('app') }}
```

#### 1.2.2 Import FpJsFormValidatorBundle in your main javascript
```diff
import $ from 'jquery';
+ import 'path-to-bundles/fpjsformvalidator/js/FpJsFormValidator';
+ import 'path-to-bundles/fpjsformvalidator/js/jquery.fpjsformvalidator';
```

#### 1.2.3 Use inits in your template
```diff
{% block javascripts %}
+ {{ js_validator_config() }}
+ {{ init_js_validation() }}

{% endblock %}
```

Expand Down
25 changes: 0 additions & 25 deletions Tests/app/.gitignore

This file was deleted.

70 changes: 0 additions & 70 deletions Tests/app/.travis.yml

This file was deleted.

54 changes: 0 additions & 54 deletions Tests/app/appveyor.yml

This file was deleted.

1 change: 0 additions & 1 deletion Tests/app/cypress.json

This file was deleted.

Loading