Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behat2 #68

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9b0fc64
restructured to support mocking and behat in the future
Dec 16, 2019
289ec55
stylecorrections
Dec 16, 2019
afaa889
added mocking classes
Dec 16, 2019
de301d0
added basic tests
Dec 16, 2019
837b8a4
dont take screenshots on travis. He doesn't like tatt
Dec 16, 2019
82fdddd
added fulltest
Jan 7, 2020
ad07a70
added some behat functions
Jan 8, 2020
5bffd46
formating
Feb 11, 2020
d8a951f
first commit
Jan 8, 2020
37d06d4
added condenser
Feb 11, 2020
cc45cd6
corrected mistake
Jan 15, 2020
dddb32d
removed inefficient condensing methods
Feb 11, 2020
760fb89
Made new condensed scenarios output instead of full output
Feb 11, 2020
7fb9424
fixed bugs
Feb 11, 2020
7e22e2d
added some documentation
Feb 11, 2020
f25661b
added PATH variable for the outputfile
Feb 11, 2020
7bed041
added relative path for generator
Feb 11, 2020
b06ec6d
reran generator
Feb 11, 2020
34b9b61
renamed variable to be better readable
Feb 11, 2020
7862133
Added warnings for no-data-situations
Feb 11, 2020
1740017
supports invalid courses
Feb 11, 2020
8ce3f31
added delayed enrolement
Feb 11, 2020
a038b4d
removed var_dump
Feb 18, 2020
5c12c1d
fixed '0' id main-course
Feb 18, 2020
157c98b
fixed bugs
Feb 20, 2020
42d8f96
implemented behat functionality
Feb 20, 2020
254d126
removed trailing newlines
Feb 20, 2020
249f502
added filecheck to prevent errors from errorhandling
Feb 19, 2020
da382ae
integrated matrix into job
Feb 19, 2020
7545b09
added space to satisfy the codingstyle
Feb 19, 2020
ff2a068
removed codingstyle violations in behat scenarios
Feb 20, 2020
6df211b
added case for the selector being hidden instead of disabled
Feb 20, 2020
46dc313
fixed travis error
Feb 27, 2020
ec5c2ee
fixed exceptions
Feb 27, 2020
a88624d
implemented tutors
Feb 27, 2020
0c951e7
fixed generator
Feb 27, 2020
15c78af
generated new tests
Feb 27, 2020
a1fab97
updated travis
Mar 2, 2020
d3404a5
run travis-behat with pretty format
Mar 2, 2020
c4ae6f6
rebuild stale amd files
Mar 2, 2020
07e4ec3
travis now uses proper behat installation
Mar 2, 2020
cffeee1
reworked tests to work with moodle course table instead of own temp
Apr 18, 2020
a5620e3
fixed bug where a started course could show standardtimecontrols
Apr 18, 2020
79688ea
split generator into text providing steps and "skeleton" code
Apr 18, 2020
2ee1bc6
removed old test
Apr 18, 2020
be1ec8e
removed unnecessary generator steps
Apr 18, 2020
8ecd9af
removed lsfcourseid var and introduced checking for coursetitle
Apr 18, 2020
f4272e4
fixed spelling mistake
Apr 18, 2020
8ac4f5a
removed accidentally pushed pycache
Apr 19, 2020
edb906b
now checking all block checks
Apr 19, 2020
1723719
added README section on testing
Apr 19, 2020
cf0cd3b
unified codingstyle
Apr 19, 2020
683d218
reran generator
Apr 19, 2020
3a77069
fixed styleerrors
Apr 19, 2020
0c4e2ec
integrate into master changes
Apr 27, 2020
59119b9
rewrote tests to work with previous master merge
Apr 27, 2020
631adbc
added missing strings
Apr 27, 2020
7557476
added missing strings
Apr 27, 2020
da9301b
fixed bug in install.xml
Apr 28, 2020
6000927
changed to postgres 9.5
Apr 28, 2020
cb8c2a9
removed vardump
May 11, 2020
9f4ae54
added missing string
May 12, 2020
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
40 changes: 16 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php

sudo: false
os: linux

dist: trusty

Expand All @@ -12,36 +12,20 @@ services:
- mysql

