| [8c356c1] | 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 4 |
|
|---|
| 5 | This library is free software; you can redistribute it and/or
|
|---|
| 6 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 7 | License as published by the Free Software Foundation; either
|
|---|
| 8 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 9 |
|
|---|
| 10 | This library is distributed in the hope that it will be useful,
|
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | Lesser General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 16 | License along with this library; if not, write to the Free Software
|
|---|
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 18 | MA 02110-1301 USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | class SetupTest extends PHPUnit_Framework_TestCase
|
|---|
| 22 | {
|
|---|
| 23 | public static function setUpBeforeClass()
|
|---|
| 24 | {
|
|---|
| 25 | global $testconfig;
|
|---|
| 26 |
|
|---|
| 27 | $file = __DIR__ ."/testconfig/testconfig.php";
|
|---|
| 28 | self::assertFileExists($file);
|
|---|
| 29 | require($file);
|
|---|
| 30 | self::$_testconfig = $testconfig;
|
|---|
| [b38cc03] | 31 |
|
|---|
| [8c356c1] | 32 | require_once($testconfig["webserviceDirectory"] ."/inc/envsetup.php");
|
|---|
| [b38cc03] | 33 |
|
|---|
| [8c356c1] | 34 | self::$_webserviceConfig = new SiWeather\Webservice\WebserviceConfig();
|
|---|
| 35 | self::assertNotNull(self::$_webserviceConfig);
|
|---|
| [b38cc03] | 36 |
|
|---|
| [8c356c1] | 37 | self::$_dataDirectory = self::$_webserviceConfig->getConfig("dataDirectory");
|
|---|
| 38 | self::assertInternaltype("string", self::$_dataDirectory);
|
|---|
| 39 | self::assertTrue(!empty(self::$_dataDirectory));
|
|---|
| 40 | self::assertTrue(!file_exists(self::$_dataDirectory));
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public static function tearDownAfterClass()
|
|---|
| 44 | {
|
|---|
| 45 | if(!file_exists(self::$_dataDirectory)){
|
|---|
| 46 | return;
|
|---|
| 47 | }
|
|---|
| 48 | // clear data directory (not recursive, because there should be only a database file in it
|
|---|
| 49 | $content = scandir(self::$_dataDirectory);
|
|---|
| 50 | self::assertInternalType("array", $content);
|
|---|
| 51 | foreach($content as $file){
|
|---|
| 52 | if(!in_array($file, array(".",".."))){
|
|---|
| 53 | self::assertTrue(unlink(self::$_dataDirectory ."/". $file));
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | // remove datadirectory
|
|---|
| 58 | self::assertTrue(rmdir(self::$_dataDirectory));
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| [b38cc03] | 61 | public function testSetupFail() {
|
|---|
| [8c356c1] | 62 | $setup = new SiWeather\Webservice\Setup();
|
|---|
| 63 | $errorMessage = "";
|
|---|
| [b38cc03] | 64 |
|
|---|
| 65 | // all of the following setup routines should report errors (with errorMessages)!
|
|---|
| 66 | // check that data directory does not exists
|
|---|
| [8c356c1] | 67 | $result = $setup->dataDirectoryCheck($errorMessage);
|
|---|
| 68 | $this->assertEquals($result, SiWeather\Webservice\DataDirectoryChecks::NotExist, $errorMessage);
|
|---|
| [b38cc03] | 69 | $this->assertTrue(!empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 70 | $errorMessage = "";
|
|---|
| 71 |
|
|---|
| 72 | // check database directory
|
|---|
| 73 | $result = $setup->databaseDirectoryCheck($errorMessage);
|
|---|
| 74 | $this->assertEquals(!$result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
|
|---|
| 75 | $this->assertTrue(!empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 76 | $errorMessage = "";
|
|---|
| 77 |
|
|---|
| 78 | // open database connection (and configure the database, if necessary)
|
|---|
| 79 | $this->assertTrue(!$setup->databaseConnection($errorMessage), $errorMessage);
|
|---|
| 80 | $this->assertTrue(!empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 81 | $errorMessage = "";
|
|---|
| 82 |
|
|---|
| 83 | $prefix = "Database not connected";
|
|---|
| 84 | $versionSqlite = $setup->databaseVersionSqlite($errorMessage);
|
|---|
| 85 | $this->assertEquals($versionSqlite, 0, $prefix ." (Could not determine SQLite version: ". $errorMessage .")");
|
|---|
| 86 | $this->assertTrue(!empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 87 | $errorMessage = "";
|
|---|
| [8c356c1] | 88 |
|
|---|
| [b38cc03] | 89 | $versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);
|
|---|
| 90 | $this->assertEquals($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
|
|---|
| 91 | $this->assertTrue(!empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | public function testSetupWorking() {
|
|---|
| 95 | $setup = new SiWeather\Webservice\Setup();
|
|---|
| 96 | $errorMessage = "";
|
|---|
| 97 |
|
|---|
| 98 | // check that data directory does not exists
|
|---|
| 99 | $result = $setup->dataDirectoryCheck($errorMessage);
|
|---|
| 100 | $this->assertEquals($result, SiWeather\Webservice\DataDirectoryChecks::NotExist, $errorMessage);
|
|---|
| 101 | $this->assertTrue(!empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 102 | $errorMessage = "";
|
|---|
| 103 |
|
|---|
| [8c356c1] | 104 | // create data directory
|
|---|
| 105 | $result = $setup->dataDirectoryCreate($errorMessage);
|
|---|
| 106 | $this->assertEquals($result, SiWeather\Webservice\DataDirectoryChecks::Success, $errorMessage);
|
|---|
| [b38cc03] | 107 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| [8c356c1] | 108 |
|
|---|
| [b38cc03] | 109 | // check database directory
|
|---|
| [8c356c1] | 110 | $result = $setup->databaseDirectoryCheck($errorMessage);
|
|---|
| [b38cc03] | 111 | $this->assertEquals($result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
|
|---|
| 112 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 113 |
|
|---|
| 114 | // check database file (or if it could be created)
|
|---|
| [8c356c1] | 115 | $result = $setup->databaseFileCheck($errorMessage);
|
|---|
| [b38cc03] | 116 | $this->assertEquals($result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
|
|---|
| 117 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 118 |
|
|---|
| 119 | // open database connection (and configure the database, if necessary)
|
|---|
| 120 | $this->assertTrue($setup->databaseConnection($errorMessage), $errorMessage);
|
|---|
| 121 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 122 |
|
|---|
| 123 | $prefix = "Database up and running";
|
|---|
| 124 | $versionSqlite = $setup->databaseVersionSqlite($errorMessage);
|
|---|
| 125 | $this->assertLessThan($versionSqlite, 0, $prefix ." (Could not determine SQLite version: ". $errorMessage .")");
|
|---|
| 126 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 127 |
|
|---|
| 128 | $versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);
|
|---|
| 129 | $this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
|
|---|
| 130 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | public function testAlreadyConfigured(){
|
|---|
| 134 | $setup = new SiWeather\Webservice\Setup();
|
|---|
| 135 | $errorMessage = "";
|
|---|
| 136 |
|
|---|
| 137 | // check that data directory does not exists
|
|---|
| 138 | $result = $setup->dataDirectoryCheck($errorMessage);
|
|---|
| 139 | $this->assertEquals($result, SiWeather\Webservice\DataDirectoryChecks::Success, $errorMessage);
|
|---|
| 140 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 141 | $errorMessage = "";
|
|---|
| 142 |
|
|---|
| 143 | // check database directory
|
|---|
| 144 | $result = $setup->databaseDirectoryCheck($errorMessage);
|
|---|
| 145 | $this->assertEquals($result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
|
|---|
| 146 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 147 |
|
|---|
| 148 | // check database file (or if it could be created)
|
|---|
| 149 | $result = $setup->databaseFileCheck($errorMessage);
|
|---|
| 150 | $this->assertEquals($result, SiWeather\Webservice\DatabaseChecks::Success, $errorMessage);
|
|---|
| 151 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 152 |
|
|---|
| 153 | // open database connection (and configure the database, if necessary)
|
|---|
| 154 | $this->assertTrue($setup->databaseConnection($errorMessage), $errorMessage);
|
|---|
| 155 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| [8c356c1] | 156 |
|
|---|
| 157 | $prefix = "Database up and running";
|
|---|
| 158 | $versionSqlite = $setup->databaseVersionSqlite($errorMessage);
|
|---|
| 159 | $this->assertLessThan($versionSqlite, 0, $prefix ." (Could not determine SQLite version: ". $errorMessage .")");
|
|---|
| [b38cc03] | 160 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| 161 |
|
|---|
| [8c356c1] | 162 | $versionSpatalite = $setup->databaseVersionSpatalite($errorMessage);
|
|---|
| 163 | $this->assertLessThan($versionSpatalite, 0, $prefix ." (Could not determine Spatalite version: ". $errorMessage .")");
|
|---|
| [b38cc03] | 164 | $this->assertTrue(empty($errorMessage), "Error message \"". $errorMessage ."\" is not empty");
|
|---|
| [8c356c1] | 165 | }
|
|---|
| 166 |
|
|---|
| 167 | protected static $_webserviceConfig;
|
|---|
| 168 | protected static $_dataDirectory;
|
|---|
| 169 | protected static $_testconfig;
|
|---|
| 170 | }
|
|---|
| 171 | ?>
|
|---|