Project

General

Profile

« Previous | Next » 

Revision fa718a2c

Added by Andreas Kohlbecker over 4 years ago

fixing PHPUnit setup for php 7 and documenting its usage with PHPStorm

View differences:

.gitignore
6 6
/.settings
7 7
/target
8 8
/screenshots
9
/vendor
10

  
9 11

  
10 12
.idea/
11 13
.classpath
12 14
.settings/
15
composer.lock
13 16

  
14 17
C:\\nppdf32Log\\debuglog.txt
15 18
workbench.xmi
composer.json
1
{
2
  "name": "cybertaxonomy.org/cdm-dataportal",
3
  "description": "The dataportal publishes CDM data hosted in a CommunityStore on the web.",
4
  "minimum-stability": "stable",
5
  "license": "GPL2",
6
  "authors": [
7
    {
8
      "name": "Andreas Kohlbecker",
9
      "email": "a.kohlbecker@bgbm.org"
10
    }
11
  ],
12
  "require": {
13
    "phpunit/phpunit": "^8"
14
  }
15
}
modules/cdm_dataportal/cdm_api/cdm_api.module
2619 2619
}
2620 2620

  
2621 2621

  
2622
/**
2623
 * Validates if the given string is a uuid.
2624
 *
2625
 * @param string $str
2626
 *   The string to validate.
2627
 *
2628
 * return bool
2629
 *   TRUE if the string is a UUID.
2630
 */
2631
function is_uuid($str) {
2632
  return is_string($str) && strlen($str) == 36 && strpos($str, '-');
2633
}
2634

  
2635
/**
2636
 * Checks if the given $object is a valid cdm entity.
2637
 *
2638
 * An object is considered a cdm entity if it has a string field $object->class
2639
 * with at least 3 characters and if it has a valid uuid in $object->uuid.
2640
 * The function is null save.
2641
 *
2642
 * @author a.kohlbecker <a.kohlbecker@bgbm.org>
2643
 *
2644
 * @param mixed $object
2645
 *   The object to validate
2646
 *
2647
 * @return bool
2648
 *   True if the object is a cdm entity.
2649
 */
2650
function is_cdm_entity($object) {
2651
  return
2652
    isset($object->class) && is_string($object->class) && strlen($object->class) > 2 && $object->class != 'TypedEntityReference'
2653
    && is_string($object->uuid) && is_uuid($object->uuid);
2654
}
2655

  
2656 2622
/**
2657 2623
 * @todo Please document this function.
2658 2624
 * @see http://drupal.org/node/1354
modules/cdm_dataportal/cdm_api/commons.php
187 187
  }
188 188
  return $r;
189 189
}
190
?>
190

  
191

  
192
/**
193
 * Validates if the given string is a uuid.
194
 *
195
 * @param string $str
196
 *   The string to validate.
197
 *
198
 * return bool
199
 *   TRUE if the string is a UUID.
200
 */
201
function is_uuid($str) {
202
  return is_string($str) && strlen($str) == 36 && strpos($str, '-');
203
}
204

  
205
/**
206
 * Checks if the given $object is a valid cdm entity.
207
 *
208
 * An object is considered a cdm entity if it has a string field $object->class
209
 * with at least 3 characters and if it has a valid uuid in $object->uuid.
210
 * The function is null save.
211
 *
212
 * @author a.kohlbecker <a.kohlbecker@bgbm.org>
213
 *
214
 * @param mixed $object
215
 *   The object to validate
216
 *
217
 * @return bool
218
 *   True if the object is a cdm entity.
219
 */