addons:
postgresql: "9.4"
postgresql: "9.5"

php:
- 7.0
- 7.1
- 7.2
- 7.3

matrix:
exclude:
- env: DB=pgsql MOODLE_BRANCH=master
php: 7.0
- env: DB=mysqli MOODLE_BRANCH=master
php: 7.0
- env: DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
php: 7.0
- env: DB=mysqli MOODLE_BRANCH=MOODLE_37_STABLE
php: 7.0
fast_finish: true

env:
global:
- IGNORE_PATHS=amd/build
matrix:
- DB=pgsql MOODLE_BRANCH=master
- DB=mysqli MOODLE_BRANCH=master
- DB=pgsql MOODLE_BRANCH=MOODLE_37_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_37_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_36_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_36_STABLE
- DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
- DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE

before_install:
- phpenv config-rm xdebug.ini
Expand All @@ -61,7 +45,7 @@ jobs:
# Prechecks against latest Moodle stable only.
- stage: static
php: 7.3
env: DB=mysqli MOODLE_BRANCH=MOODLE_37_STABLE
env: DB=mysqli MOODLE_BRANCH=MOODLE_38_STABLE
script:
- moodle-plugin-ci phplint
- moodle-plugin-ci phpcpd
Expand All @@ -75,15 +59,23 @@ jobs:
# Smaller build matrix for development builds
- stage: develop
php: 7.3
env: DB=mysqli MOODLE_BRANCH=MOODLE_37_STABLE
env: DB=pgsql MOODLE_BRANCH=MOODLE_38_STABLE
script:
- moodle-plugin-ci phpunit --coverage-clover
- moodle-plugin-ci behat
- cd moodle
- php -S localhost:8000 >/dev/null 2>&1 &
- cd ..
- sleep 10 # Wait for behat to start
- php moodle/admin/tool/behat/cli/run.php --tags="@block_evasys_sync"

# Default 'test' stage: Unit tests and behat tests against full matrix.
script:
- moodle-plugin-ci phpunit --coverage-clover
- moodle-plugin-ci behat
- cd moodle
- php -S localhost:8000 >/dev/null 2>&1 &
- cd ..
- sleep 10 # Wait for behat to start
- php moodle/admin/tool/behat/cli/run.php --tags="@block_evasys_sync_fulltest"

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
178 changes: 178 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,181 @@ Nach Klick auf obigen Button wird eine Übersicht über Befragungen angezeigt, d

