diff --git a/tests/fixtures/27-less-unbuilt.patch b/tests/fixtures/27-less-unbuilt.patch new file mode 100644 index 00000000..1e9506fa --- /dev/null +++ b/tests/fixtures/27-less-unbuilt.patch @@ -0,0 +1,26 @@ +From 793df60c6b5d4733191ef7d2c2b19b940803c066 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 22:35:27 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: for less tests + +This should be applied on top of v2.7.14 +--- + theme/bootstrapbase/less/moodle/reports.less | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/theme/bootstrapbase/less/moodle/reports.less b/theme/bootstrapbase/less/moodle/reports.less +index 6c90a80..211c709 100644 +--- a/theme/bootstrapbase/less/moodle/reports.less ++++ b/theme/bootstrapbase/less/moodle/reports.less +@@ -15,4 +15,6 @@ + + #page-report-participation-index.dir-rtl .participationselectform div label[for=menuinstanceid] { + margin-right: 0px; // No right margin for RTL. +-} +\ No newline at end of file ++} ++ ++.integrationcsschange{display:none;} +-- +2.8.1 + diff --git a/tests/fixtures/27-shifter-unbuildjs.patch b/tests/fixtures/27-shifter-unbuildjs.patch new file mode 100644 index 00000000..012d9e5a --- /dev/null +++ b/tests/fixtures/27-shifter-unbuildjs.patch @@ -0,0 +1,26 @@ +From f2e278d056561d0d6fbce54be6d187a514640553 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 22:20:00 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: for shifter tests + +This should be applied on top of v2.7.14 +--- + lib/editor/atto/yui/src/editor/js/editor.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/editor/atto/yui/src/editor/js/editor.js b/lib/editor/atto/yui/src/editor/js/editor.js +index ca6ca55..5260475 100644 +--- a/lib/editor/atto/yui/src/editor/js/editor.js ++++ b/lib/editor/atto/yui/src/editor/js/editor.js +@@ -363,7 +363,7 @@ Y.extend(Editor, Y.Base, { + }, + + _setPluginState: function(enable, plugin) { +- var target = 'disableButtons'; ++ var target = 'disableButtons-dan-woz-ere'; + if (enable) { + target = 'enableButtons'; + } +-- +2.8.1 + diff --git a/tests/fixtures/31-grunt-js-unbuilt.patch b/tests/fixtures/31-grunt-js-unbuilt.patch new file mode 100644 index 00000000..7c4bbc19 --- /dev/null +++ b/tests/fixtures/31-grunt-js-unbuilt.patch @@ -0,0 +1,26 @@ +From ca0ff741dab36b760e20a37418fcdb139885eb79 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 23:06:36 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: unbuilt js change for grunt + +This should be applied on top of v3.1.0 +--- + lib/amd/src/url.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/amd/src/url.js b/lib/amd/src/url.js +index b3263ee..b6348de 100644 +--- a/lib/amd/src/url.js ++++ b/lib/amd/src/url.js +@@ -61,7 +61,7 @@ define(['core/config'], function(config) { + relativeUrl: function(relativePath) { + + if (relativePath.indexOf('http:') === 0 || relativePath.indexOf('https:') === 0 || relativePath.indexOf('://') >= 0) { +- throw new Error('relativeUrl function does not accept absolute urls'); ++ throw new Error('relativeUrl function does not accept absolute urls. danp woz ere!'); + } + + // Fix non-relative paths; +-- +2.8.1 + diff --git a/tests/fixtures/31-grunt-less-unbuilt.patch b/tests/fixtures/31-grunt-less-unbuilt.patch new file mode 100644 index 00000000..d7da32c2 --- /dev/null +++ b/tests/fixtures/31-grunt-less-unbuilt.patch @@ -0,0 +1,26 @@ +From 205c355bc8ef7bfb52695cc42f2d98826759364b Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 22:35:27 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: less unbuilt for grunt tests + +This should be applied on top of v3.1.0 +--- + theme/bootstrapbase/less/moodle/reports.less | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/theme/bootstrapbase/less/moodle/reports.less b/theme/bootstrapbase/less/moodle/reports.less +index 6c90a80..211c709 100644 +--- a/theme/bootstrapbase/less/moodle/reports.less ++++ b/theme/bootstrapbase/less/moodle/reports.less +@@ -15,4 +15,6 @@ + + #page-report-participation-index.dir-rtl .participationselectform div label[for=menuinstanceid] { + margin-right: 0px; // No right margin for RTL. +-} +\ No newline at end of file ++} ++ ++.integrationcsschange{display:none;} +-- +2.8.1 + diff --git a/tests/fixtures/31-php_lint-bad.patch b/tests/fixtures/31-php_lint-bad.patch new file mode 100644 index 00000000..e3b4017b --- /dev/null +++ b/tests/fixtures/31-php_lint-bad.patch @@ -0,0 +1,22 @@ +From 7fd18b3698c14916bdfa83f502544ddd0eb65b20 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 22:54:14 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: for php_lint tests + +This should be applied on top of v3.1.0 +--- + lib/moodlelib.php | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/lib/moodlelib.php b/lib/moodlelib.php +index 8160f89..f6c0fd7 100644 +--- a/lib/moodlelib.php ++++ b/lib/moodlelib.php +@@ -9768,3 +9768,4 @@ class lang_string { + return array('forcedstring', 'string', 'lang'); + } + } ++die('oh this is gonna be a problem! +-- +2.8.1 + diff --git a/tests/fixtures/31-php_lint-ok.patch b/tests/fixtures/31-php_lint-ok.patch new file mode 100644 index 00000000..9aeee76e --- /dev/null +++ b/tests/fixtures/31-php_lint-ok.patch @@ -0,0 +1,26 @@ +From c6385705362f492fab3dc90cf5317e372fef60c8 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 22:51:00 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 OK fixture: for php_lint tests + +This should be applied on top of v3.1.0 +--- + lib/moodlelib.php | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/moodlelib.php b/lib/moodlelib.php +index 8160f89..c7cadf2 100644 +--- a/lib/moodlelib.php ++++ b/lib/moodlelib.php +@@ -9321,7 +9321,7 @@ function object_array_unique($array, $keepkeyassoc = true) { + * @return boolean + */ + function is_primary_admin($userid) { +- $primaryadmin = get_admin(); ++ $primaryadmin = get_admin(); + + if ($userid == $primaryadmin->id) { + return true; +-- +2.8.1 + diff --git a/tests/fixtures/31-thirdparty-error.patch b/tests/fixtures/31-thirdparty-error.patch new file mode 100644 index 00000000..6e74337f --- /dev/null +++ b/tests/fixtures/31-thirdparty-error.patch @@ -0,0 +1,31 @@ +From 096f3a432dcc478a7277889dee49f46f833c39b5 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 23:21:24 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: for thirdparty check + +This should be applied on top of v3.1.0 +--- + lib/amd/src/mustache.js | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/amd/src/mustache.js b/lib/amd/src/mustache.js +index a3ce19e..1075fad 100644 +--- a/lib/amd/src/mustache.js ++++ b/lib/amd/src/mustache.js +@@ -25,13 +25,6 @@ + // + + // Description of import into Moodle: +-// Checkout from https://github.com/moodle/custom-mustache.js +-// Rebase onto latest release tag from https://github.com/janl/mustache.js +-// Copy mustache.js into lib/amd/src/ in Moodle folder. +-// Add the license as a comment to the file and these instructions. +-// Add jshint tags so this file is not linted. +-// Remove the "global define:" comment (hint for linter) +-// Make sure that you have not removed the custom code for '$' and '<'. + + /*! + * mustache.js - Logic-less {{mustache}} templates with JavaScript +-- +2.8.1 + diff --git a/tests/fixtures/31-thirdparty-ok.patch b/tests/fixtures/31-thirdparty-ok.patch new file mode 100644 index 00000000..770611cc --- /dev/null +++ b/tests/fixtures/31-thirdparty-ok.patch @@ -0,0 +1,45 @@ +From c0805275c6a79422632d0fb10bd7fa9f518929a8 Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Wed, 15 Jun 2016 23:21:24 +0100 +Subject: [PATCH 1/1] MDLSITE-4211 fixture: OK thirdparty check + +This should be applied on top of v3.1.0 +--- + lib/amd/src/mustache.js | 7 ------- + lib/thirdpartylibs.xml | 2 +- + 2 files changed, 1 insertion(+), 8 deletions(-) + +diff --git a/lib/amd/src/mustache.js b/lib/amd/src/mustache.js +index a3ce19e..1075fad 100644 +--- a/lib/amd/src/mustache.js ++++ b/lib/amd/src/mustache.js +@@ -25,13 +25,6 @@ + // + + // Description of import into Moodle: +-// Checkout from https://github.com/moodle/custom-mustache.js +-// Rebase onto latest release tag from https://github.com/janl/mustache.js +-// Copy mustache.js into lib/amd/src/ in Moodle folder. +-// Add the license as a comment to the file and these instructions. +-// Add jshint tags so this file is not linted. +-// Remove the "global define:" comment (hint for linter) +-// Make sure that you have not removed the custom code for '$' and '<'. + + /*! + * mustache.js - Logic-less {{mustache}} templates with JavaScript +diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml +index 6440a73..2779103 100644 +--- a/lib/thirdpartylibs.xml ++++ b/lib/thirdpartylibs.xml +@@ -261,7 +261,7 @@ + amd/src/mustache.js + Mustache.js + MIT +- 2.2.1 ++ 2.2.2 + + + graphlib.php +-- +2.8.1 + diff --git a/tests/fixtures/32-thirdparty-lib-added.patch b/tests/fixtures/32-thirdparty-lib-added.patch new file mode 100644 index 00000000..fe3599dc --- /dev/null +++ b/tests/fixtures/32-thirdparty-lib-added.patch @@ -0,0 +1,27 @@ +From 4600d7d6fd5d5bd4f5bae80c3e89b838d95f2b1d Mon Sep 17 00:00:00 2001 +From: Dan Poltawski +Date: Tue, 12 Jul 2016 11:23:56 +0100 +Subject: [PATCH 1/1] MDLSITE-4678 fixture: adding third party lib + +--- + lib/thirdpartylibs.xml | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/lib/thirdpartylibs.xml b/lib/thirdpartylibs.xml +index 6440a73..3385d2f 100644 +--- a/lib/thirdpartylibs.xml ++++ b/lib/thirdpartylibs.xml +@@ -275,4 +275,10 @@ + GPL + 2.3.0 + ++ ++ integrationtest ++ Moodle Integration test for MDLSITE-4678 ++ GPL ++ 2.3.0 ++ + +-- +2.9.0 + diff --git a/tests/grunt_process.bats b/tests/grunt_process.bats new file mode 100755 index 00000000..6a7a4808 --- /dev/null +++ b/tests/grunt_process.bats @@ -0,0 +1,70 @@ +#!/usr/bin/env bats + +load libs/shared_setup + + +setup () { + create_git_branch MOODLE_31_STABLE v3.1.0 + + export extrapath=. +} + +@test "grunt_process: normal" { + cd $BATS_TEST_DIRNAME/../grunt_process/ + run ./grunt_process.sh + assert_success + assert_output --partial "Done, without errors." + assert_output --partial "OK: All modules are perfectly processed by grunt" +} + +@test "grunt_process: Uncommited .less change" { + # Create css change. + cd $gitdir + $gitcmd am $BATS_TEST_DIRNAME/fixtures/31-grunt-less-unbuilt.patch + + # Run test + cd $BATS_TEST_DIRNAME/../grunt_process/ + run ./grunt_process.sh + + # Assert result + assert_failure + assert_output --partial "Done, without errors." # Grunt shouldn't have an issue here. + assert_output --partial "ERROR: Some modules are not properly processed by grunt. Changes detected:" + assert_output --regexp "GRUNT-CHANGE: (.*)/theme/bootstrapbase/style/moodle.css" +} + +@test "grunt_process: Uncommited .js change" { + # Create js change. + cd $gitdir + $gitcmd am $BATS_TEST_DIRNAME/fixtures/31-grunt-js-unbuilt.patch + + # Run test + cd $BATS_TEST_DIRNAME/../grunt_process/ + run ./grunt_process.sh + + # Assert result + assert_failure + assert_output --partial "Done, without errors." # Grunt shouldn't have an issue here. + assert_output --partial "ERROR: Some modules are not properly processed by grunt. Changes detected:" + assert_output --regexp "GRUNT-CHANGE: (.*)/lib/amd/build/url.min.js" +} + +@test "grunt_process: Uncommited ignorefiles change" { + # When a third party library is added, developers need to commit + # ignorefiles change since 3.2. + + # Testing on in-dev 3.2dev + create_git_branch 32-dev 5a1728df39116fc701cc907e85a638aa7674f416 + cd $gitdir + $gitcmd am $BATS_TEST_DIRNAME/fixtures/32-thirdparty-lib-added.patch + + # Run test + cd $BATS_TEST_DIRNAME/../grunt_process/ + run ./grunt_process.sh + + # Assert result + assert_failure + assert_output --partial "ERROR: Some modules are not properly processed by grunt. Changes detected:" + assert_output --regexp "GRUNT-CHANGE: (.*)/.eslintignore" +} + diff --git a/tests/less_checker.bats b/tests/less_checker.bats new file mode 100755 index 00000000..91f6a9f0 --- /dev/null +++ b/tests/less_checker.bats @@ -0,0 +1,30 @@ +#!/usr/bin/env bats + +load libs/shared_setup + + +setup () { + create_git_branch MOODLE_27_STABLE v2.7.14 + + export extrapath=. + # Setup recess base. + export recessbase=$LOCAL_CI_TESTS_CACHEDIR/recess + mkdir -p $recessbase +} + +@test "less_checker: normal" { + cd $BATS_TEST_DIRNAME/../less_checker/ + run ./less_checker.sh + assert_success + assert_output --partial "OK: All .less files are perfectly compiled and matching git contents" +} + +@test "less_checker: uncommitted less change" { + cd $gitdir + $gitcmd am $BATS_TEST_DIRNAME/fixtures/27-less-unbuilt.patch + cd $BATS_TEST_DIRNAME/../less_checker/ + run ./less_checker.sh + assert_failure + assert_output --partial "ERROR: Some .less files are not matching git contents. Changes detected:" + assert_output --partial "theme/bootstrapbase/style/moodle.css" +} diff --git a/tests/libs/shared_setup.bash b/tests/libs/shared_setup.bash index cdc50d35..5f9ad6e7 100644 --- a/tests/libs/shared_setup.bash +++ b/tests/libs/shared_setup.bash @@ -22,18 +22,24 @@ fi export WORKSPACE=$BATS_TMPDIR/workspace mkdir -p $WORKSPACE -export gitcmd=`which git` -export npmcmd=`which npm` +export gitcmd=git +export phpcmd=php +export npmcmd=npm export npmbase=$LOCAL_CI_TESTS_CACHEDIR/npmbase mkdir -p $npmbase export gitdir=$LOCAL_CI_TESTS_GITDIR create_git_branch () { + branch=$1 + resetto=$2 + cd $gitdir $gitcmd checkout . -q $gitcmd clean -fd -q - $gitcmd checkout -B $gitbranch -q - $gitcmd reset --hard origin/$gitbranch + $gitcmd checkout -B $branch -q + $gitcmd reset --hard $resetto -q + + export gitbranch=$branch cd $BATS_TEST_DIRNAME } diff --git a/tests/php_lint.bats b/tests/php_lint.bats new file mode 100755 index 00000000..3f00aa0f --- /dev/null +++ b/tests/php_lint.bats @@ -0,0 +1,40 @@ +#!/usr/bin/env bats + +load libs/shared_setup + +setup () { + create_git_branch MOODLE_31_STABLE v3.1.0 + + export extrapath=. +} + +@test "php_lint: lib/moodlelib.php lint free" { + cd $gitdir + export GIT_PREVIOUS_COMMIT=$($gitcmd rev-parse HEAD) + $gitcmd am $BATS_TEST_DIRNAME/fixtures/31-php_lint-ok.patch + export GIT_COMMIT=$($gitcmd rev-parse HEAD) + + cd $BATS_TEST_DIRNAME/../php_lint/ + run ./php_lint.sh + assert_success + assert_output --partial "Running php syntax check from $GIT_PREVIOUS_COMMIT to $GIT_COMMIT" + assert_output --partial "lib/moodlelib.php - OK" + assert_output --partial "No PHP syntax errors found" +} + +@test "php_lint: lib/moodlelib.php lint error detected" { + cd $gitdir + export GIT_PREVIOUS_COMMIT=$($gitcmd rev-parse HEAD) + $gitcmd am $BATS_TEST_DIRNAME/fixtures/31-php_lint-bad.patch + export GIT_COMMIT=$($gitcmd rev-parse HEAD) + + # Run test + cd $BATS_TEST_DIRNAME/../php_lint/ + run ./php_lint.sh + + # Assert result + assert_failure + assert_output --partial "Running php syntax check from $GIT_PREVIOUS_COMMIT to $GIT_COMMIT" + assert_output --partial "lib/moodlelib.php - ERROR:" + assert_output --regexp "PHP syntax errors found." +} diff --git a/tests/shifter_walk.bats b/tests/shifter_walk.bats new file mode 100755 index 00000000..b6679c4a --- /dev/null +++ b/tests/shifter_walk.bats @@ -0,0 +1,29 @@ +#!/usr/bin/env bats + +load libs/shared_setup + +setup () { + create_git_branch MOODLE_27_STABLE v2.7.14 + + export extrapath=. + # setup shifter base. + export shifterbase=$LOCAL_CI_TESTS_CACHEDIR/shifter + mkdir -p $shifterbase +} + +@test "shifter_walk: normal" { + cd $BATS_TEST_DIRNAME/../shifter_walk/ + run ./shifter_walk.sh + assert_success + assert_output --partial "OK: All modules are perfectly shiftered" +} + +@test "shifter_walk: Uncommitted .js change" { + cd $gitdir + $gitcmd am $BATS_TEST_DIRNAME/fixtures/27-shifter-unbuildjs.patch + cd $BATS_TEST_DIRNAME/../shifter_walk/ + run ./shifter_walk.sh + assert_failure + assert_output --partial "ERROR: Some modules are not properly shiftered. Changes detected:" + assert_output --partial "lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor.js" +} diff --git a/tests/thirdparty_check.bats b/tests/thirdparty_check.bats new file mode 100755 index 00000000..5972fab4 --- /dev/null +++ b/tests/thirdparty_check.bats @@ -0,0 +1,38 @@ +#!/usr/bin/env bats + +load libs/shared_setup + +setup () { + create_git_branch MOODLE_31_STABLE v3.1.0 + + export extrapath=. +} + +@test "thirdparty_check: thirdpartyfile modified OK" { + cd $gitdir + export initialcommit=$($gitcmd rev-parse HEAD) + $gitcmd am $BATS_TEST_DIRNAME/fixtures/31-thirdparty-ok.patch + export finalcommit=$($gitcmd rev-parse HEAD) + + cd $BATS_TEST_DIRNAME/../thirdparty_check/ + run ./thirdparty_check.sh + assert_success + assert_output --partial "INFO: Checking for third party modifications from $initialcommit to $finalcommit" + assert_output --partial "INFO: Detected third party modification in lib/amd/src/mustache.js" + assert_output --partial "INFO: OK lib/thirdpartylibs.xml modified" + refute_output --partial "WARN:" +} + +@test "thirdparty_check: thirdpartyfile modified without update" { + cd $gitdir + export initialcommit=$($gitcmd rev-parse HEAD) + $gitcmd am $BATS_TEST_DIRNAME/fixtures/31-thirdparty-error.patch + export finalcommit=$($gitcmd rev-parse HEAD) + + cd $BATS_TEST_DIRNAME/../thirdparty_check/ + run ./thirdparty_check.sh + assert_success # TODO, this should be fixed! + assert_output --partial "INFO: Checking for third party modifications from $initialcommit to $finalcommit" + assert_output --partial "INFO: Detected third party modification in lib/amd/src/mustache.js" + assert_output --partial "WARN: modification to third party library (lib/amd/src/mustache.js) without update to lib/thirdpartylibs.xml or lib/amd/src/readme_moodle.txt" +}