220
function is_cdm_entity($object) {
221
  return
222
    isset($object->class) && is_string($object->class) && strlen($object->class) > 2 && $object->class != 'TypedEntityReference'
223
    && is_string($object->uuid) && is_uuid($object->uuid);
224
}
modules/cdm_dataportal/ide/eclipse/phpUnit.launch
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<launchConfiguration type="org.eclipse.php.debug.core.launching.PHPExeLaunchConfigurationType">
3
<stringAttribute key="ATTR_FILE" value="/Drupal-GIT/5.x/modules/cdm_dataportal/test/phpUnit/src/SimpleNameTest.php"/>
4
<stringAttribute key="ATTR_FILE_FULL_PATH" value="/home/andreas/workspaces/_svn-trunk/drupal-git/5.x/modules/cdm_dataportal/test/phpUnit/src/SimpleNameTest.php"/>
5
<stringAttribute key="ATTR_INI_LOCATION" value="/etc/php5/apache2/php.ini"/>
6
<stringAttribute key="ATTR_LOCATION" value="/usr/bin/php53/php"/>
7
<stringAttribute key="debugOutputEncoding" value="UTF-8"/>
8
<stringAttribute key="debugTransferEncoding" value="UTF-8"/>
9
<stringAttribute key="exeDebugArguments" value="--stderr --configuration ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml} ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/src/}"/>
10
<booleanAttribute key="firstLineBreakpoint" value="false"/>
11
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
12
<mapEntry key="DRUPAL_ROOT" value="/home/andreas/workspaces/www/Drupal5"/>
13
<mapEntry key="SITE_BASE_PATH" value="/flora-malesiana"/>
14
<mapEntry key="XDEBUG_CONFIG" value="idekey=ECLIPSE_DBGP"/>
15
</mapAttribute>
16
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
17
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
18
<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
19
<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
20
</listAttribute>
21
<stringAttribute key="org.eclipse.php.debug.core.PHP_Project" value="/Drupal-GIT"/>
22
<booleanAttribute key="org.eclipse.php.debug.core.RunWithDebugInfo" value="true"/>
23
<stringAttribute key="org.eclipse.php.debug.coreconfiguration_delegate_class" value="org.eclipse.php.internal.debug.core.launching.XDebugExeLaunchConfigurationDelegate"/>
24
<stringAttribute key="org.eclipse.php.debug.corephp_debugger_id" value="org.eclipse.php.debug.core.xdebugDebugger"/>
25
</launchConfiguration>
modules/cdm_dataportal/ide/eclipse/phpunit (external tools).launch
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
3
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="false"/>
4
<mapAttribute key="org.eclipse.debug.core.environmentVariables">
5
<mapEntry key="PHPBIN" value="C:\Programme\php-5.2.14\php.exe"/>
6
<mapEntry key="SCRIPT_NAME" value="${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/src}"/>
7
<mapEntry key="XDEBUG_CONFIG" value="idekey=ECLIPSE_DBGP"/>
8
</mapAttribute>
9
<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
10
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
11
</listAttribute>
12
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
13
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/usr/bin/php52/phpunit"/>
14
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="--configuration ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml}&#13;&#10;${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/src}"/>
15
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/}"/>
16
</launchConfiguration>
modules/cdm_dataportal/includes/test.php.inc
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: andreas
5
 * Date: 09.01.20
6
 * Time: 14:11
7
 */
