Skip to content

Commit

Permalink
MDLSITE-4211 testing: add unit tests!
Browse files Browse the repository at this point in the history
* grunt_process
* less_checker
* php_lint
* shifter_walk
* thirdparty_check
  • Loading branch information
danpoltawski committed Jul 13, 2016
1 parent 6eab377 commit 3afbeeb
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 4 deletions.
26 changes: 26 additions & 0 deletions tests/fixtures/27-less-unbuilt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 793df60c6b5d4733191ef7d2c2b19b940803c066 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

26 changes: 26 additions & 0 deletions tests/fixtures/27-shifter-unbuildjs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From f2e278d056561d0d6fbce54be6d187a514640553 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

26 changes: 26 additions & 0 deletions tests/fixtures/31-grunt-js-unbuilt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From ca0ff741dab36b760e20a37418fcdb139885eb79 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

26 changes: 26 additions & 0 deletions tests/fixtures/31-grunt-less-unbuilt.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 205c355bc8ef7bfb52695cc42f2d98826759364b Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

22 changes: 22 additions & 0 deletions tests/fixtures/31-php_lint-bad.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
From 7fd18b3698c14916bdfa83f502544ddd0eb65b20 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

26 changes: 26 additions & 0 deletions tests/fixtures/31-php_lint-ok.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From c6385705362f492fab3dc90cf5317e372fef60c8 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

31 changes: 31 additions & 0 deletions tests/fixtures/31-thirdparty-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 096f3a432dcc478a7277889dee49f46f833c39b5 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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

45 changes: 45 additions & 0 deletions tests/fixtures/31-thirdparty-ok.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From c0805275c6a79422632d0fb10bd7fa9f518929a8 Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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 @@
<location>amd/src/mustache.js</location>
<name>Mustache.js</name>
<license>MIT</license>
- <version>2.2.1</version>
+ <version>2.2.2</version>
</library>
<library>
<location>graphlib.php</location>
--
2.8.1

27 changes: 27 additions & 0 deletions tests/fixtures/32-thirdparty-lib-added.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 4600d7d6fd5d5bd4f5bae80c3e89b838d95f2b1d Mon Sep 17 00:00:00 2001
From: Dan Poltawski <[email protected]>
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 @@
<license>GPL</license>
<version>2.3.0</version>
</library>
+ <library>
+ <location>integrationtest</location>
+ <name>Moodle Integration test for MDLSITE-4678</name>
+ <license>GPL</license>
+ <version>2.3.0</version>
+ </library>
</libraries>
--
2.9.0

70 changes: 70 additions & 0 deletions tests/grunt_process.bats
Original file line number Diff line number Diff line change
@@ -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"
}

30 changes: 30 additions & 0 deletions tests/less_checker.bats
Original file line number Diff line number Diff line change
@@ -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"
}
14 changes: 10 additions & 4 deletions tests/libs/shared_setup.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Loading

0 comments on commit 3afbeeb

Please sign in to comment.