Skip to content

Commit

Permalink
tests: added tests for netteForms.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 8, 2015
1 parent fcdb7e9 commit 3425fee
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 9 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ matrix:
allow_failures:
- php: hhvm

include:
- php: 5.5
env: netteForms=1

script:
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
- php code-checker/src/code-checker.php
- if [ "$netteForms" != 1 ]; then vendor/bin/tester tests -s -p php -c tests/php-unix.ini; fi
- if [ "$netteForms" != 1 ]; then php code-checker/src/code-checker.php; fi
- if [ "$netteForms" == 1 ]; then grunt --gruntfile tests/netteForms/Gruntfile.js test; fi

after_failure:
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done

before_script:
# Install Nette Tester & Code Checker
- composer install --no-interaction --dev --prefer-source
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
- if [ "$netteForms" != 1 ]; then composer install --no-interaction --dev --prefer-source; fi
- if [ "$netteForms" != 1 ]; then composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source; fi
- if [ "$netteForms" == 1 ]; then npm install -g grunt-cli; cd tests/netteForms; npm install; bower install; cd ../..; fi

11 changes: 6 additions & 5 deletions src/assets/netteForms.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ Nette.validators = {
},

equal: function(elem, arg, val) {
/* jshint eqeqeq: false */
if (arg === undefined) {
return null;
}
Expand Down Expand Up @@ -301,9 +302,9 @@ Nette.validators = {

regexp: function(elem, arg, val) {
var parts = typeof arg === 'string' ? arg.match(/^\/(.*)\/([imu]*)$/) : false;
if (parts) { try {
return (new RegExp(parts[1], parts[2].replace('u', ''))).test(val);
} catch (e) {} }
try {
return parts && (new RegExp(parts[1], parts[2].replace('u', ''))).test(val);
} catch (e) {}
},

pattern: function(elem, arg, val) {
Expand Down Expand Up @@ -385,7 +386,7 @@ Nette.toggleForm = function(form, elem) {
*/
Nette.toggleControl = function(elem, rules, topSuccess, firsttime) {
rules = rules || Nette.parseJSON(elem.getAttribute('data-nette-rules'));
var has = false, __hasProp = Object.prototype.hasOwnProperty, handler = function() {
var has = false, hasProp = Object.prototype.hasOwnProperty, handler = function () {
Nette.toggleForm(elem.form, elem);
}, handled = [];

Expand Down Expand Up @@ -424,7 +425,7 @@ Nette.toggleControl = function(elem, rules, topSuccess, firsttime) {
}
}
for (var id2 in rule.toggle || []) {
if (__hasProp.call(rule.toggle, id2)) {
if (hasProp.call(rule.toggle, id2)) {
Nette.toggles[id2] = Nette.toggles[id2] || (rule.toggle[id2] ? success : !success);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*/output
/test.log
/tmp
/netteForms/node_modules
/netteForms/bower_components
44 changes: 44 additions & 0 deletions tests/netteForms/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
// Predefined globals whom JSHint will ignore.
"browser" : true, // Standard browser globals e.g. `window`, `document`.
"predef" : [ // Custom globals.
"FileList"
],

"debug" : false, // Allow debugger statements e.g. browser breakpoints.
"devel" : true, // Allow developments statements e.g. `console.log();`.

// ECMAScript 5.
"es5" : false, // Allow ECMAScript 5 syntax.

// The Good Parts.
"asi" : true, // Tolerate Automatic Semicolon Insertion (no semicolons).
"laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
"boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"curly" : true, // Require {} for every new block or scope.
"eqeqeq" : true, // Require triple equals i.e. `===`.
"eqnull" : false, // Tolerate use of `== null`.
"evil" : true, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef" : true, // Prohipit variable use before definition.
"loopfunc" : true, // Allow functions to be defined within loops.
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl" : true, // Tolerate script-targeted URLs.
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
"undef" : true, // Require all non-global variables be declared before they are used.

// Personal styling preferences.
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"nomen" : true, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"plusplus" : false, // Prohibit use of `++` & `--`.
"sub" : false // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
}
30 changes: 30 additions & 0 deletions tests/netteForms/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'../../src/assets/*.js'
]
},
jasmine: {
test: {
src: '../../src/assets/*.js',
options: {
vendor: [
'bower_components/fixtures/fixtures.js'
],
specs: 'spec/*Spec.js'
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-jasmine');

grunt.registerTask('test', [
'jshint','jasmine'
]);
};
21 changes: 21 additions & 0 deletions tests/netteForms/SpecRunner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.2.0</title>

<link rel="stylesheet" href="bower_components/jasmine/lib/jasmine-core/jasmine.css">

<script src="bower_components/jasmine/lib/jasmine-core/jasmine.js"></script>
<script src="bower_components/jasmine/lib/jasmine-core/jasmine-html.js"></script>
<script src="bower_components/jasmine/lib/jasmine-core/boot.js"></script>
<script src="bower_components/fixtures/fixtures.js"></script>

<script src="../../src/assets/netteForms.js"></script>

<script src="spec/Nette.validateRuleSpec.js"></script>
</head>

<body>
</body>
</html>
7 changes: 7 additions & 0 deletions tests/netteForms/bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "netteForms.js tests",
"dependencies": {
"jasmine": "~2.2.1",
"fixtures": "~1.5.3"
}
}
8 changes: 8 additions & 0 deletions tests/netteForms/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"devDependencies": {
"bower": "^1.3.12",
"grunt": "^0.4.5",
"grunt-contrib-jasmine": "^0.8.2",
"grunt-contrib-jshint": "^0.11.0"
}
}
Loading

0 comments on commit 3425fee

Please sign in to comment.