modules/cdm_dataportal/test/phpUnit/.phpunit.result.cache
1
C:37:"PHPUnit\Runner\DefaultTestResultCache":331:{a:2:{s:7:"defects";a:2:{s:47:"ShortnameTest::test_cdm_dataportal_shortname_of";i:4;s:47:"StatisticalValuesTests::test_statistical_values";i:4;}s:5:"times";a:3:{s:27:"TestTests::test_fancymodule";d:0.002;s:47:"ShortnameTest::test_cdm_dataportal_shortname_of";d:0.003;s:47:"StatisticalValuesTests::test_statistical_values";d:0.003;}}}
modules/cdm_dataportal/test/phpUnit/README
1
HOW TO RUN THE PHPUNIT TESTS IN ECLIPSE
2
============================================
3
Author: Andreas Kohlbecker, 2012
4

  
5

  
6
NOTE: these tests are to be run from within {DRUPAL_ROOT}/sites/*/modules/cdm_dataportal/test/phpunit
7

  
8

  
9
 Install PHPunit
10
----------------------------------------------
11

  
12
in the following we assume that you have installed php5.2 manually according to the
13
guidance given in http://dev.e-taxonomy.eu/trac/wiki/Install_php5.3_to_php5.2_in_parallel
14

  
15

  
16
update PEAR:
17

  
18
	cd /usr/bin/php52
19
	sudo ./pear config-set auto_discover 1
20
	sudo ./pear install phpunit/PHPUnit
21

  
22
 the above should be sufficient,
23
 but in case something is going wrong you also can try :
24

  
25
  	sudo ./pear upgrade pear
26
	sudo ./pear channel-discover pear.phpunit.de
27

  
28
phpUnit should now be installed in /usr/share/php52/pear/PHPUnit
29

  
30
you may also have to install PHP_CodeCoverage:
31

  
32
	sudo ./pear channel-discover components.ez.no
33
	sudo ./pear install phpunit/PHP_CodeCoverage
34
	sudo ./pear install pear.phpunit.de/PHP_CodeCoverage
35

  
36

  
37
and also xdebug:
38

  
39
	sudo ./pecl install xdebug
40

  
41

  
42

  
43
 Adding the PEAR libraries to eclipse
44
----------------------------------------------
45

  
46
based on http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit#Configure_XDebug_Debugger_to_work_with_PHPUnit
47

  
48
 1. First make sure that your project has the correct include and build path.
49
    Right click on your project in the navigator and select "Properties".
50
    Then navigate to the "PHP Include Path" preference page.
51
    Click on the "Libraries" tab, then click "Add Library..."
52
    Click '"Next" ---> "Config" --> (Preferences php/php libraries) "New"
53

  
54
    Enter the library name "PEAR" and add it to the environment.
55
	After returning to the preferences page click the "Add external folder..." button
56
	Find your PEAR folder (usually you find it in your PHP directory, as
57
	in our case of  php5.2 installed manually where it is /usr/share/php52/pear.
58
	In some distributions it is the php folder itself rather than the PEAR folder
59
	as most PEAR packages (including PHPUnit) are directly installed into /usr/share/php.)
60
	Return to the preferences page and click "Ok"
61

  
62

  
63
 Running phpunit tests in eclipse
64
----------------------------------------------
65

  
66
 what we are now trying to achieve with the eclipse launcher configuration is in principle
67
 to run the following command:
68

  
69
  /usr/bin/php52/php /usr/bin/php52/phpunit --verbose --bootstrap bootstrap.php
70

  
71
therefore we provide the script phpunitRunner.php which will execute phpUnit.
72
In order to configure it properly you need to supply some environment variables.
73

  
74
  DRUPAL_ROOT - path to the root of your Drupal installation, that is dataportal installation.
75
  XDEBUG_CONFIG - must be set to 'idekey=ECLIPSE_DBGP'
76
  SITE_BASE_PATH - set this variable to the base path of the dataportal website you want to use for testing, eg: /flora-malesiana
77

  
78

  
79
Create a new php run configuration which executes phpunitRunner.php and configure the above named
80
environment variables in the "Environment" tab.
81
In the "PhpScriptArgument" tab set the following:
82

  
83
  	--stderr --configuration ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml} ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/src/}
84

  
85

  
86

  
87

  
modules/cdm_dataportal/test/phpUnit/README.md
1
Running PHPUnit tests in PHPStorm
2
============================================
3

  
4
Author: Andreas Kohlbecker, 2012–2020
5

  
6

  
7
**Official PhPStorm documentation on PHPUnit tests:**
8

  
9
* https://www.jetbrains.com/help/phpstorm/using-phpunit-framework.html
10
* https://www.jetbrains.com/help/phpstorm/php-test-frameworks.html
11
* https://www.jetbrains.com/help/phpstorm/using-the-composer-dependency-manager.html
12
* https://www.jetbrains.com/help/phpstorm/php-interpreters.html
13

  
14

  
15
/usr/bin/php /home/andreas/workspaces/cdm/cdm-dataportal/vendor/phpunit/phpunit/phpunit --configuration /home/andreas/workspaces/cdm/cdm-dataportal/modules/cdm_dataportal/test/phpUnit/phpUnit.xml StatisticalValuesTests /home/andreas/workspaces/cdm/cdm-dataportal/modules/cdm_dataportal/test/phpUnit/src/unit/statistical_values_tests.php
16

  
17

  
18

  
19
Install PHPUnit
20
----------------------------------------------
21

  
22
In Debian based Linux distros PHPUnit usually can be installed by
23

  
24
    apt-get install phpunit
25

  
26
the recommended way for whowever is the installation via [Composer](https://getcomposer.org/) 
27
the state of the art dependency manager for PHP.
28

  
29
    apt-get install composer
30
    
31
The `cdm-dataportal` project contains a `composer.json` file which sets *phpunit version 8* as dependency for this project.
32
PHPStorm should detect this configuration file. You can check this by opening the settings page **Language&Frameworks > PHP > Composer** 
33
which shoould look like:
34
 
35
 ![](phpStorm-composer-configuration.png)
36

  
37
**NOTE:** You may also want to install PHP_CodeCoverage by adding the dependency to `composer.json`.
38

  
39

  
40

  
41
Install XDebug
42
----------------------------------------------
43

  
44

  
45
xdebug can easily be installed via pecl:
46

  
47
	pecl install xdebug
48
    
49
at the end of the output pecl shows:
50
     
51
    ...
52
    Build process completed successfully
53
    Installing '/usr/lib/php5/20121212/xdebug.so'
54
	
55
	
56
After successful installation the XDebug extension binary will be located for example in `/usr/lib/php/*/xdebug.so`.
57
In order to make XDebug available to the PHP CLI you need to set this location in the settings page **File > Settings > 
58
Languages and Frameworks > PHP** as *Debugger extension*:
59

  
60
![](phpStorm-php-cli-configuration.png)
61

  
62

  
63
Configure PHPUnit in PHPStorm
64
-----------------------------------------------
65

  
66
PHPStorm should have autodetected the PHPUnit installed via Composer already
67
Open the settings page **File > Settings > Languages and Frameworks > PHP > Test Frameworks** make sure the option 
68
"*Use Composer Autoloader*" is checked and set `modules/cdm_dataportal/test/phpUnit/phpUnit.xml` as *Default configuration file*.
69

  
70
![](phpStorm-phpunit-configuration.png)
71

  
72

  
73
Running PHPUnit tests in PHPStorm
74
---------------------------------------------------------------
75

  
76
Simply right click on a test file and choose *Run 'TestFile' (PHPUnit)* in the context menu.
77

  
78

  
79
Running PHPUnit tests via the phpunitRunner.php script (DEPRECATED)
80
---------------------------------------------------------------
81

  
82
*This has only been preseved since it could be useful for running test suites from the commandline or in the CI server.*
83

  
84
 what we are now trying to achieve with the eclipse launcher configuration is in principle
85
 to run the following command:
86

  
87
  /usr/bin/php52/php /usr/bin/php52/phpunit --verbose --bootstrap bootstrap.php
88

  
89
therefore we provide the script phpunitRunner.php which will execute phpUnit.
90
In order to configure it properly you need to supply some environment variables.
91

  
92
  DRUPAL_ROOT - path to the root of your Drupal installation, that is dataportal installation.
93
  XDEBUG_CONFIG - must be set to 'idekey=ECLIPSE_DBGP'
94
  SITE_BASE_PATH - set this variable to the base path of the dataportal website you want to use for testing, eg: /flora-malesiana
95

  
96

  
97
Create a new php run configuration which executes phpunitRunner.php and configure the above named
98
environment variables in the "Environment" tab.
99
In the "PhpScriptArgument" tab set the following:
100

  
101
  	--stderr --configuration ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml} ${workspace_loc:/Drupal5/sites/all/modules/cdm_dataportal/test/phpUnit/src/}
102

  
103

  
104

  
105

  
modules/cdm_dataportal/test/phpUnit/bootstrap.php
6 6

  
7 7
// TestUtils.php must be included at the very first step
8 8

  
9
module_load_include('php', 'bootstrap', 'estUtils');
9
module_load_include('php', 'bootstrap', 'TestUtils');
10 10

  
11 11
if (empty($_ENV['DRUPAL_ROOT'])) {
12
  print('environment variable "DRUPAL_ROOT" mnust point to the root of the Drupal installation.');
12
  print('environment variable "DRUPAL_ROOT" must point to the root of the Drupal installation.');
13 13
  exit(-1);
14 14
}
15 15
chdir($_ENV['DRUPAL_ROOT']); // cd to {DRUPAL_ROOT}
modules/cdm_dataportal/test/phpUnit/phpUnit.conf.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<phpunit bootstrap="bootstrap.php">
3
	
4
	<php>
5
	  <ini name="error_reporting" value="E_ALL &amp; ~E_NOTICE" />
6
	  <ini name="display_errors" value="TRUE" />
7
    <ini name="display_startup_errors" value="TRUE" />
8
	</php>
9
	
10
  <testsuites>
11
	  <testsuite name="benchmark">
12
	    <file>src/cdm_dataportal.moduleTest.php</file>
13
	  </testsuite>
14
  </testsuites>
15
  
16
</phpunit>
modules/cdm_dataportal/test/phpUnit/phpUnit.drupal-integration-test.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<!--
4
	This phpUnit configuration will cause a full bootstrap of drupal to allow for full integration tests
5
	FIXME: bootstrap.php currently causes the php interpreter to exit code 255
6
-->
7
<phpunit bootstrap="bootstrap.php">
8
	
9
	<php>
10
	  <ini name="error_reporting" value="E_ALL &amp; ~E_NOTICE" />
11
	  <ini name="display_errors" value="TRUE" />
12
    <ini name="display_startup_errors" value="TRUE" />
13
	</php>
14
	
15
  <testsuites>
16
	  <testsuite name="benchmark">
17
	    <file>src/integration/cdm_dataportal.moduleTest.php</file>
18
	  </testsuite>
19
  </testsuites>
20
  
21
</phpunit>
modules/cdm_dataportal/test/phpUnit/phpUnit.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<!--
4
    Configuration for simple unit tests which do not require bootstrapping of drupal
5
    The test cases are located in ./src/unit-tests
6
-->
7
<phpunit defaultTestSuite="unit">
8
    <php>
9
        <!--
10
            include_path: must point to the folder modules/cdm_dataportal
11
        -->
12
        <includePath>../..</includePath>
13

  
14
        <ini name="error_reporting" value="E_ALL"/>
15
        <!--
16
        <ini name="display_errors" value="TRUE"/>
17
        <ini name="display_startup_errors" value="TRUE"/>
18
        -->
19
    </php>
20

  
21

  
22
    <testsuites>
23
        <testsuite name="unit">
24
            <directory>src/unit/</directory>
25
        </testsuite>
26
    </testsuites>
27

  
28
</phpunit>
modules/cdm_dataportal/test/phpUnit/resources/integration/theme/cdm_dataportal.name.themeTest-taxon1.json
1
{
2
    "appendedPhrase": "",
3
    "class": "Taxon",
4
    "created": "2011-01-17T12:53:58.000+01:00",
5
    "data": [
6

  
7
    ],
8
    "doubtful": false,
9
    "excluded": false,
10
    "lsid": null,
11
    "protectedTitleCache": false,
12
    "taxonStatusUnknown": false,
13
    "taxonomicChildrenCount": 0,
14
    "titleCache": "Alectryon myrmecophilus Leenh. sec. Flora Malesiana - Sapindaceae I",
15
    "unplaced": false,
16
    "updated": "2011-04-01T17:31:18.795+02:00",
17
    "useNameCache": false,
18
    "uuid": "0ae4f7ab-f482-482c-ba57-cf0e4389a417",
19
    "name": {
20
        "anamorphic": false,
21
        "appendedPhrase": "",
22
        "basionymAuthorship": null,
23
        "binomHybrid": false,
24
        "class": "BotanicalName",
25
        "created": "2011-01-17T12:53:58.000+01:00",
26
        "data": [
27

  
28
        ],
29
        "exBasionymAuthorship": null,
30
        "exCombinationAuthorship": null,
31
        "genusOrUninomial": "Alectryon",
32
        "hybridFormula": false,
33
        "infraGenericEpithet": "",
34
        "infraSpecificEpithet": "",
35
        "lsid": null,
36
        "monomHybrid": false,
37
        "nomenclaturalCode": "ICNAFP",
38
        "nomenclaturalMicroReference": "223; 33 (1988) 319",
39
        "parsingProblem": 0,
40
        "problemEnds": -1,
41
        "problemStarts": -1,
42
        "protectedAuthorshipCache": false,
43
        "protectedFullTitleCache": false,
44
        "protectedNameCache": false,
45
        "protectedTitleCache": false,
46
        "specificEpithet": "myrmecophilus",
47
        "titleCache": "Alectryon myrmecophilus Leenh.",
48
        "trinomHybrid": false,
49
        "updated": "2011-04-05T16:15:35.581+02:00",
50
        "uuid": "641a0d51-fa0b-49b4-b335-53746ea2bf83",
51
        "taggedName": [
52
            {
53
                "class": "TaggedText",
54
                "text": "Alectryon",
55
                "type": "name"
56
            },
57
            {
58
                "class": "TaggedText",
59
                "text": "myrmecophilus",
60
                "type": "name"
61
            },
62
            {
63
                "class": "TaggedText",
64
                "text": "Leenh.",
65
                "type": "authors"
66
            }
67
        ]
68
    }
69
}
modules/cdm_dataportal/test/phpUnit/resources/theme/cdm_dataportal.name.themeTest-taxon1.json
1
{
2
    "appendedPhrase": "",
3
    "class": "Taxon",
4
    "created": "2011-01-17T12:53:58.000+01:00",
5
    "data": [
6

  
7
    ],
8
    "doubtful": false,
9
    "excluded": false,
10
    "lsid": null,
11
    "protectedTitleCache": false,
12
    "taxonStatusUnknown": false,
13
    "taxonomicChildrenCount": 0,
14
    "titleCache": "Alectryon myrmecophilus Leenh. sec. Flora Malesiana - Sapindaceae I",
15
    "unplaced": false,
16
    "updated": "2011-04-01T17:31:18.795+02:00",
17
    "useNameCache": false,
18
    "uuid": "0ae4f7ab-f482-482c-ba57-cf0e4389a417",
19
    "name": {
20
        "anamorphic": false,
21
        "appendedPhrase": "",
22
        "basionymAuthorship": null,
23
        "binomHybrid": false,
24
        "class": "BotanicalName",
25
        "created": "2011-01-17T12:53:58.000+01:00",
26
        "data": [
27

  
28
        ],
29
        "exBasionymAuthorship": null,
30
        "exCombinationAuthorship": null,
31
        "genusOrUninomial": "Alectryon",
32
        "hybridFormula": false,
33
        "infraGenericEpithet": "",
34
        "infraSpecificEpithet": "",
35
        "lsid": null,
36
        "monomHybrid": false,
37
        "nomenclaturalCode": "ICNAFP",
38
        "nomenclaturalMicroReference": "223; 33 (1988) 319",
39
        "parsingProblem": 0,
40
        "problemEnds": -1,
41
        "problemStarts": -1,
42
        "protectedAuthorshipCache": false,
43
        "protectedFullTitleCache": false,
44
        "protectedNameCache": false,
45
        "protectedTitleCache": false,
46
        "specificEpithet": "myrmecophilus",
47
        "titleCache": "Alectryon myrmecophilus Leenh.",
48
        "trinomHybrid": false,
49
        "updated": "2011-04-05T16:15:35.581+02:00",
50
        "uuid": "641a0d51-fa0b-49b4-b335-53746ea2bf83",
51
        "taggedName": [
52
            {
53
                "class": "TaggedText",
54
                "text": "Alectryon",
55
                "type": "name"
56
            },
57
            {
58
                "class": "TaggedText",
59
                "text": "myrmecophilus",
60
                "type": "name"
61
            },
62
            {
63
                "class": "TaggedText",
64
                "text": "Leenh.",
65
                "type": "authors"
66
            }
67
        ]
68
    }
69
}
modules/cdm_dataportal/test/phpUnit/src/SimpleNameTest.php
1
<?php
2

  
3
/**
4
 * test to test if phpUnit is ok
5
 * @author a.kohlbecker
6
 *
7
 */
8
class ShortnameTest extends PHPUnit_Framework_TestCase {
9

  
10
  /*
11
   --------'BACILLARIOPHYCEAE (FOSS.)'---------
12
   --------'BACILLUS OBSCURUS (FOSS.)'---------
13
   >>> B. OBSCURUS (FOSS.)
14
   --------'Lapsana communis L.'---------
15
   >>> L. communis L.
16
   --------'Lapsana L.'---------
17
   --------'Lapsana communis subsp. adenophora (Boiss.) Rech.'---------
18
   >>> L. communis subsp. adenophora (Boiss.) Rech.
19
   --------'Asterolampra marylandica'---------
20
   >>> A. marylandica
21
   --------'Ophrys ×"kreutziana"'---------
22
   >>> O. ×"kreutziana"
23
   --------'Ophrys bornmuelleri subsp. bornmuelleri × subsp. grandiflora'---------
24
   >>> O. bornmuelleri subsp. bornmuelleri × subsp. grandiflora
25
   --------'Aegilops ×insulae-cypri'---------
26
   >>> A. ×insulae-cypri
27

  
28
   */
29

  
30
  function test_cdm_dataportal_shortname_of() {
31
    $testStrings = array(
32
      "BACILLARIOPHYCEAE (FOSS.)" => "BACILLARIOPHYCEAE (FOSS.)",
33
      "BACILLUS OBSCURUS (FOSS.)" => "B. OBSCURUS (FOSS.)",
34
      "Lapsana communis L." => "L. communis L.",
35
      "Lapsana L." => "Lapsana L.",
36
      "Lapsana communis subsp. adenophora (Boiss.) Rech." => "L. communis subsp. adenophora (Boiss.) Rech.",
37
      "Asterolampra marylandica" => "A. marylandica",
38
      "Ophrys ×\"kreutziana\"" => "O. ×\"kreutziana\"",
39
      "Ophrys bornmuelleri subsp. bornmuelleri × subsp. grandiflora" => "O. bornmuelleri subsp. bornmuelleri × subsp. grandiflora",
40
      "Aegilops ×insulae-cypri" => "A. ×insulae-cypri",
41
      "Hieracium harjuënse Sennikov" => "H. harjuënse Sennikov",
42
      "Hieracium harjuënse" => "H. harjuënse",
43
    );
44

  
45
    foreach ($testStrings as $nameString => $shortname) {
46
      $tagtxt->type = "name";
47
      $tagtxt->text = $nameString;
48
      $name->taggedTitle = array($tagtxt);
49
      $result = cdm_dataportal_shortname_of($name);
50

  
51
      $this->assertEquals($shortname, $result);
52
    }
53
  }
54
}
modules/cdm_dataportal/test/phpUnit/src/cdm_dataportal.moduleTest.php
1
<?php
2

  
3
class ModuleTests extends PHPUnit_Framework_TestCase {
4

  
5
  function test_load_polytomousKey() {
6

  
7
    $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
8

  
9
    print("\n\n<h4>Benchmarking web services: deep initialization vs. bit-by-bit initialization</h4>\n"
10
		. $polytomousKeysPager->count . " PolytomousKeys to load.\n");
11

  
12
    print("<table border=\"1\">\n<tr><th>key uuid</td><td>bit-by-bit initialization</td><td>deep initialization</td></tr>\n");
13
    flush();
14

  
15
    $time_load_bbb_total = 0;
16
    $time_load_deep_total = 0;
17
    $i = 0;
18
    foreach ($polytomousKeysPager->records as $polytomousKey) {
19

  
20
      if (! is_uuid($polytomousKey->uuid)) {
21
        continue;
22
      }
23
      //			if($i++ == 4){
24

  
25
      //				break;
26

  
27
      //			}
28

  
29

  
30
      print("<tr><td>$polytomousKey->uuid</td>");
31
      // ---- bit-by-bit ---- //
32

  
33
      $time_load_start = microtime(true);
34
      $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKey->uuid);
35
      _load_polytomousKeySubGraph($polytomousKey->root);
36
      $time_load = microtime(true) - $time_load_start;
37
      //			if($i++ == 1){
38

  
39
      //				var_dump($polytomousKey);
40

  
41
      //			}
42

  
43
      $time_load_bbb_total += $time_load;
44
      print("<td>" . sprintf('%3.3f', $time_load) . "s</td>");
45

  
46
      // ---- deep ---- //
47

  
48
      $time_load_start = microtime(true);
49
      $polytomousKey = cdm_ws_get("portal/" . CDM_WS_POLYTOMOUSKEY, array($polytomousKey->uuid, "loadWithNodes"));
50
      $time_load = microtime(true) - $time_load_start;
51
      //			if($i++ == 1){
52

  
53
//        var_dump($polytomousKey);
54

  
55
//      }
56

  
57
      $time_load_deep_total += $time_load;
58
      print("<td>" . sprintf('%3.3f', $time_load) . "s</td></tr>\n");
59

  
60
    }
61
    print("<tr><td>total time</td><td>" . sprintf('%3.3f', $time_load_bbb_total) . "s</td><td>" . sprintf('%3.3f', $time_load_deep_total) . "s</td></tr>\n");
62
    flush();
63

  
64
  }
65

  
66
}
modules/cdm_dataportal/test/phpUnit/src/integration/SimpleNameTest.php
1
<?php
2

  
3
use PHPUnit\Framework\TestCase;
4

  
5

  
6
class ShortnameTest extends TestCase {
7

  
8
  /*
9
   --------'BACILLARIOPHYCEAE (FOSS.)'---------
10
   --------'BACILLUS OBSCURUS (FOSS.)'---------
11
   >>> B. OBSCURUS (FOSS.)
12
   --------'Lapsana communis L.'---------
13
   >>> L. communis L.
14
   --------'Lapsana L.'---------
15
   --------'Lapsana communis subsp. adenophora (Boiss.) Rech.'---------
16
   >>> L. communis subsp. adenophora (Boiss.) Rech.
17
   --------'Asterolampra marylandica'---------
18
   >>> A. marylandica
19
   --------'Ophrys ×"kreutziana"'---------
20
   >>> O. ×"kreutziana"
21
   --------'Ophrys bornmuelleri subsp. bornmuelleri × subsp. grandiflora'---------
22
   >>> O. bornmuelleri subsp. bornmuelleri × subsp. grandiflora
23
   --------'Aegilops ×insulae-cypri'---------
24
   >>> A. ×insulae-cypri
25

  
26
   */
27

  
28
  function test_cdm_dataportal_shortname_of() {
29
    $testStrings = array(
30
      "BACILLARIOPHYCEAE (FOSS.)" => "BACILLARIOPHYCEAE (FOSS.)",
31
      "BACILLUS OBSCURUS (FOSS.)" => "B. OBSCURUS (FOSS.)",
32
      "Lapsana communis L." => "L. communis L.",
33
      "Lapsana L." => "Lapsana L.",
34
      "Lapsana communis subsp. adenophora (Boiss.) Rech." => "L. communis subsp. adenophora (Boiss.) Rech.",
35
      "Asterolampra marylandica" => "A. marylandica",
36
      "Ophrys ×\"kreutziana\"" => "O. ×\"kreutziana\"",
37
      "Ophrys bornmuelleri subsp. bornmuelleri × subsp. grandiflora" => "O. bornmuelleri subsp. bornmuelleri × subsp. grandiflora",
38
      "Aegilops ×insulae-cypri" => "A. ×insulae-cypri",
39
      "Hieracium harjuënse Sennikov" => "H. harjuënse Sennikov",
40
      "Hieracium harjuënse" => "H. harjuënse",
41
    );
42

  
43
    foreach ($testStrings as $nameString => $shortname) {
44
      $tagtxt->type = "name";
45
      $tagtxt->text = $nameString;
46
      $name->taggedTitle = array($tagtxt);
47
      $result = cdm_dataportal_shortname_of($name);
48

  
49
      $this->assertEquals($shortname, $result);
50
    }
51
  }
52
}
modules/cdm_dataportal/test/phpUnit/src/integration/cdm_dataportal.moduleTest.php
1
<?php
2

  
3
use PHPUnit\Framework\TestCase;
4

  
5
class ModuleTests extends TestCase {
6

  
7
  function test_load_polytomousKey() {
8

  
9
    $polytomousKeysPager = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKeyUuid);
10

  
11
    print("\n\n<h4>Benchmarking web services: deep initialization vs. bit-by-bit initialization</h4>\n"
12
		. $polytomousKeysPager->count . " PolytomousKeys to load.\n");
13

  
14
    print("<table border=\"1\">\n<tr><th>key uuid</td><td>bit-by-bit initialization</td><td>deep initialization</td></tr>\n");
15
    flush();
16

  
17
    $time_load_bbb_total = 0;
18
    $time_load_deep_total = 0;
19
    $i = 0;
20
    foreach ($polytomousKeysPager->records as $polytomousKey) {
21

  
22
      if (! is_uuid($polytomousKey->uuid)) {
23
        continue;
24
      }
25
      //			if($i++ == 4){
26

  
27
      //				break;
28

  
29
      //			}
30

  
31

  
32
      print("<tr><td>$polytomousKey->uuid</td>");
33
      // ---- bit-by-bit ---- //
34

  
35
      $time_load_start = microtime(true);
36
      $polytomousKey = cdm_ws_get(CDM_WS_POLYTOMOUSKEY, $polytomousKey->uuid);
37
      _load_polytomousKeySubGraph($polytomousKey->root);
38
      $time_load = microtime(true) - $time_load_start;
39
      //			if($i++ == 1){
40

  
41
      //				var_dump($polytomousKey);
42

  
43
      //			}
44

  
45
      $time_load_bbb_total += $time_load;
46
      print("<td>" . sprintf('%3.3f', $time_load) . "s</td>");
47

  
48
      // ---- deep ---- //
49

  
50
      $time_load_start = microtime(true);
51
      $polytomousKey = cdm_ws_get("portal/" . CDM_WS_POLYTOMOUSKEY, array($polytomousKey->uuid, "loadWithNodes"));
52
      $time_load = microtime(true) - $time_load_start;
53
      //			if($i++ == 1){
54

  
55
//        var_dump($polytomousKey);
56

  
57
//      }
58

  
59
      $time_load_deep_total += $time_load;
60
      print("<td>" . sprintf('%3.3f', $time_load) . "s</td></tr>\n");
61

  
62
    }
63
    print("<tr><td>total time</td><td>" . sprintf('%3.3f', $time_load_bbb_total) . "s</td><td>" . sprintf('%3.3f', $time_load_deep_total) . "s</td></tr>\n");
64
    flush();
65

  
66
  }
67

  
68
}
modules/cdm_dataportal/test/phpUnit/src/integration/theme/cdm_dataportal.name.themeTest.php
1
<?php
2

  
3
class NameThemeTests extends PHPUnit_Framework_TestCase {
4

  
5
  function test_render_taxon_or_name() {
6
    $taxon1_file = "theme/cdm_dataportal.name.themeTest-taxon1.json";
7
    $taxon = TestUtils::load_from_json_resource($taxon1_file);
8
    $this->assertEquals($taxon->uuid, "0ae4f7ab-f482-482c-ba57-cf0e4389a417");
9
    $out = render_taxon_or_name($taxon->name);
10
    TestUtils::stderr($out);
11
  }
12

  
13
}
modules/cdm_dataportal/test/phpUnit/src/testTest.php
1
<?php
2

  
3
/**
4
 * test to test if phpUnit is ok
5
 * @author a.kohlbecker
6
 *
7
 */
8
class TestTests extends PHPUnit_Framework_TestCase {
9
  function test_fancymodule() {
10
    $this->assertInternalType("string", "true");
11
  }
12
}
modules/cdm_dataportal/test/phpUnit/src/theme/cdm_dataportal.name.themeTest.php
1
<?php
2

  
3
class NameThemeTests extends PHPUnit_Framework_TestCase {
4

  
5
  function test_render_taxon_or_name() {
6
    $taxon1_file = "theme/cdm_dataportal.name.themeTest-taxon1.json";
7
    $taxon = TestUtils::load_from_json_resource($taxon1_file);
8
    $this->assertEquals($taxon->uuid, "0ae4f7ab-f482-482c-ba57-cf0e4389a417");
9
    $out = render_taxon_or_name($taxon->name);
10
    TestUtils::stderr($out);
11
  }
12

  
13
}
modules/cdm_dataportal/test/phpUnit/src/unit/statistical_values_tests.php
1
<?php
2

  
3
use PHPUnit\Framework\TestCase;
4

  
5
// these includes require <includePath>../..</includePath> to be set in phpUnit.xml
6
include 'includes/common.inc';
7
include 'cdm_api/commons.php';
8

  
9
/**
10
 * test to test if phpUnit is ok
11
 * @author a.kohlbecker
12
 *
13
 */
14
class StatisticalValuesTests extends TestCase {
15

  
16
  function new_statistical_value($value = null){
17
    $stat_val = new stdClass();
18
    $stat_val->_value = $value;
19
    return $stat_val;
20
  }
21

  
22
  function create_statistical_values($typicalLowerBoundary = null, $typicalUpperrBoundary = null, $average  = null, $sampleSize = null){
23
    $stat_vals = statistical_values_array();
24
    $stat_vals['TypicalLowerBoundary'] = $this->new_statistical_value($typicalLowerBoundary);
25
    $stat_vals['TypicalUpperBoundary'] = $this->new_statistical_value($typicalUpperrBoundary);
26
    $stat_vals['SampleSize'] = $this->new_statistical_value($sampleSize);
27
    $stat_vals['Average'] = $this->new_statistical_value($average);
28
    return $stat_vals;
29
  }
30

  
31
  function html2text($html){
32
    return  html_entity_decode(strip_tags($html), ENT_COMPAT, 'utf-8');
33
  }
34

  
35
  function test_statistical_values() {
36

  
37
    $stat_vals = $this->create_statistical_values(0.123457,  0.123456, 0.123456523847, 5);
38

  
39
    $this->assertEquals('0.123457–0.123456[5;x̄=0.1234565]', $this->html2text(statistical_values($stat_vals)));
40
  }
41

  
42
}
modules/cdm_dataportal/test/phpUnit/src/unit/testTest.php
1
<?php
2

  
3
declare(strict_types=1);
4

  
5
use PHPUnit\Framework\TestCase;
6

  
7

  
8
/**
9
 * test to test if phpUnit is ok
10
 * @author a.kohlbecker
11
 *
12
 */
13
class TestTests extends TestCase {
14

  
15
  function test_fancymodule() {
16
    $this->assertTrue(true);
17
  }
18

  
19
}

Also available in: Unified diff