In diesem Fall sind keine Befragungen vorbereitet. Falls Befragungen vorhanden sind, wird zusätzlich ein Button angezeigt, der zur Übertragung der Teilnehmerliste dient:
![Screenshot: Mit Evaluationen](https://cloud.githubusercontent.com/assets/432117/21343860/1d4ce964-c699-11e6-8cd9-2b20f3155153.png)

## Tests

Die Funktionsweise des Blocks wird durch Behattests sichergestellt.

##### Tests durchführen:
Um die Test durchzuführen führen sie:
`php moodle/admin/tool/behat/cli/run.php --tags="@block_evasys_sync"` aus. <br>
Mehr Infos dazu in der [Dokumentation](https://docs.moodle.org/dev/Running_acceptance_test)

##### Neue Tests schreiben:
- Diese Plugin verfügt über einen Behattest Generator, zu finden in `evasys_sync/tests/behat/generator` <br>
- Der Generator ist zweigeteilt. Um bestehende Schritte zu ändern reicht es die entsprechende Schrittdefiniton in `steps.py` zu finden und zu ändern.
- Um neue Schritte zu definieren, muss ein entsprechender Schritt in `steps.py` angelegt werden, und die entsprechenden parameter in `generator.py` als key im `OPTIONS dict` angelegt werden. zudem muss in den verwendeten methoden der Parameter hinzugefügt werden. <br>
Logischerweise muss der neue Schritt auch in `behat_block_evasys_sync` definiert werden sofern es kein Standardschritt ist.

######Generator
Der generelle Aufbau des Generators ist wie folgt:
<br>`steps.py`:
- direkte Texterzeugende Methoden sollten hier definiert werden.
- Für einfache Schritte die nur von einem Parameter abhängen können `dicts` benutzt werden.
- Bennenungskonventionen:
* `dicts`: <i>type</i>_<i>chechname_with_underscores</i>
* `functions`: <i>type</i>_<i>chechnamewithoutunderscores</i>
- _type_ richtet sich nach der Funktion des zurückgegebenen Texts im Context des Behat tests:
* `description`: Der zurückgegebene Text ist für die Scenariobeschreibung.
* `step`: Der zurückgegebene Text legt die Umgebung des Tests fest.
* `check`: Der zurückgegebene Text ist eine Überprüfung der erzeugten Seite.

<br>`generator.py`:
- 4 hauptmethoden die für die übergebenen Parameter entsprechende Texte zurückgeben:
* `get_checks` Gibt alle Checks aus
* `get_scenario` Gibt alle Umgebungsfestlegenden Texte zurück
* `get_combi_description` Gibt die Beschreibung eines Szenarios auch für eine mehrfachbelegung von parametern zurück
* `get_postcondensing_checks` Gibt die Checks die beim verkleinern der Szenarien nicht berücksichtigt werden sollen Zurück.

Der generator erzeutgt zunächst aus allen in `OPTIONS` festgelegten Parametern das Karthesische Produkt. <br>
Danach werden für jede Option die Checks berechnet.
Alle Optionen mit gleichem Check werden darauf überprüft ob sie durch das abändern eines
Parameters mit einer der anderen Optionen übereinstimmen. Wenn Ja wird angenommen, dass der Parameter nicht relevant für den Ausgang ist und die 2 Tests zusammengefasst.

######Mockingklassen:
Die Rückgaben des Evasys und LSF system werden für die Tests gemockt.<br>
Dies geschiet in den Dateien `lsf_api_mock_testable.php` sowie in der unterklasse `evasys_api_testable` in `evasys_api.php`
<br>
Die relationen sehen dabei wie folgt aus:<br>
`lsfid` &rarr; `(veranstnr, semestertext)` = `evasyskennung` <br>
Die daten werden als JSON array im `summary` Feld der `course` Tabelle gespeichert. Dabei haben die Daten folgende Form: <br>
`stdClass()->evacourses => array()`
<details name="evavardump">
<summary>Single Evacourse vardump</summary>

object(stdClass)[281]
public 'valid' => boolean true
public 'veranstnr' => int 0
public 'semestertxt' => string 'WS 2017/18' (length=10)
public 'studentcount' => int 100
public 'title' => string 'DynamicSurvey0' (length=14)
public 'surveys' =>
array (size=1)
0 =>
object(stdClass)[282]
public 'num' => int 0
public 'formid' => int 1
public 'is_open' => string 't' (length=1)
public 'form_count' => int 20
public 'pswd_count' => int 200
</details>

Das `stdClass->evacourses` Array sollte dabei für eine lsfid die entsprechende Datenstruktur [siehe vardump](#evavardump) zurückliefern.
<br>
Die gemockte lsfapi gibt lediglich `semestertext` und `veranstnr` zurück da die restlichen Werte nicht behötigt werden <br>
Auch die gemockte evasysapi gibt lediglich benutzte Werte zurück und füllt den Rest mit dummys. Sollte ein neuer Wert benötigt werden, so muss dieser hier eingefügt werden. <br>
Hier sind dafür Vardumps bereitgestellt, (evasys Struktur ändert sich je nachdem ob der Kurs eine oder mehrere Umfragen besitzt!!!):
<details>
<summary>Evasys Kurs Vardump</summary>

object(stdClass)[402]
public 'm_nCourseId' => int 166410
public 'm_sProgramOfStudy' => string '' (length=0)
public 'm_sCourseTitle' => string 'AutoMultiSurvey' (length=15)
public 'm_sRoom' => string '' (length=0)
public 'm_nCourseType' => int 1
public 'm_sPubCourseId' => string '1002 WS 2018/19' (length=15)
public 'm_sExternalId' => string '' (length=0)
public 'm_nCountStud' => int 2
public 'm_sCustomFieldsJSON' => string '{}' (length=2)
public 'm_nUserId' => int 73350
public 'm_nFbid' => int 338
public 'm_nPeriodId' => int 40
public 'm_aoParticipants' =>
object(stdClass)[404]
public 'm_aoSecondaryInstructors' =>
object(stdClass)[401]
public 'm_oSurveyHolder' =>
object(stdClass)[411]
public 'm_aSurveys' =>
object(stdClass)[412]
public 'Surveys' =>

</details>
<details>
<summary>Vardump von einem Kurs mit nur eimer Umfrage</summary>

public 'm_aSurveys' =>
object(stdClass)[412]
public 'Surveys' =>
object(stdClass)[413]
public 'm_nSurveyId' => int 330416933
public 'm_nState' => int 0
public 'm_sTitle' => string 'AutoMultiSurvey' (length=15)
public 'm_cType' => string 'o' (length=1)
public 'm_nFrmid' => int 832
public 'm_nStuid' => int 34763
public 'm_nVerid' => int 166410
public 'm_nOpenState' => int 1
public 'm_nFormCount' => int 0
public 'm_nPswdCount' => int 2
public 'm_sLastDataCollectionDate' => string '' (length=0)
public 'm_nPageLinkOffset' => int 0
public 'm_sMaskTan' => string '' (length=0)
public 'm_nMaskState' => int 0
public 'm_oPeriod' =>
object(stdClass)[414]
public 'm_nPeriodId' => int 40
public 'm_sTitel' => string 'WS 2018/19' (length=10)
public 'm_sStartDate' => string '2018-10-01' (length=10)
public 'm_sEndDate' => string '2019-03-31' (length=10)
</details>

<details>
<summary>Vardump von einem Kurs mit mehreren Umfragen</summary>

public 'm_aSurveys' =>
object(stdClass)[412]
public 'Surveys' =>
array (size=2)
0 =>
object(stdClass)[409]
public 'm_nSurveyId' => int 330416933
public 'm_nState' => int 0
public 'm_sTitle' => string 'AutoMultiSurvey' (length=15)
public 'm_cType' => string 'o' (length=1)
public 'm_nFrmid' => int 832
public 'm_nStuid' => int 34763
public 'm_nVerid' => int 166410
public 'm_nOpenState' => int 1
public 'm_nFormCount' => int 0
public 'm_nPswdCount' => int 2
public 'm_sLastDataCollectionDate' => string '' (length=0)
public 'm_nPageLinkOffset' => int 0
public 'm_sMaskTan' => string '' (length=0)
public 'm_nMaskState' => int 0
public 'm_oPeriod' =>
object(stdClass)[410]
...
1 =>
object(stdClass)[411]
public 'm_nSurveyId' => int 2114887341
public 'm_nState' => int 0
public 'm_sTitle' => string 'AutoMultiSurvey' (length=15)
public 'm_cType' => string 'o' (length=1)
public 'm_nFrmid' => int 784
public 'm_nStuid' => int 34763
public 'm_nVerid' => int 166410
public 'm_nOpenState' => int 1
public 'm_nFormCount' => int 0
public 'm_nPswdCount' => int 2
public 'm_sLastDataCollectionDate' => string '' (length=0)
public 'm_nPageLinkOffset' => int 0
public 'm_sMaskTan' => string '' (length=0)
public 'm_nMaskState' => int 0
public 'm_oPeriod' =>
object(stdClass)[410]
</details>

Letztlich ist noch zu bemerken, dass für über die `idnumber` verknüpfte Kurse immer ein Sommersemester als `semestertext` gewählt werden sollte,
entsprechend für über die Mappingfunktion verknüpfte Kurse ein Wintersemester, um gleiche Evasyskennungen zu vermeiden.
3 changes: 1 addition & 2 deletions adminsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@
}
$persistent = new \block_evasys_sync\user_cat_allocation(0, $record);
$persistent->create();

redirect($PAGE->url);
// redirect($PAGE->url);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont know how that got in there, will investigate

exit();
} else if (isset($data->submitbutton)) {
if (isset($data->evasys_wsdl_url)) {
Expand Down
3 changes: 2 additions & 1 deletion amd/build/edit_timeframe.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading