commit
8e4b47d6e1
|
@ -22,6 +22,7 @@ test/php/bin/extcmd_test
|
|||
|
||||
# misc test output
|
||||
test/frontend/static/public
|
||||
test/php/library/Icinga/Protocol/Statusdat/.cache
|
||||
|
||||
# Generated API documentation
|
||||
doc/api
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
# Frontend component tests
|
||||
|
||||
Frontend tests test your code from the users perspective: By opening a specific url, executing a few clicks, strokes, etc.
|
||||
and expecting something to happen. We use [CasperJS](http://casperjs.org/) for frontend testing, which is basically a
|
||||
headless Webkit browser.
|
||||
|
||||
**NOTE**: The 1.1.0DEV version does *NOT* work at this time as the api changed. Use the stable 1.0.3 branch instead.
|
||||
|
||||
In order to be able to run the frontend tests, you need a running instance of icingaweb. You should make sure that you
|
||||
don't need this instance after running the tests, as they could change preferences or configuration
|
||||
|
||||
## Writing tests
|
||||
|
||||
|
||||
### Test bootstrap - icingawebtest.js module
|
||||
|
||||
The icingawebtest.js module is required for proper testing, as this module eases casperjs usage. After importing the
|
||||
module with:
|
||||
|
||||
var icingawebtest = require('./icingawebtest');
|
||||
|
||||
You only need two methods for testing:
|
||||
|
||||
* *getTestEnv()*: This method returns a modified casperjs test environment. The difference to then normal casperjs object
|
||||
is that all methods which take a URL are overloaded so you can add a relative URL if you want to (and
|
||||
normally you don't want to hardcode your test URLs)
|
||||
Example:
|
||||
|
||||
var casper = icingawebtest.getTestEnv();
|
||||
|
||||
* performLogin(): This calls the login page of your icingaweb instance and tries to login with the supplied credentials
|
||||
|
||||
icinga.performLogin();
|
||||
|
||||
|
||||
Login is performed with the credentials from the CASPERJS_USER/CASPERJS_PASS environment (this can be set with the
|
||||
./runtest --user %user% --pass %pass% arguments). The host, server and port are also represented as
|
||||
CASPERJS_HOST, CASPERJS_PORT and CASPERJS_PATH environment settings. The default in runtest resembles the version that
|
||||
works best in the vagrant development environment:
|
||||
|
||||
* The default user is 'jdoe'
|
||||
* The default password is 'password'
|
||||
* The host and port are localhost:80
|
||||
* The default path is icinga2-web
|
||||
|
||||
### Writing the test code
|
||||
|
||||
Most tests will require you to login with the supplied credentials, this can be performed with a simple call
|
||||
|
||||
icinga.performLogin();
|
||||
|
||||
You can then start the test by calling casper.thenOpen with the page you want to work
|
||||
|
||||
casper.thenOpen("/mysite", function() {
|
||||
// perform tests
|
||||
});
|
||||
|
||||
### Testing
|
||||
|
||||
Afterwards, everything is like a normal CasperJS test, so you can wrap your assertions in a casper.then method:
|
||||
|
||||
// assert a specific title
|
||||
casper.then(function() {
|
||||
this.test.assertTitle("Just an empty page");
|
||||
});
|
||||
|
||||
Note that asynchronous calls reuqire you to wait or provide a callback until the resource is loaded:
|
||||
|
||||
// waitForSelector calls callbackFn as soon as the selector returns a non-empty set
|
||||
casper.waitForSelector("div#icinga-main a", callbackFn);
|
||||
|
||||
At the end of your test, you have to provide
|
||||
|
||||
casper.run(function() {
|
||||
this.test.done();
|
||||
});
|
||||
|
||||
Otherwise the tests won't be executed.
|
|
@ -1,88 +0,0 @@
|
|||
# Writing JavaScipt tests
|
||||
|
||||
JavaScript tests are executed using [mocha](http://visionmedia.github.io/mocha/) as a test framework and
|
||||
[should.js](https://github.com/visionmedia/should.js/) as the assertion framework.
|
||||
|
||||
## Mocking require.js
|
||||
|
||||
As we use require.js for asynchronous dependency resolution in JavaScript, this can lead to problems in our node.js
|
||||
environment. In order to avoid requirejs calls to cause issues, it has been mocked in the testlib/asyncmock.js class
|
||||
and should be required in every testcase:
|
||||
|
||||
var rjsmock = require("requiremock.js");
|
||||
|
||||
rjsmock now makes dependency management comfortable and provides the following most important methods:
|
||||
|
||||
// remove all registered dependencies from the rjsmock cache
|
||||
rjsmock.purgeDependencies();
|
||||
|
||||
// register the following objects underneath the following requirejs paths:
|
||||
rjsmock.registerDependencies({
|
||||
'icinga/container' : {
|
||||
updateContainer : function() {},
|
||||
createPopupContainer: function() {}
|
||||
}
|
||||
});
|
||||
// in your js code a require(['icinga/container], function(container) {}) would now have the above mock
|
||||
// object in the container variable
|
||||
|
||||
requireNew("icinga/util/async.js"); // requires icinga/util/async.js file - and ignores the requirejs cache
|
||||
var async = rjsmock.getDefine(); // returns the last define, this way you can retrieve a specific javacript file
|
||||
|
||||
## Faking async responses
|
||||
|
||||
As we currently use the icinga/util/async.js class for all asynchronous requests, it's easy to fake responses. The asyncmock.js
|
||||
class provides functions for this. To use it in your test, you first have to require it:
|
||||
|
||||
var asyncMock = require("asyncmock.js");
|
||||
|
||||
You now can use asyncMock.setNextAsyncResult((async) asyncManager, (string) resultString, (bool) fails, (object) headers) to
|
||||
let the next request of the passed asyncManager object return resultString as the response, with the headers provided as the
|
||||
last parameter. If fails = true, the error callback of the request will be called.
|
||||
|
||||
|
||||
## Example test
|
||||
|
||||
The following example describes a complete test, (which tests whether the registerHeaderListener method in the async class works) :
|
||||
|
||||
var should = require("should"); // require should.js for assertions
|
||||
var rjsmock = require("requiremock.js"); // use the requiremock described above
|
||||
var asyncMock = require("asyncmock.js"); // Helper class to fake async requests
|
||||
|
||||
GLOBAL.document = $('body'); // needed when our test accesses window.document
|
||||
|
||||
|
||||
describe('The async module', function() { // start the test scenario
|
||||
it("Allows to react on specific headers", function(done) { // Start a test case - when done is called it is finished
|
||||
rjsmock.purgeDependencies(); // Remove any dependency previously declared
|
||||
rjsmock.registerDependencies({ // Mock icinga/container, as this is a dependency for the following include
|
||||
'icinga/container' : {
|
||||
updateContainer : function() {},
|
||||
createPopupContainer: function() {}
|
||||
}
|
||||
});
|
||||
|
||||
requireNew("icinga/util/async.js"); // This is the file we want to test, load it and all of it's dependencies
|
||||
var async = rjsmock.getDefine(); // Retrieve a reference to the loaded file
|
||||
|
||||
// Use asyncMock.setNextAsyncResult to let the next async request return 'result' without failing and set
|
||||
// the response headers 'X-Dont-Care' and 'X-Test-Header'
|
||||
asyncMock.setNextAsyncResult(async, "result", false, {
|
||||
'X-Dont-Care' : 'Ignore-me',
|
||||
'X-Test-Header' : 'Testme123'
|
||||
});
|
||||
|
||||
// register a listener for results with the X-Test-Header response
|
||||
async.registerHeaderListener("X-Test-Header", function(value, header) {
|
||||
// test for the correct header
|
||||
should.equal("Testme123", value);
|
||||
// call done to mark this test as succeeded
|
||||
done();
|
||||
},this);
|
||||
// run the faked request
|
||||
var test = async.createRequest();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
The path where you should put your PHPUnit tests should reflect the path in the sourcetree, with test/php/ prepended. So
|
||||
if you're testing a file library/Icinga/My/File.php the test file should be at test/php/library/Icinga/My/File.php. This
|
||||
also applies for modules, where the test folder is underneath modules/myModule/test/php
|
||||
also applies for modules, where the tests are underneath modules/myModule/test/php
|
||||
|
||||
## Example test skeleton
|
||||
|
||||
|
@ -12,13 +12,8 @@ Let's assume you're testing a class MyClass underneath the MyModule module and t
|
|||
modules/mymodule/library/MyModule/Helper/MyClass.php.
|
||||
|
||||
<?php
|
||||
// The namespace is the same namespace as the file to test has, but with 'Test' prepended
|
||||
namespace Test\Modules\MyModule\Helper;
|
||||
|
||||
// Require the file and maybe others. The start point is always the applications
|
||||
// testss/php/ folder where the runtest executable can be found
|
||||
|
||||
require_once '../../mymodule/library/MyModule/Helper/MyClass.php';
|
||||
// The namespace is the same namespace as the file to test has, but with 'Tests' prepended
|
||||
namespace Tests\Module\MyModule\Helper;
|
||||
|
||||
class MyClassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
@ -30,28 +25,33 @@ modules/mymodule/library/MyModule/Helper/MyClass.php.
|
|||
|
||||
## Testing Singletons
|
||||
|
||||
When test methods **modify static** class properties (which is the case when using singletons), add the PHPUnit
|
||||
When test methods **modify static** class properties (which is the case when using singletons), do not add the PHPUnit
|
||||
[`@backupStaticAttributes enabled`](http://phpunit.de/manual/3.7/en/appendixes.annotations.html#appendixes.annotations.backupStaticAttributes)
|
||||
annotation to their [DockBlock](http://www.phpdoc.org/docs/latest/for-users/phpdoc/basic-syntax.html#what-is-a-docblock)
|
||||
in order to backup and restore static attributes before and after the method execution respectively. For reference you
|
||||
should **document** that the test interacts with static attributes:
|
||||
annotation to their [DocBlock](http://www.phpdoc.org/docs/latest/for-users/phpdoc/basic-syntax.html#what-is-a-docblock)
|
||||
in order to backup and restore static attributes before and after the test execution respectively. Use the setUp()
|
||||
and tearDown() routines instead to accomplish this task.
|
||||
|
||||
<?php
|
||||
|
||||
namespace My\Test;
|
||||
|
||||
use \PHPUnit_Framework_TestCase;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use My\CheesecakeFactory;
|
||||
|
||||
class SingletonTest extends PHPUnit_Framework_TestCase
|
||||
class SingletonTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Interact with static attributes
|
||||
*
|
||||
* Utilizes singleton CheesecakeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->openingHours = CheesecakeFactory::getOpeningHours();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
CheesecakeFactory::setOpeningHours($this->openingHours);
|
||||
}
|
||||
|
||||
public function testThatInteractsWithStaticAttributes()
|
||||
{
|
||||
CheesecakeFactory::setOpeningHours(24);
|
||||
|
@ -59,79 +59,7 @@ should **document** that the test interacts with static attributes:
|
|||
}
|
||||
}
|
||||
|
||||
## Requirements and the dependency mess
|
||||
|
||||
### spl_autoload_register vs. require
|
||||
|
||||
When looking at our test classes, you'll notice that we don't use PHPs autoloader to automatically load dependency, but
|
||||
write 'require_once' by ourselfs. This has the following reasons:
|
||||
|
||||
- When writing tests, you to be aware of every dependency your testclass includes. With autoloading, it's not directly
|
||||
obvious which classes are included during runtime.
|
||||
- When mocking classes, you don't need to tell your autoloader to use this class instead of the one used in production
|
||||
- Tests can't be run isolated without an boostrap class initializing the autoloader
|
||||
|
||||
### How to avoid require_once massacres: LibraryLoader
|
||||
|
||||
The downside of this approach is obvious: Especially when writing compoment tests you end up writing a lot of 'require'
|
||||
classes. In the worst case, the PHP require_once method doesn't recognize a path to be already included and ends up
|
||||
with an 'Cannot redeclare class XY' issue.
|
||||
|
||||
To avoid this, you should implement a LibraryLoader class for your component that handles the require_once calls.
|
||||
For example, the status.dat component tests has a TestLoader class that includes all dependencies of the component:
|
||||
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
require_once('library/Icinga/LibraryLoader.php');
|
||||
|
||||
/**
|
||||
* Load all required libraries to use the statusdat
|
||||
* component in integration tests
|
||||
*
|
||||
**/
|
||||
class StatusdatTestLoader extends LibraryLoader
|
||||
{
|
||||
/**
|
||||
* @see LibraryLoader::requireLibrary
|
||||
*
|
||||
**/
|
||||
public static function requireLibrary()
|
||||
{
|
||||
// include Zend requirements
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Cache.php';
|
||||
require_once 'Zend/Log.php';
|
||||
|
||||
// retrieve the path to the icinga library
|
||||
$libPath = self::getLibraryPath();
|
||||
|
||||
// require library dependencies
|
||||
require_once($libPath."/Data/AbstractQuery.php");
|
||||
require_once($libPath."/Application/Logger.php");
|
||||
require_once($libPath."/Data/DatasourceInterface.php");
|
||||
|
||||
// shorthand for the folder where the statusdat component can be found
|
||||
$statusdat = realpath($libPath."/Protocol/Statusdat/");
|
||||
require_once($statusdat."/View/AccessorStrategy.php");
|
||||
// ... a few more requires ...
|
||||
require_once($statusdat."/Query/Group.php");
|
||||
}
|
||||
}
|
||||
|
||||
Now an component test (like tests/php/library/Icinga/Protocol/Statusdat/ReaderTest.php) can avoid the require calls and
|
||||
just use the requireLibrary method:
|
||||
|
||||
use Icinga\Protocol\Statusdat\Reader as Reader;
|
||||
|
||||
// Load library at once
|
||||
require_once("StatusdatTestLoader.php");
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
|
||||
**Note**: This should be used for component tests, where you want to test the combination of your classes. When testing
|
||||
a single execution unit, like a method, it's often better to explicitly write your dependencies.
|
||||
|
||||
If you compare the first approach with the last one you will notice that, even if we produced more code in the end, our
|
||||
test is more verbose in what it is doing. When someone is updating your test, he should easily see what tests are existing
|
||||
and what scenarios are missing.
|
||||
The reason to avoid using @backupStaticAttributes is the fact that if it is necessary to utilize a
|
||||
singleton in your *unit* tests you probably want to rethink what you are going to test and because
|
||||
some tests are using the mock framework [`Mockery`](https://github.com/padraic/mockery) which is
|
||||
using static class properties to implement its caching mechanics.
|
||||
|
|
|
@ -6,11 +6,10 @@ Tests for the application can be found underneath the test folder:
|
|||
|
||||
test/
|
||||
php/ PHPUnit tests for backend code
|
||||
js/ mocha tests for JavaScript frontend code unittests
|
||||
frontend/ Integration tests for the frontend using casperjs
|
||||
regression/ PHPUnit regression tests
|
||||
|
||||
The same structure applies for modules, which also contain a toplevel test folder and suitable subtests. When you fix
|
||||
a bug and write a regression test for it, put the test in the 'regression' and name it %DESCRIPTION%%TicketNumber% (myBug1234.js)
|
||||
a bug and write a regression test for it, put it in 'regression' and name it %DESCRIPTION%%TicketNumber% (myBug1234.php)
|
||||
|
||||
## Running tests
|
||||
|
||||
|
|
|
@ -18,11 +18,8 @@ This list summarizes what will be described in the next few chapters:
|
|||
- Your assertions should reflect one test scenario, i.e. don't write one test method that tests if something works **and**
|
||||
if it correctly detects errors after it works. Write one test to determine the behaviour with correct input and one that
|
||||
tests the behaviour with invalid input.
|
||||
- When writing unit-tests (like function level tests), try to keep your dependencies as low as possible (best indicator herefor
|
||||
is the number of require calls in your test). Mock external components and inject them into the class you want to test. If
|
||||
your testsubject is not able to use mocked dependencies, it's often a design flaw and should be considered as a bug
|
||||
(and be fixed)
|
||||
- When writing component tests with a lot of dependencies, wrap the require calls in a LibraryLoader subclass
|
||||
- Mock external components and inject them into the class you want to test. If your testsubject is not able to use mocked
|
||||
dependencies, it's often a design flaw and should be considered as a bug (and be fixed)
|
||||
|
||||
|
||||
## What should be tested
|
||||
|
@ -163,12 +160,6 @@ need much dependency handling. An example for a unittest would be to test the fo
|
|||
|
||||
A unit test for this user could, but should not look like this (we'll explain why):
|
||||
|
||||
require_once "../../library/Icinga/MyLibrary/UserManager.php";
|
||||
// needed by UserManager
|
||||
require_once "../../library/Icinga/Authentication/Manager.php"
|
||||
require_once "../../library/Icinga/Authentication/User.php"
|
||||
// .. imagine a few more require_once
|
||||
|
||||
use Icinga/MyLibrary/UserManager
|
||||
|
||||
class UserManagerTest extends \PHPUnit_Framework_TestCase
|
||||
|
@ -196,7 +187,7 @@ A unit test for this user could, but should not look like this (we'll explain wh
|
|||
$this->assertTrue($mgr->isCorrectPassword("hans", "validpasswor"));
|
||||
}
|
||||
|
||||
This test has obviously a few issues:
|
||||
This test has a few issues:
|
||||
|
||||
- First, it assert a precondition to apply : A database must exist with the users jdoe and jsmith and the credentials
|
||||
must match the ones provided in the test
|
||||
|
@ -238,7 +229,6 @@ It would of course be best to create an Interface like UserSource which the Auth
|
|||
we trust our Programmer to provide a suitable object. We now can eliminate all the AuthManager dependencies by mocking the
|
||||
AuthManager (lets dumb it down to just providing an array of users):
|
||||
|
||||
require_once "../../library/Icinga/MyLibrary/UserManager.php";
|
||||
use Icinga/MyLibrary/UserManager
|
||||
|
||||
class AuthManagerMock
|
||||
|
@ -286,7 +276,6 @@ AuthManager (lets dumb it down to just providing an array of users):
|
|||
Ok, we might have more code here than before, but our test is now less like prone to fail:
|
||||
|
||||
- Our test doesn't assume any preconditions to apply, like having a db server with correct users
|
||||
- The require call to the AuthManager is gone, so if there's a bug in the AuthManager implementation our test is not affected
|
||||
|
||||
|
||||
|
||||
|
@ -368,84 +357,3 @@ Also, the assertions should get an error message that will be printed on failure
|
|||
|
||||
Now if something fails, we now see what has been tested via the testmethod and what caused the test to fail in the
|
||||
assertion error message. You could also leave the comments and everybody knows what you are doing.
|
||||
|
||||
## Testing PHP
|
||||
|
||||
|
||||
## Requirements and the dependency mess
|
||||
|
||||
### spl_autoload_register vs. require
|
||||
|
||||
When looking at our test classes, you'll notice that we don't use PHPs autoloader to automatically load dependency, but
|
||||
write 'require_once' by ourselfs. This has the following reasons:
|
||||
|
||||
- When writing tests, you to be aware of every dependency your testclass includes. With autoloading, it's not directly
|
||||
obvious which classes are included during runtime.
|
||||
- When mocking classes, you don't need to tell your autoloader to use this class instead of the one used in production
|
||||
- Tests can't be run isolated without an boostrap class initializing the autoloader
|
||||
|
||||
### How to avoid require_once massacres: LibraryLoader
|
||||
|
||||
The downside of this approach is obvious: Especially when writing compoment tests you end up writing a lot of 'require'
|
||||
classes. In the worst case, the PHP require_once method doesn't recognize a path to be already included and ends up
|
||||
with an 'Cannot redeclare class XY' issue.
|
||||
|
||||
To avoid this, you should implement a LibraryLoader class for your component that handles the require_once calls.
|
||||
For example, the status.dat component tests has a TestLoader class that includes all dependencies of the component:
|
||||
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
require_once('library/Icinga/LibraryLoader.php');
|
||||
|
||||
/**
|
||||
* Load all required libraries to use the statusdat
|
||||
* component in integration tests
|
||||
*
|
||||
**/
|
||||
class StatusdatTestLoader extends LibraryLoader
|
||||
{
|
||||
/**
|
||||
* @see LibraryLoader::requireLibrary
|
||||
*
|
||||
**/
|
||||
public static function requireLibrary()
|
||||
{
|
||||
// include Zend requirements
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Cache.php';
|
||||
require_once 'Zend/Log.php';
|
||||
|
||||
// retrieve the path to the icinga library
|
||||
$libPath = self::getLibraryPath();
|
||||
|
||||
// require library dependencies
|
||||
require_once($libPath."/Data/AbstractQuery.php");
|
||||
require_once($libPath."/Application/Logger.php");
|
||||
require_once($libPath."/Data/DatasourceInterface.php");
|
||||
|
||||
// shorthand for the folder where the statusdat component can be found
|
||||
$statusdat = realpath($libPath."/Protocol/Statusdat/");
|
||||
require_once($statusdat."/View/AccessorStrategy.php");
|
||||
// ... a few more requires ...
|
||||
require_once($statusdat."/Query/Group.php");
|
||||
}
|
||||
}
|
||||
|
||||
Now an component test (like tests/php/library/Icinga/Protocol/Statusdat/ReaderTest.php) can avoid the require calls and
|
||||
just use the requireLibrary method:
|
||||
|
||||
use Icinga\Protocol\Statusdat\Reader as Reader;
|
||||
|
||||
// Load library at once
|
||||
require_once("StatusdatTestLoader.php");
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
|
||||
**Note**: This should be used for component tests, where you want to test the combination of your classes. When testing
|
||||
a single execution unit, like a method, it's often better to explicitly write your dependencies.
|
||||
|
||||
If you compare the first approach with the last one you will notice that, even if we produced more code in the end, our
|
||||
test is more verbose in what it is doing. When someone is updating your test, he should easily see what tests are existing
|
||||
and what scenarios are missing.
|
||||
|
||||
|
|
|
@ -50,29 +50,14 @@ password is queried when connecting from the local machine:
|
|||
Icinga has it's own base test which lets you easily require libraries, testing database and form functionality. The class resides in
|
||||
library/Icinga/Test. If you write a test, just subclass BaseTestCase.
|
||||
|
||||
### Default test header
|
||||
|
||||
Before writing a test you should include the base test first
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
Now you can simply include dependencies with predefined properties:
|
||||
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/AuthenticationForm.php';
|
||||
|
||||
BaseTestCase provides static variables for every directory in the project.
|
||||
|
||||
### Writing database tests
|
||||
|
||||
The base test uses the PHPUnit dataProvider annotation system to create Zend Database Adapters. Typically a
|
||||
The base test uses the PHPUnit dataProvider annotation system to create database connections. Typically a
|
||||
database test looks like this:
|
||||
|
||||
/**
|
||||
* @dataProvider mysqlDb
|
||||
* @param Zend_Db_Adapter_PDO_Abstract $mysqlDb
|
||||
* @param Icinga\Data\Db\Connection $mysqlDb
|
||||
*/
|
||||
public function testSomethingWithMySql($mysqlDb)
|
||||
{
|
||||
|
@ -106,58 +91,3 @@ BaseTestCase holds method to require form libraries and create form classes base
|
|||
|
||||
The second parameter of createForm() can be omitted. You can set initial post request data as
|
||||
an array if needed.
|
||||
|
||||
## Writing tests for controllers
|
||||
|
||||
When writing tests for controllers, you can subclass the MonitoringControllerTest class underneath monitoring/test/php/testlib:
|
||||
|
||||
class MyTestclass extends MonitoringControllerTest
|
||||
{
|
||||
// test stuff
|
||||
}
|
||||
|
||||
This class handles a lot of depenendency resolving and controller mocking. In order to test your action correctly and
|
||||
without side effects, the TestFixture class allows your to define and set up your faked monitoring results in the backend
|
||||
you want to test:
|
||||
|
||||
use Test\Monitoring\Testlib\Datasource\TestFixture;
|
||||
|
||||
class MyTestclass extends MonitoringControllerTest
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$fixture = new TestFixture();
|
||||
// adding a new critical, but acknowledged host
|
||||
$fixture->addHost("hostname", 1, ObjectFlags::ACKNOWLEDGED())
|
||||
|
||||
// add a comment to the host (this has to be done before adding services)
|
||||
->addComment("author", "comment text")
|
||||
|
||||
// assign to hostgroup
|
||||
->addToHostgroup("myHosts")
|
||||
|
||||
// and add three services to this host
|
||||
->addService("svc1", 0) // Service is ok
|
||||
->addService("svc2", 1, ObjectFlags::PASSIVE) // service is warning and passive
|
||||
->addService("svc3", 2, null, array("notes_url" => "test.html")) // critical with notes url
|
||||
->addComment("author", "what a nice service comment") // add a comment to the service
|
||||
->addToServicegroup("alwaysdown"); // add svc3 to servicegroup
|
||||
|
||||
// Create the datasource from this fixture, here in MySQL
|
||||
$this->setupFixture($fixture, "mysql");
|
||||
|
||||
// ... do the actual testing (discussed now)
|
||||
}
|
||||
}
|
||||
|
||||
After the call to setupFixture() your backend should be ready to be tested. Setting up the controller manually would
|
||||
force you to go through the whole bootstrap. To avoid this the MonitoringControllerTest class provides a 'requireController'
|
||||
method which returns the Controller for you with an already set up backend using your previously defined testdata:
|
||||
|
||||
$controller = $this->requireController('MyController', 'mysql');
|
||||
// controller is now the Zend controller instance, perform an action
|
||||
$controller->myAction();
|
||||
$result = $controller->view->hosts->fetchAll();
|
||||
|
||||
This example assumes that the controller populates the 'host' variable in the view, so now you can assert the state of
|
||||
the result according to your test plan.
|
|
@ -59,12 +59,14 @@ class Icinga
|
|||
/**
|
||||
* Setter for an application environment
|
||||
*
|
||||
* @param ApplicationBootstrap $app
|
||||
* @param ApplicationBootstrap $app
|
||||
* @param bool $overwrite
|
||||
*
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public static function setApp(ApplicationBootstrap $app)
|
||||
public static function setApp(ApplicationBootstrap $app, $overwrite = false)
|
||||
{
|
||||
if (self::$app !== null) {
|
||||
if (self::$app !== null && !$overwrite) {
|
||||
throw new ProgrammingError('Cannot start Icinga twice');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +1,5 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Application;
|
||||
|
@ -40,6 +15,7 @@ class Loader
|
|||
|
||||
/**
|
||||
* List of namespaces
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $namespaces = array();
|
||||
|
@ -54,14 +30,16 @@ class Loader
|
|||
|
||||
/**
|
||||
* Register new namespace for directory
|
||||
* @param string $namespace
|
||||
* @param string $directory
|
||||
* @throws \Icinga\Exception\ProgrammingError
|
||||
*
|
||||
* @param string $namespace
|
||||
* @param string $directory
|
||||
*
|
||||
* @throws ProgrammingError
|
||||
*/
|
||||
public function registerNamespace($namespace, $directory)
|
||||
{
|
||||
if (!is_dir($directory)) {
|
||||
throw new ProgrammingError('Directory does not exist: '. $directory);
|
||||
throw new ProgrammingError('Directory does not exist: ' . $directory);
|
||||
}
|
||||
|
||||
$this->namespaces[$namespace] = $directory;
|
||||
|
@ -69,8 +47,10 @@ class Loader
|
|||
|
||||
/**
|
||||
* Test if a namespace exists
|
||||
* @param string $namespace
|
||||
* @return bool
|
||||
*
|
||||
* @param string $namespace
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasNamespace($namespace)
|
||||
{
|
||||
|
@ -80,19 +60,19 @@ class Loader
|
|||
/**
|
||||
* Class loader
|
||||
*
|
||||
* Ignores all but classes in the Icinga namespace.
|
||||
* Ignores all but classes in registered namespaces.
|
||||
*
|
||||
* @param string $class
|
||||
* @return boolean
|
||||
* @param string $class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function loadClass($class)
|
||||
{
|
||||
$namespace = $this->getNamespaceForClass($class);
|
||||
|
||||
if ($namespace) {
|
||||
$file = $this->namespaces[$namespace]. preg_replace('/^'. preg_quote($namespace). '/', '', $class);
|
||||
|
||||
$file = str_replace(self::NAMESPACE_SEPARATOR, '/', $file). '.php';
|
||||
$file = $this->namespaces[$namespace] . preg_replace('/^' . preg_quote($namespace) . '/', '', $class);
|
||||
$file = str_replace(self::NAMESPACE_SEPARATOR, '/', $file) . '.php';
|
||||
|
||||
if (@file_exists($file)) {
|
||||
require_once $file;
|
||||
|
@ -108,16 +88,19 @@ class Loader
|
|||
*
|
||||
* Return is the longest match in the array found
|
||||
*
|
||||
* @param string $className
|
||||
* @return bool|string
|
||||
* @param string $className
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getNamespaceForClass($className)
|
||||
{
|
||||
$testNamespace = '';
|
||||
$testLength = 0;
|
||||
|
||||
foreach ($this->namespaces as $namespace => $directory) {
|
||||
$stub = preg_replace('/^'. preg_quote($namespace). '/', '', $className);
|
||||
foreach (array_keys($this->namespaces) as $namespace) {
|
||||
$stub = preg_replace(
|
||||
'/^' . preg_quote($namespace) . '(' . preg_quote(self::NAMESPACE_SEPARATOR) . '|$)/', '', $className
|
||||
);
|
||||
$length = strlen($className) - strlen($stub);
|
||||
if ($length > $testLength) {
|
||||
$testLength = $length;
|
||||
|
|
|
@ -1,30 +1,5 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace {
|
||||
|
@ -46,23 +21,18 @@ namespace {
|
|||
|
||||
namespace Icinga\Test {
|
||||
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require_once 'Zend/Db/Adapter/Pdo/Abstract.php';
|
||||
require_once 'DbTest.php';
|
||||
require_once 'FormTest.php';
|
||||
// @codingStandardsIgnoreStart
|
||||
use \Exception;
|
||||
use \DateTimeZone;
|
||||
use \RuntimeException;
|
||||
use Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Zend_Config;
|
||||
use Zend_Db_Adapter_Pdo_Abstract;
|
||||
use Zend_Db_Adapter_Pdo_Mysql;
|
||||
use Zend_Db_Adapter_Pdo_Pgsql;
|
||||
use Zend_Db_Adapter_Pdo_Oci;
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Icinga\Application\Icinga;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Data\Db\Connection;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Web\Form;
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
/**
|
||||
* Class BaseTestCase
|
||||
|
@ -138,17 +108,12 @@ namespace Icinga\Test {
|
|||
);
|
||||
|
||||
/**
|
||||
* Constructs a test case with the given name.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
* @param string $dataName
|
||||
* @see PHPUnit_Framework_TestCase::__construct
|
||||
* Setup the default timezone and pass it to DateTimeFactory::setConfig
|
||||
*/
|
||||
public function __construct($name = null, array $data = array(), $dataName = '')
|
||||
public static function setupTimezone()
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
date_default_timezone_set('UTC');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,12 +123,6 @@ namespace Icinga\Test {
|
|||
*/
|
||||
public static function setupDirectories()
|
||||
{
|
||||
static $initialized = false;
|
||||
|
||||
if ($initialized === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$baseDir = realpath(__DIR__ . '/../../../');
|
||||
|
||||
if ($baseDir === false) {
|
||||
|
@ -176,8 +135,34 @@ namespace Icinga\Test {
|
|||
self::$testDir = $baseDir . '/test/php';
|
||||
self::$shareDir = $baseDir . '/share/icinga2-web';
|
||||
self::$moduleDir = $baseDir . '/modules';
|
||||
}
|
||||
|
||||
$initialized = true;
|
||||
/**
|
||||
* Setup MVC bootstrapping and ensure that the Icinga-Mock gets reinitialized
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->setupIcingaMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup mock object for the application's bootstrap
|
||||
*/
|
||||
protected function setupIcingaMock()
|
||||
{
|
||||
$bootstrapMock = Mockery::mock('Icinga\Application\ApplicationBootstrap')->shouldDeferMissing();
|
||||
$bootstrapMock->shouldReceive('getFrontController->getRequest')->andReturnUsing(
|
||||
function () {
|
||||
return Mockery::mock('Request')
|
||||
->shouldReceive('getPathInfo')->andReturn('')
|
||||
->shouldReceive('getBaseUrl')->andReturn('/')
|
||||
->shouldReceive('getQuery')->andReturn(array())
|
||||
->getMock();
|
||||
}
|
||||
)->shouldReceive('getApplicationDir')->andReturn(self::$appDir);
|
||||
|
||||
Icinga::setApp($bootstrapMock, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,7 +173,7 @@ namespace Icinga\Test {
|
|||
* @return Zend_Config
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function createDbConfigFor($name)
|
||||
protected function createDbConfigFor($name)
|
||||
{
|
||||
if (array_key_exists($name, self::$dbConfiguration)) {
|
||||
return new Zend_Config(self::$dbConfiguration[$name]);
|
||||
|
@ -198,67 +183,64 @@ namespace Icinga\Test {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an array of Zend Database Adapter
|
||||
* Creates an array of Icinga\Data\Db\Connection
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function createDbAdapterFor($name)
|
||||
protected function createDbConnectionFor($name)
|
||||
{
|
||||
$this->requireDbLibraries();
|
||||
|
||||
try {
|
||||
$adapter = ResourceFactory::createResource($this->createDbConfigFor($name))->getConnection();
|
||||
$conn = ResourceFactory::createResource($this->createDbConfigFor($name));
|
||||
} catch (Exception $e) {
|
||||
$adapter = $e->getMessage();
|
||||
$conn = $e->getMessage();
|
||||
}
|
||||
|
||||
return array(
|
||||
array($adapter)
|
||||
array($conn)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPUnit provider for mysql
|
||||
*
|
||||
* @return Zend_Db_Adapter_Pdo_Mysql
|
||||
* @return Connection
|
||||
*/
|
||||
public function mysqlDb()
|
||||
{
|
||||
return $this->createDbAdapterFor('mysql');
|
||||
return $this->createDbConnectionFor('mysql');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPUnit provider for pgsql
|
||||
*
|
||||
* @return Zend_Db_Adapter_Pdo_Pgsql
|
||||
* @return Connection
|
||||
*/
|
||||
public function pgsqlDb()
|
||||
{
|
||||
return $this->createDbAdapterFor('pgsql');
|
||||
return $this->createDbConnectionFor('pgsql');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPUnit provider for oracle
|
||||
*
|
||||
* @return Zend_Db_Adapter_Pdo_Oci
|
||||
* @return Connection
|
||||
*/
|
||||
public function oracleDb()
|
||||
{
|
||||
return $this->createDbAdapterFor('oracle');
|
||||
return $this->createDbConnectionFor('oracle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes sql file on PDO object
|
||||
* Executes sql file by using the database connection
|
||||
*
|
||||
* @param Zend_Db_Adapter_Pdo_Abstract $resource
|
||||
* @param string $filename
|
||||
* @param Connection $resource
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean Operational success flag
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function loadSql(Zend_Db_Adapter_Pdo_Abstract $resource, $filename)
|
||||
public function loadSql(Connection $resource, $filename)
|
||||
{
|
||||
if (!is_file($filename)) {
|
||||
throw new RuntimeException(
|
||||
|
@ -274,17 +256,17 @@ namespace Icinga\Test {
|
|||
);
|
||||
}
|
||||
|
||||
$resource->exec($sqlData);
|
||||
$resource->getConnection()->exec($sqlData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup provider for testcase
|
||||
*
|
||||
* @param string|Zend_Db_Adapter_PDO_Abstract|null $resource
|
||||
* @param string|Connection|null $resource
|
||||
*/
|
||||
public function setupDbProvider($resource)
|
||||
{
|
||||
if (!$resource instanceof Zend_Db_Adapter_Pdo_Abstract) {
|
||||
if (!$resource instanceof Connection) {
|
||||
if (is_string($resource)) {
|
||||
$this->markTestSkipped('Could not initialize provider: ' . $resource);
|
||||
} else {
|
||||
|
@ -293,15 +275,17 @@ namespace Icinga\Test {
|
|||
return;
|
||||
}
|
||||
|
||||
$adapter = $resource->getConnection();
|
||||
|
||||
try {
|
||||
$resource->getConnection();
|
||||
$adapter->getConnection();
|
||||
} catch (Exception $e) {
|
||||
$this->markTestSkipped('Could not connect to provider: '. $e->getMessage());
|
||||
}
|
||||
|
||||
$tables = $resource->listTables();
|
||||
$tables = $adapter->listTables();
|
||||
foreach ($tables as $table) {
|
||||
$resource->exec('DROP TABLE ' . $table . ';');
|
||||
$adapter->exec('DROP TABLE ' . $table . ';');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,59 +323,8 @@ namespace Icinga\Test {
|
|||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all libraries to instantiate forms
|
||||
*/
|
||||
public static function requireFormLibraries()
|
||||
{
|
||||
require_once 'Zend/Form/Decorator/Abstract.php';
|
||||
require_once 'Zend/Validate/Abstract.php';
|
||||
require_once 'Zend/Form/Element/Xhtml.php';
|
||||
require_once 'Zend/Form/Element/Text.php';
|
||||
require_once 'Zend/Form/Element/Submit.php';
|
||||
require_once 'Zend/Form/Element/Checkbox.php';
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/View.php';
|
||||
|
||||
require_once self::$libDir . '/Web/Form/InvalidCSRFTokenException.php';
|
||||
|
||||
require_once self::$libDir . '/Web/Form/Element/DateTimePicker.php';
|
||||
require_once self::$libDir . '/Web/Form/Element/Note.php';
|
||||
require_once self::$libDir . '/Web/Form/Element/Number.php';
|
||||
|
||||
require_once self::$libDir . '/Web/Form/Decorator/ConditionalHidden.php';
|
||||
require_once self::$libDir . '/Web/Form/Decorator/HelpText.php';
|
||||
require_once self::$libDir . '/Web/Form/Decorator/BootstrapForm.php';
|
||||
|
||||
require_once self::$libDir . '/Web/Form/Validator/DateFormatValidator.php';
|
||||
require_once self::$libDir . '/Web/Form/Validator/TimeFormatValidator.php';
|
||||
require_once self::$libDir . '/Web/Form/Validator/WritablePathValidator.php';
|
||||
|
||||
require_once self::$libDir . '/Web/Form.php';
|
||||
|
||||
require_once self::$libDir . '/User/Preferences.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all classes for database adapter creation
|
||||
*/
|
||||
public static function requireDbLibraries()
|
||||
{
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Db.php';
|
||||
require_once 'Zend/Log.php';
|
||||
|
||||
require_once self::$libDir . '/Exception/ConfigurationError.php';
|
||||
require_once self::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once self::$libDir . '/Data/DatasourceInterface.php';
|
||||
require_once self::$libDir . '/Data/ResourceFactory.php';
|
||||
require_once self::$libDir . '/Data/Db/Connection.php';
|
||||
require_once self::$libDir . '/Application/Logger.php';
|
||||
}
|
||||
}
|
||||
|
||||
BaseTestCase::setupTimezone();
|
||||
BaseTestCase::setupDirectories();
|
||||
BaseTestCase::requireFormLibraries();
|
||||
BaseTestcase::requireDbLibraries();
|
||||
}
|
||||
|
|
|
@ -29,48 +29,45 @@
|
|||
|
||||
namespace Icinga\Test;
|
||||
|
||||
use \Zend_Db_Adapter_Pdo_Abstract;
|
||||
use \Zend_Db_Adapter_Pdo_Mysql;
|
||||
use \Zend_Db_Adapter_Pdo_Pgsql;
|
||||
use \Zend_Db_Adapter_Pdo_Oci;
|
||||
use Icinga\Data\Db\Connection;
|
||||
|
||||
interface DbTest
|
||||
{
|
||||
/**
|
||||
* PHPUnit provider for mysql
|
||||
*
|
||||
* @return Zend_Db_Adapter_Pdo_Mysql
|
||||
* @return Connection
|
||||
*/
|
||||
public function mysqlDb();
|
||||
|
||||
/**
|
||||
* PHPUnit provider for pgsql
|
||||
*
|
||||
* @return Zend_Db_Adapter_Pdo_Pgsql
|
||||
* @return Connection
|
||||
*/
|
||||
public function pgsqlDb();
|
||||
|
||||
/**
|
||||
* PHPUnit provider for oracle
|
||||
*
|
||||
* @return Zend_Db_Adapter_Pdo_Oci
|
||||
* @return Connection
|
||||
*/
|
||||
public function oracleDb();
|
||||
|
||||
/**
|
||||
* Executes sql file on PDO object
|
||||
*
|
||||
* @param Zend_Db_Adapter_PDO_Abstract $resource
|
||||
* @param string $filename
|
||||
* @param Connection $resource
|
||||
* @param string $filename
|
||||
*
|
||||
* @return boolean Operational success flag
|
||||
*/
|
||||
public function loadSql(Zend_Db_Adapter_PDO_Abstract $resource, $filename);
|
||||
public function loadSql(Connection $resource, $filename);
|
||||
|
||||
/**
|
||||
* Setup provider for testcase
|
||||
*
|
||||
* @param string|Zend_Db_Adapter_PDO_Abstract|null $resource
|
||||
* @param string|Connection|null $resource
|
||||
*/
|
||||
public function setupDbProvider($resource);
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ class SessionNamespace implements IteratorAggregate
|
|||
*/
|
||||
public function __unset($key)
|
||||
{
|
||||
$this->removed[] = $key;
|
||||
unset($this->values[$key]);
|
||||
$this->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,6 +160,17 @@ class SessionNamespace implements IteratorAggregate
|
|||
return isset($this->values[$key]) ? $this->values[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the given value from the session
|
||||
*
|
||||
* @param string $key The value's name
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
$this->removed[] = $key;
|
||||
unset($this->values[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for all session values
|
||||
*
|
||||
|
@ -180,7 +190,7 @@ class SessionNamespace implements IteratorAggregate
|
|||
public function setAll(array $values, $overwrite = false)
|
||||
{
|
||||
foreach ($values as $key => $value) {
|
||||
if ($this->get($key) !== $value && !$overwrite) {
|
||||
if ($this->get($key, $value) !== $value && !$overwrite) {
|
||||
continue;
|
||||
}
|
||||
$this->set($key, $value);
|
||||
|
|
|
@ -43,14 +43,6 @@ use Icinga\Application\Icinga;
|
|||
*/
|
||||
class Url
|
||||
{
|
||||
/**
|
||||
* Rather dirty hack as the ApplicationBootstrap isn't an interface right now and can't be mocked
|
||||
* overwrite this to use a specific request for all Urls (so only in tests)
|
||||
*
|
||||
* @var null
|
||||
*/
|
||||
public static $overwrittenRequest = null;
|
||||
|
||||
/**
|
||||
* An array of all parameters stored in this Url
|
||||
*
|
||||
|
@ -123,9 +115,6 @@ class Url
|
|||
*/
|
||||
private static function getRequest()
|
||||
{
|
||||
if (self::$overwrittenRequest) {
|
||||
return self::$overwrittenRequest;
|
||||
}
|
||||
return Icinga::app()->getFrontController()->getRequest();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
# Testing controllers with different backends
|
||||
|
||||
Icingaweb's monitoring controllers support a variety of different backends (IDO, Statusdat, Livestatus) and make it
|
||||
therefore hard to test for every backend. In order to make life a little bit easier, Test-Fixtures allow you to setup
|
||||
a backend with specific monitoring data and test it afterwards by running the controller's action.
|
||||
|
||||
## Example
|
||||
|
||||
It's best to subclass MonitoringControllerTest (found in modules/monitoring/test/testlib), as this handles depency resoultion
|
||||
and setup for you:
|
||||
|
||||
|
||||
// assume our test is underneath the test/application/controllers folder in the monitoring module
|
||||
require_once(dirname(__FILE__).'/../../testlib/MonitoringControllerTest.php');
|
||||
|
||||
use Test\Monitoring\Testlib\MonitoringControllerTest;
|
||||
use Test\Monitoring\Testlib\Datasource\TestFixture;
|
||||
use Test\Monitoring\Testlib\Datasource\ObjectFlags;
|
||||
|
||||
class MyControllerTest extends MonitoringControllerTest
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
// Create a test fixture
|
||||
$fixture = new TestFixture()
|
||||
$fixture->addHost('host', 0) // Add a host with state OK
|
||||
->addToHostgroup('myHosts') // Add host to hostgroup
|
||||
->addService('svc1', 1) // Add a warning service 'svc1' underneath host
|
||||
->addToServiceGroup('svc_warning') // add this service to a servicegroup svc_warning
|
||||
->addService('svc2', 2, ObjectFlags::ACKNOWLEDGED()) // Add a critical, but acknowledged service to this host
|
||||
->addService(
|
||||
'svc3',
|
||||
1,
|
||||
new ObjectFlags(),
|
||||
array("customvariables" =>
|
||||
array("customer" => "myCustomer")
|
||||
)
|
||||
); // add a warning service with a customvariable
|
||||
|
||||
$this->setupFixture($fixture, "mysql"); // setup the fixture for MySQL, so the backend is populated with the data set above
|
||||
// backends can be mysql, pgsql, statusdat (and in the future livestatus)
|
||||
$controller = $this->requireController('MyController', 'mysql'); // request a controller with the given backend injected
|
||||
$controller->myAction(); // controller is now the Zend controller instance, perform an action
|
||||
$result = $controller->view->hosts->fetchAll(); // get the result of the query
|
||||
// and assert stuff
|
||||
$this->assertEquals(1, count($result), "Asserting one host being retrieved in the controller");
|
||||
}
|
||||
}
|
||||
|
||||
## The Test-fixture API
|
||||
|
||||
In order to populate your backend with specific monitoring objects, you have to create a TestFixture class. This class
|
||||
allows you to setup the monitoring objects in a backend independent way using a few methods:
|
||||
|
||||
### TestFixture::addHost($name, $state, [ObjectFlags $flags], [array $properties])
|
||||
|
||||
The addHost method adds a host with the name $name and the status $state (0-2) to your testfixture. When no ObjectFlags
|
||||
object is provided, the default flags are used (not flapping, notifications enabled, active and passive enabled, not
|
||||
acknowledged, not in downtime and not pending). The $properties array can contain additional settings like 'address',
|
||||
an 'customvariables' array, 'notes_url', 'action_url' or 'icon_image'.
|
||||
|
||||
Subsequent addToHostgroup and addService calls will affect this host (so the service will be added to this host)
|
||||
|
||||
### TestFixture::addService($name, $state, [ObjectFlags $flags], [array $properties])
|
||||
|
||||
The addHost method adds a service with the name $name and the status $state (0-3) to your testfixture. When no ObjectFlags
|
||||
object is provided, the default flags are used (not flapping, notifications enabled, active and passive enabled, not
|
||||
acknowledged, not in downtime and not pending). The $properties array can contain additional settings like an
|
||||
'customvariables' array, 'notes_url', 'action_url' or 'icon_image'.
|
||||
|
||||
Subsequent addToServicegroup calls will affect this service.
|
||||
|
||||
|
||||
### ObjectFlags
|
||||
|
||||
The Objectflags object encapsulates the following monitoring states with the following default values:
|
||||
|
||||
public $flapping = 0; // Whether this host is flapping
|
||||
public $notifications = 1; // Whether notifications are enabled
|
||||
public $active_checks = 1; // Whether actice checks are enabled
|
||||
public $passive_checks = 1; // Whether passive checks are enabled
|
||||
public $acknowledged = 0; // Whether this object has been acknowledged
|
||||
public $in_downtime = 0; // Whether this object is in a scheduled downtime
|
||||
public $is_pending = 0; // Whether this object is currently pending
|
||||
public $time = time(); // The last check and statechange time
|
||||
|
||||
ObjectFlags can either be created using new ObjectFlags([$ageInSeconds]) and directly modify the attributes or by
|
||||
calling one of the following factory methods:
|
||||
|
||||
|
||||
ObjectFlags::FLAPPING()
|
||||
ObjectFlags::PENDING()
|
||||
ObjectFlags::DISABLE_NOTIFICATIONS()
|
||||
ObjectFlags::PASSIVE_ONLY()
|
||||
ObjectFlags::ACTIVE_ONLY()
|
||||
ObjectFlags::DISABLED() {
|
||||
ObjectFlags::ACKNOWLEDGED()
|
||||
ObjectFlags::IN_DOWNTIME()
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Application\Controllers\ListController;
|
||||
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/test/php/testlib/MonitoringControllerTest.php'));
|
||||
require_once(realpath(BaseTestCase::$libDir . '/Data/Db/TreeToSqlParser.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/DataView.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/HostStatus.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/Notification.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/Downtime.php'));
|
||||
|
||||
use Test\Monitoring\Testlib\MonitoringControllerTest;
|
||||
use Test\Monitoring\Testlib\Datasource\TestFixture;
|
||||
use Test\Monitoring\Testlib\Datasource\ObjectFlags;
|
||||
|
||||
class ListControllerHostMySQLTest extends MonitoringControllerTest
|
||||
{
|
||||
|
||||
public function testHostListMySQL()
|
||||
{
|
||||
$this->executeHostListTestFor("mysql");
|
||||
}
|
||||
|
||||
public function testHostListPgSQL()
|
||||
{
|
||||
$this->executeHostListTestFor("pgsql");
|
||||
}
|
||||
|
||||
public function testHostListStatus()
|
||||
{
|
||||
$this->executeHostListTestFor("statusdat");
|
||||
}
|
||||
|
||||
public function executeHostListTestFor($backend)
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$checkTime = (string)(time()-2000);
|
||||
$fixture = new TestFixture();
|
||||
$firstHostFlags = ObjectFlags::PASSIVE_ONLY();
|
||||
$firstHostFlags->acknowledged = 1;
|
||||
$firstHostFlags->in_downtime = 1;
|
||||
$firstHostFlags->has_been_checked = 1;
|
||||
$firstHostFlags->notifications = 0;
|
||||
$firstHostFlags->flapping = 1;
|
||||
$firstHostFlags->time = $checkTime;
|
||||
|
||||
$fixture->addHost('host1', 1, $firstHostFlags, array(
|
||||
"address" => "10.92.1.5",
|
||||
"has_been_checked" => 1,
|
||||
"icon_image" => "myIcon.png",
|
||||
"notes_url" => "note1.html",
|
||||
"action_url" => "action.html"))->
|
||||
addToHostgroup('router')->
|
||||
addComment('author', 'host comment text')->
|
||||
addService('svc1', 2)->
|
||||
addService('svc2', 2)->
|
||||
addService('svc3', 2, ObjectFlags::ACKNOWLEDGED())->
|
||||
addService('svc4', 0);
|
||||
$fixture->addHost('host2', 1)->
|
||||
addService('svc1', 2);
|
||||
$fixture->addHost('host3', 0)->
|
||||
addService('svc1', 0);
|
||||
$fixture->addHost('host4', 0)->
|
||||
addService('svc1', 0);
|
||||
$fixture->addHost('host5', 2, ObjectFlags::ACKNOWLEDGED())->
|
||||
addService('svc1', 3)->addComment('author','svc comment');
|
||||
|
||||
try {
|
||||
$this->setupFixture($fixture, $backend);
|
||||
} catch (\PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
$this->markTestSkipped('Could not setup fixture for backends '.$backend.' :'.$e->getMessage());
|
||||
return null;
|
||||
}
|
||||
$controller = $this->requireController('ListController', $backend);
|
||||
$controller->hostsAction();
|
||||
$result = $controller->view->hosts;
|
||||
|
||||
$this->assertEquals(5, $result->getTotalItemCount(), 'Testing correct result count for '.$backend);
|
||||
|
||||
$result = $result->getAdapter()->getItems(0,6);
|
||||
for($i=1;$i<=5;$i++) {
|
||||
$this->assertEquals('host'.$i, $result[$i-1]->host_name, "Asserting correct host names for backend ".$backend);
|
||||
}
|
||||
|
||||
$hostToTest = $result[0];
|
||||
$persistedLastCheck = explode("+", $hostToTest->host_last_check);
|
||||
$persistedLastCheck = $persistedLastCheck[0];
|
||||
$this->assertEquals("10.92.1.5", $hostToTest->host_address, "Testing for correct host address field (backend ".$backend.")");
|
||||
// commented out due to failing tests when delay is too long
|
||||
// $this->assertEquals(date("Y-m-d H:i:s", intval($checkTime)), $persistedLastCheck, "Testing for correct last check time format (backend ".$backend.")");
|
||||
//$this->assertEquals($checkTime, $hostToTest->host_last_state_change, "Testing for correct last state change (backend ".$backend.")");
|
||||
$this->assertEquals("Plugin output for host host1", $hostToTest->host_output, "Testing correct output for host (backend ".$backend.")");
|
||||
$this->assertEquals("Long plugin output for host host1", $hostToTest->host_long_output, "Testing correct long output for host (backend ".$backend.")");
|
||||
$this->assertEquals(0, $hostToTest->host_notifications_enabled, "Testing for disabled notifications (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_acknowledged, "Testing for host being acknowledged (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_in_downtime, "Testing for host being in downtime (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_is_flapping, "Testing for host being flapping (backend ".$backend.')');
|
||||
$this->assertEquals(1, $hostToTest->host_last_comment, 'Testing correct comment count for first host (backend '.$backend.')');
|
||||
$this->assertEquals(0, $hostToTest->host_state_type, 'Testing for soft state');
|
||||
$this->assertEquals(1, $hostToTest->host_handled, 'Testing for handled host (backend '.$backend.')');
|
||||
$this->assertEquals("myIcon.png", $hostToTest->host_icon_image, 'Testing for icon image (backend '.$backend.')');
|
||||
$this->assertEquals("note1.html", $hostToTest->host_notes_url, 'Testing for notes url (backend '.$backend.')');
|
||||
$this->assertEquals("action.html", $hostToTest->host_action_url, 'Testing for action url (backend '.$backend.')');
|
||||
$this->assertEquals(2, $hostToTest->host_unhandled_service_count, 'Testing correct open problems count (backend '.$backend.')');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Application\Controllers\ListController;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/test/php/testlib/MonitoringControllerTest.php'));
|
||||
require_once(realpath(BaseTestCase::$libDir . '/Data/Db/TreeToSqlParser.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/DataView.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/ServiceStatus.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/Notification.php'));
|
||||
require_once(realpath(BaseTestCase::$moduleDir . '/monitoring/library/Monitoring/DataView/Downtime.php'));
|
||||
|
||||
use Test\Monitoring\Testlib\MonitoringControllerTest;
|
||||
use Test\Monitoring\Testlib\Datasource\TestFixture;
|
||||
use Test\Monitoring\Testlib\Datasource\ObjectFlags;
|
||||
|
||||
class ListControllerServiceMySQLTest extends MonitoringControllerTest
|
||||
{
|
||||
|
||||
public function testServiceListMySQL()
|
||||
{
|
||||
$this->executeServiceListTestFor("mysql");
|
||||
}
|
||||
|
||||
public function testServiceListPgSQL()
|
||||
{
|
||||
$this->executeServiceListTestFor("pgsql");
|
||||
}
|
||||
|
||||
// public function testServiceListStatusdat()
|
||||
// {
|
||||
// $this->executeServiceListTestFor("statusdat");
|
||||
// }
|
||||
|
||||
public function executeServiceListTestFor($backend)
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
$checkTime = time()-2000;
|
||||
$fixture = new TestFixture();
|
||||
$fixture->addHost('host1', 0)->
|
||||
addService("svc1", 0, new ObjectFlags(2000), array(
|
||||
"notes_url" => "notes.url",
|
||||
"action_url" => "action.url",
|
||||
"icon_image" => "svcIcon.png"
|
||||
))->
|
||||
addService("svcDown", 2) -> addComment("author", "Comment text")->
|
||||
addService("svcFlapping", 1, ObjectFlags::FLAPPING())->addToServicegroup("Warning")->
|
||||
addService("svcNotifDisabled", 2, ObjectFlags::DISABLE_NOTIFICATIONS())->
|
||||
addService("svcPending", 0, ObjectFlags::PENDING());
|
||||
$fixture->addHost('host2', 1)->
|
||||
addService("svcPassive", 1, ObjectFlags::PASSIVE_ONLY())->addToServicegroup("Warning")->
|
||||
addService("svcDisabled", 1, ObjectFlags::DISABLED())->addToServicegroup("Warning")->
|
||||
addService("svcDowntime", 2, ObjectFlags::IN_DOWNTIME())->
|
||||
addService("svcAcknowledged", 1, ObjectFlags::ACKNOWLEDGED())->addToServicegroup("Warning");
|
||||
try {
|
||||
$this->setupFixture($fixture, $backend);
|
||||
} catch (\PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
$this->markTestSkipped('Could not setup fixture for backends '.$backend.' :'.$e->getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
$controller = $this->requireController('ListController', $backend);
|
||||
$controller->servicesAction();
|
||||
|
||||
$result = $controller->view->services;
|
||||
|
||||
$this->assertEquals(9, $result->getTotalItemCount(), "Testing for correct service count");
|
||||
$result = $result->getAdapter()->getItems(0,1);
|
||||
$this->assertEquals("notes.url", $result[0]->service_notes_url, "Testing for correct notes_url");
|
||||
$this->assertEquals("action.url", $result[0]->service_action_url, "Testing for correct action_url");
|
||||
$this->assertEquals(0, $result[0]->service_state, "Testing for correct Service state");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +1,15 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/AcknowledgeForm.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
|
||||
|
||||
use \DateTimeZone;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
|
||||
class AcknowledgeFormTest extends BaseTestCase
|
||||
{
|
||||
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\AcknowledgeForm';
|
||||
|
||||
/**
|
||||
* Set DateTimeFactory's time zone to UTC
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
public function testFormValid()
|
||||
{
|
||||
$form = $this->createForm(
|
||||
|
|
|
@ -1,41 +1,11 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommentForm.php';
|
||||
|
||||
class CommentFormTest extends BaseTestCase
|
||||
{
|
||||
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\CommentForm';
|
||||
|
|
|
@ -1,41 +1,11 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CustomNotificationForm.php';
|
||||
|
||||
class CustomNotificationFormTest extends BaseTestCase
|
||||
{
|
||||
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\CustomNotificationForm';
|
||||
|
|
|
@ -1,41 +1,10 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/DelayNotificationForm.php';
|
||||
|
||||
use Icinga\Module\Monitoring\Form\Command\DelayNotificationForm;
|
||||
|
||||
class DelayNotificationFormTest extends BaseTestCase
|
||||
|
|
|
@ -1,63 +1,15 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/WithChildrenCommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/RescheduleNextCheckForm.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
|
||||
|
||||
use \DateTimeZone;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
|
||||
class RescheduleNextCheckFormTest extends BaseTestCase
|
||||
{
|
||||
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\RescheduleNextCheckForm';
|
||||
|
||||
/**
|
||||
* Set DateTimeFactory's time zone to UTC
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
public function testFormInvalidWhenChecktimeIsIncorrect()
|
||||
{
|
||||
$form = $this->createForm(
|
||||
|
|
|
@ -1,69 +1,16 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Validate/Digits.php';
|
||||
require_once 'Zend/Validate/GreaterThan.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/ScheduleDowntimeForm.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use DateTimeZone;
|
||||
use Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Module\Monitoring\Form\Command\ScheduleDowntimeForm; // Used by constant FORM_CLASS
|
||||
use Icinga\Module\Monitoring\Form\Command\ScheduleDowntimeForm;
|
||||
|
||||
class ScheduleDowntimeFormTest extends BaseTestCase
|
||||
{
|
||||
const FORM_CLASS = 'Icinga\Module\Monitoring\Form\Command\ScheduleDowntimeForm';
|
||||
|
||||
/**
|
||||
* Set up the default time zone
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
date_default_timezone_set('UTC');
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
}
|
||||
|
||||
public function testCorrectFormElementCreation()
|
||||
{
|
||||
$formFixed = $this->createForm(self::FORM_CLASS);
|
||||
|
|
|
@ -1,42 +1,10 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Forms\Command;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Forms\Command;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once BaseTestCase::$libDir . '/Exception/ProgrammingError.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/CommandForm.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php';
|
||||
|
||||
use Icinga\Module\Monitoring\Form\Command\SubmitPassiveCheckResultForm;
|
||||
|
||||
class SubmitPassiveCheckResultFormTest extends BaseTestCase
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Modules\Monitoring\Application\Views\Helpers;
|
||||
namespace Tests\Icinga\Module\Monitoring\Application\Views\Helpers;
|
||||
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once __DIR__. '/../../../../../application/views/helpers/MonitoringFlags.php';
|
||||
use \Zend_View_Helper_MonitoringFlags;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/MonitoringFlags.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class MonitoringFlagsTest extends BaseTestCase
|
||||
{
|
||||
public function testHosts1()
|
||||
{
|
||||
|
@ -19,7 +24,7 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
|||
'flap_detection_enabled' => '1',
|
||||
);
|
||||
|
||||
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
|
||||
$monitoringFlags = new Zend_View_Helper_MonitoringFlags();
|
||||
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
|
||||
|
||||
$this->assertCount(6, $returnArray);
|
||||
|
@ -47,7 +52,7 @@ class MonitoringFlagsTest extends \PHPUnit_Framework_TestCase
|
|||
'flap_detection_enabled' => '0',
|
||||
);
|
||||
|
||||
$monitoringFlags = new \Zend_View_Helper_MonitoringFlags();
|
||||
$monitoringFlags = new Zend_View_Helper_MonitoringFlags();
|
||||
$returnArray = $monitoringFlags->monitoringFlags((object)$testArray);
|
||||
|
||||
$this->assertCount(6, $returnArray);
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Modules\Monitoring\Application\Views\Helpers;
|
||||
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
require_once 'Zend/View.php';
|
||||
require_once __DIR__. '/../../../../../application/views/helpers/MonitoringProperties.php';
|
||||
use \Zend_View_Helper_MonitoringProperties;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* @TODO(el): This test is subject to bug #4679 and
|
||||
*/
|
||||
class HostStruct4Properties extends \stdClass
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/MonitoringProperties.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class HostStruct4Properties
|
||||
{
|
||||
public $host_name = 'localhost';
|
||||
public $host_address = '127.0.0.1';
|
||||
|
@ -62,14 +64,17 @@ class HostStruct4Properties extends \stdClass
|
|||
public $host_status_update_time = '2013-07-08 10:10:10';
|
||||
}
|
||||
|
||||
class MonitoringPropertiesTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @TODO(el): This test is subject to bug #4679
|
||||
*/
|
||||
class MonitoringPropertiesTest extends BaseTestCase
|
||||
{
|
||||
public function testOutput1()
|
||||
{
|
||||
$host = new HostStruct4Properties();
|
||||
$host->current_check_attempt = '5';
|
||||
|
||||
$propertyHelper = new \Zend_View_Helper_MonitoringProperties();
|
||||
$propertyHelper = new Zend_View_Helper_MonitoringProperties();
|
||||
$items = $propertyHelper->monitoringProperties($host);
|
||||
|
||||
$this->assertEquals('5/10 (HARD state)', $items['Current Attempt']);
|
||||
|
@ -77,14 +82,13 @@ class MonitoringPropertiesTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testOutput2()
|
||||
{
|
||||
date_default_timezone_set("UTC");
|
||||
$host = new HostStruct4Properties();
|
||||
$host->current_check_attempt = '5';
|
||||
$host->active_checks_enabled = '1';
|
||||
$host->passive_checks_enabled = '0';
|
||||
$host->is_flapping = '1';
|
||||
|
||||
$propertyHelper = new \Zend_View_Helper_MonitoringProperties();
|
||||
$propertyHelper = new Zend_View_Helper_MonitoringProperties();
|
||||
$items = $propertyHelper->monitoringProperties($host);
|
||||
|
||||
$test = array(
|
||||
|
|
|
@ -1,64 +1,38 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2014 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2014 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Modules\Monitoring\Application\Views\Helpers;
|
||||
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
namespace Tests\Icinga\Modules\Monitoring\Application\Views\Helpers;
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_View_Helper_ResolveMacros;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
require_once BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/ResolveMacros.php';
|
||||
|
||||
use \stdClass;
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(BaseTestCase::$moduleDir . '/monitoring/application/views/helpers/ResolveMacros.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class ResolveMacrosTest extends BaseTestCase
|
||||
{
|
||||
public function testHostMacros()
|
||||
{
|
||||
$hostMock = new stdClass();
|
||||
$hostMock = Mockery::mock('host');
|
||||
$hostMock->host_name = 'test';
|
||||
$hostMock->host_address = '1.1.1.1';
|
||||
|
||||
$helper = new \Zend_View_Helper_ResolveMacros();
|
||||
$helper = new Zend_View_Helper_ResolveMacros();
|
||||
$this->assertEquals($helper->resolveMacros('$HOSTNAME$', $hostMock), $hostMock->host_name);
|
||||
$this->assertEquals($helper->resolveMacros('$HOSTADDRESS$', $hostMock), $hostMock->host_address);
|
||||
}
|
||||
|
||||
public function testServiceMacros()
|
||||
{
|
||||
$svcMock = new stdClass();
|
||||
$svcMock = Mockery::mock('service');
|
||||
$svcMock->host_name = 'test';
|
||||
$svcMock->host_address = '1.1.1.1';
|
||||
$svcMock->service_description = 'a service';
|
||||
|
||||
$helper = new \Zend_View_Helper_ResolveMacros();
|
||||
$helper = new Zend_View_Helper_ResolveMacros();
|
||||
$this->assertEquals($helper->resolveMacros('$HOSTNAME$', $svcMock), $svcMock->host_name);
|
||||
$this->assertEquals($helper->resolveMacros('$HOSTADDRESS$', $svcMock), $svcMock->host_address);
|
||||
$this->assertEquals($helper->resolveMacros('$SERVICEDESC$', $svcMock), $svcMock->service_description);
|
||||
|
@ -66,25 +40,25 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
|
||||
public function testCustomvars()
|
||||
{
|
||||
$objectMock = new stdClass();
|
||||
$objectMock = Mockery::mock('object');
|
||||
$objectMock->customvars = array(
|
||||
'CUSTOMVAR' => 'test'
|
||||
);
|
||||
|
||||
$helper = new \Zend_View_Helper_ResolveMacros();
|
||||
$helper = new Zend_View_Helper_ResolveMacros();
|
||||
$this->assertEquals($helper->resolveMacros('$CUSTOMVAR$', $objectMock), $objectMock->customvars['CUSTOMVAR']);
|
||||
}
|
||||
|
||||
public function testFaultyMacros()
|
||||
{
|
||||
$hostMock = new \stdClass();
|
||||
$hostMock = Mockery::mock('host');
|
||||
$hostMock->host_name = 'test';
|
||||
$hostMock->customvars = array(
|
||||
'HOST' => 'te',
|
||||
'NAME' => 'st'
|
||||
);
|
||||
|
||||
$helper = new \Zend_View_Helper_ResolveMacros();
|
||||
$helper = new Zend_View_Helper_ResolveMacros();
|
||||
$this->assertEquals(
|
||||
$helper->resolveMacros('$$HOSTNAME$ $ HOSTNAME$ $HOST$NAME$', $hostMock),
|
||||
'$test $ HOSTNAME$ teNAME$'
|
||||
|
@ -93,12 +67,12 @@ class ResolveMacrosTest extends BaseTestCase
|
|||
|
||||
public function testMacrosWithSpecialCharacters()
|
||||
{
|
||||
$objectMock = new \stdClass();
|
||||
$objectMock = Mockery::mock('object');
|
||||
$objectMock->customvars = array(
|
||||
'V€RY_SP3C|@L' => 'not too special!'
|
||||
);
|
||||
|
||||
$helper = new \Zend_View_Helper_ResolveMacros();
|
||||
$helper = new Zend_View_Helper_ResolveMacros();
|
||||
$this->assertEquals(
|
||||
$helper->resolveMacros('$V€RY_SP3C|@L$', $objectMock),
|
||||
$objectMock->customvars['V€RY_SP3C|@L']
|
||||
|
|
|
@ -1,49 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Modules\Monitoring\Library\Filter\Type;
|
||||
namespace Tests\Icinga\Module\Monitoring\Library\Filter\Type;
|
||||
|
||||
use Icinga\Module\Monitoring\Filter\Type\StatusFilter;
|
||||
use Icinga\Filter\Type\TimeRangeSpecifier;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/TimeRangeSpecifier.php');
|
||||
require_once realpath(BaseTestCase::$moduleDir .'/monitoring/library/Monitoring/Filter/Type/StatusFilter.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
|
||||
class StatusFilterTest extends BaseTestCase
|
||||
{
|
||||
public function testOperatorProposal()
|
||||
|
@ -140,4 +105,4 @@ class StatusFilterTest extends BaseTestCase
|
|||
'Assert the right node to be the time specifier query (field)'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +1,11 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
namespace Test\Modules\Monitoring\Library\Filter;
|
||||
|
||||
use Icinga\Filter\Filterable;
|
||||
use Icinga\Filter\Query\Tree;
|
||||
namespace Tests\Icinga\Module\Monitoring\Library\Filter;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Module\Monitoring\Filter\Type\StatusFilter;
|
||||
use Icinga\Filter\Type\TimeRangeSpecifier;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Filter\Filter;
|
||||
use Icinga\Filter\Type\TextFilter;
|
||||
|
@ -39,52 +13,19 @@ use Icinga\Filter\FilterAttribute;
|
|||
use Icinga\Module\Monitoring\Filter\UrlViewFilter;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Filter.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/FilterAttribute.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Domain.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Query/Tree.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Type/TextFilter.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/TimeRangeSpecifier.php');
|
||||
require_once realpath(BaseTestCase::$moduleDir .'/monitoring/library/Monitoring/Filter/Type/StatusFilter.php');
|
||||
require_once realpath(BaseTestCase::$moduleDir .'/monitoring/library/Monitoring/Filter/UrlViewFilter.php');
|
||||
|
||||
class FilterMock implements Filterable
|
||||
{
|
||||
public function isValidFilterTarget($field)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getMappedField($field)
|
||||
{
|
||||
return $field;
|
||||
}
|
||||
|
||||
public function applyFilter()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function clearFilter()
|
||||
{
|
||||
// TODO: Implement clearFilter() method.
|
||||
}
|
||||
|
||||
public function addFilter($filter)
|
||||
{
|
||||
// TODO: Implement addFilter() method.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class UrlViewFilterTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->filterMock = Mockery::mock('Icinga\Filter\Filterable');
|
||||
$this->filterMock->shouldReceive('isValidFilterTarget')->with(Mockery::any())->andReturn(true)
|
||||
->shouldReceive('getMappedField')->andReturnUsing(function ($f) { return $f; })
|
||||
->shouldReceive('applyFilter')->andReturn(true)
|
||||
->shouldReceive('clearFilter')->andReturnNull()
|
||||
->shouldReceive('addFilter')->with(Mockery::any())->andReturnNull();
|
||||
}
|
||||
|
||||
public function testUrlParamCreation()
|
||||
{
|
||||
$this->markTestSkipped('Or queries are disabled');
|
||||
|
@ -113,7 +54,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
. ' and attr5 is UP';
|
||||
|
||||
$tree = $searchEngine->createQueryTreeForFilter($query);
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$uri = $filterFactory->fromTree($tree);
|
||||
$this->assertEquals(
|
||||
'attr1!=Hans+wurst|attr2=%2Asomething%2A&attr3=bla%2A|attr4=1&host_last_state_change>=yesterday&attr5=0',
|
||||
|
@ -124,7 +65,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testTreeFromSimpleKeyValueUrlCreation()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$tree = $filterFactory->parseUrl('attr1!=Hans+Wurst');
|
||||
$this->assertEquals(
|
||||
$tree->root->type,
|
||||
|
@ -152,7 +93,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
{
|
||||
$this->markTestSkipped("OR queries are disabled");
|
||||
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$query = 'attr1!=Hans+Wurst&test=test123|bla=1';
|
||||
$tree = $filterFactory->parseUrl($query);
|
||||
$this->assertEquals($tree->root->type, Node::TYPE_AND, 'Assert the root of the filter tree to be an AND node');
|
||||
|
@ -162,7 +103,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
public function testImplicitConjunctionInUrl()
|
||||
{
|
||||
$this->markTestSkipped("OR queries are disabled");
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$query = 'attr1!=Hans+Wurst&test=test123|bla=1|2|3';
|
||||
$tree = $filterFactory->parseUrl($query);
|
||||
$this->assertEquals($tree->root->type, Node::TYPE_AND, 'Assert the root of the filter tree to be an AND node');
|
||||
|
@ -175,7 +116,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testMissingValuesInQueries()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$queryStr = 'attr1!=Hans+Wurst&test=';
|
||||
$tree = $filterFactory->parseUrl($queryStr);
|
||||
$query = $filterFactory->fromTree($tree);
|
||||
|
@ -184,7 +125,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testErrorInQueries()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$queryStr = 'test=&attr1!=Hans+Wurst';
|
||||
$tree = $filterFactory->parseUrl($queryStr);
|
||||
$query = $filterFactory->fromTree($tree);
|
||||
|
@ -193,7 +134,7 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
|
||||
public function testSenselessConjunctions()
|
||||
{
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
$queryStr = 'test=&|/5/|&attr1!=Hans+Wurst';
|
||||
$tree = $filterFactory->parseUrl($queryStr);
|
||||
$query = $filterFactory->fromTree($tree);
|
||||
|
@ -203,12 +144,11 @@ class UrlViewFilterTest extends BaseTestCase
|
|||
public function testRandomString()
|
||||
{
|
||||
$filter = '';
|
||||
$filterFactory = new UrlViewFilter(new FilterMock());
|
||||
$filterFactory = new UrlViewFilter($this->filterMock);
|
||||
|
||||
for ($i=0; $i<10;$i++) {
|
||||
$filter .= str_shuffle('&|ds& wra =!<>|dsgs=,-G');
|
||||
$tree = $filterFactory->parseUrl($filter);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,310 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib;
|
||||
|
||||
require_once 'Zend/View.php';
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
|
||||
use \Zend_View;
|
||||
use \Zend_Config;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use \Icinga\Protocol\Statusdat\Reader;
|
||||
use \Icinga\Web\Controller\ActionController;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
use \Test\Monitoring\Testlib\DataSource\DataSourceTestSetup;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
|
||||
/**
|
||||
* Base class for monitoring controllers that loads required dependencies
|
||||
* and allows easier setup of tests
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
*
|
||||
* class MyControllerTest extends MonitoringControllerTest
|
||||
* {
|
||||
* public function testSomething()
|
||||
* {
|
||||
* // Create a test fixture
|
||||
* $fixture = new TestFixture()
|
||||
* $fixture->addHost('host', 0)->addService(...)->..->;
|
||||
*
|
||||
* $this->setupFixture($fixture, "mysql"); // setup the fixture
|
||||
* $controller = $this->requireController('MyController', 'mysql');
|
||||
* // controller is now the Zend controller instance, perform an action
|
||||
* $controller->myAction();
|
||||
* $result = $controller->view->hosts->fetchAll();
|
||||
* // assert stuff
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
abstract class MonitoringControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
{
|
||||
/**
|
||||
* The module directory for requiring modules (is relative to the source file)
|
||||
* @var string
|
||||
*/
|
||||
private $moduleDir = "";
|
||||
|
||||
/**
|
||||
* The application directory for requirying library files (is relative to the source file)
|
||||
* @var string
|
||||
*/
|
||||
private $appDir = "";
|
||||
|
||||
/**
|
||||
* Require necessary libraries on test creation
|
||||
*
|
||||
* This is called for every test and assures that all required libraries for the controllers
|
||||
* are loaded. If you need additional dependencies you should overwrite this method, call the parent
|
||||
* and then require your classes
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->moduleDir = dirname(__FILE__) . '/../../../';
|
||||
$this->appDir = $this->moduleDir.'../../library/Icinga/';
|
||||
$module = $this->moduleDir;
|
||||
$app = $this->appDir;
|
||||
set_include_path(get_include_path().':'.$module);
|
||||
set_include_path(get_include_path().':'.$app);
|
||||
|
||||
require_once('Zend/Config.php');
|
||||
require_once('Zend/Db.php');
|
||||
require_once(dirname(__FILE__) . '/datasource/DataSourceTestSetup.php');
|
||||
|
||||
$this->requireBase();
|
||||
$this->requireViews();
|
||||
|
||||
ResourceFactory::setConfig(
|
||||
new Zend_Config(array(
|
||||
'statusdat-unittest' => array(
|
||||
'type' => 'statusdat',
|
||||
'status_file' => '/tmp/teststatus.dat',
|
||||
'object_file' => '/tmp/testobjects.cache',
|
||||
'no_cache' => true
|
||||
),
|
||||
'ido-mysql-unittest' => array(
|
||||
'type' => 'db',
|
||||
'db' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'username' => 'icinga_unittest',
|
||||
'password' => 'icinga_unittest',
|
||||
'dbname' => 'icinga_unittest'
|
||||
),
|
||||
'ido-pgsql-unittest' => array(
|
||||
'type' => 'db',
|
||||
'db' => 'mysql',
|
||||
'host' => 'localhost',
|
||||
'username' => 'icinga_unittest',
|
||||
'password' => 'icinga_unittest',
|
||||
'dbname' => 'icinga_unittest'
|
||||
)
|
||||
))
|
||||
);
|
||||
Backend::setConfig(
|
||||
new Zend_Config(array(
|
||||
'statusdat-unittest' => array(
|
||||
'type' => 'statusdat',
|
||||
'resource' => 'statusdat-unittest'
|
||||
),
|
||||
'ido-mysql-unittest' => array(
|
||||
'type' => 'ido',
|
||||
'resource' => 'ido-mysql-unittest'
|
||||
),
|
||||
'ido-pgsql-unittest' => array(
|
||||
'type' => 'ido',
|
||||
'resource' => 'ido-pgsql-unittest'
|
||||
)
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Require base application and data retrieval classes from the Icinga Library
|
||||
*
|
||||
*/
|
||||
private function requireBase()
|
||||
{
|
||||
require_once('Application/Benchmark.php');
|
||||
require_once('Data/BaseQuery.php');
|
||||
require_once('Data/DatasourceInterface.php');
|
||||
require_once('Data/Db/Connection.php');
|
||||
require_once('Data/Db/Query.php');
|
||||
require_once('Exception/ProgrammingError.php');
|
||||
require_once('Web/Widget/SortBox.php');
|
||||
require_once('Web/Widget/FilterBox.php');
|
||||
require_once('Web/Widget/FilterBadgeRenderer.php');
|
||||
require_once('library/Monitoring/Backend.php');
|
||||
require_once('library/Monitoring/Controller.php');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all defined IDO queries in this module
|
||||
*
|
||||
*/
|
||||
private function requireIDOQueries()
|
||||
{
|
||||
require_once('library/Monitoring/Backend/Ido/Query/IdoQuery.php');
|
||||
$this->requireFolder('library/Monitoring/Backend/Ido/Query');
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all php files in the folder $folder
|
||||
*
|
||||
* @param $folder The path to the folder containing PHP files
|
||||
*/
|
||||
private function requireFolder($folder)
|
||||
{
|
||||
$module = $this->moduleDir;
|
||||
$views = scandir($module.$folder);
|
||||
foreach ($views as $view) {
|
||||
if (!preg_match('/php$/', $view)) {
|
||||
continue;
|
||||
}
|
||||
require_once(realpath($module.$folder."/".$view));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all views and queries from the statusdat backen
|
||||
*
|
||||
*/
|
||||
private function requireStatusDatQueries()
|
||||
{
|
||||
require_once(realpath($this->moduleDir.'/library/Monitoring/Backend/Statusdat/Query/StatusdatQuery.php'));
|
||||
$this->requireFolder('library/Monitoring/Backend/Statusdat');
|
||||
$this->requireFolder('library/Monitoring/Backend/Statusdat/Query');
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all (generic) view classes from the monitoring module
|
||||
*/
|
||||
private function requireViews()
|
||||
{
|
||||
$module = $this->moduleDir;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Require and set up a controller $controller using the backend type specified at $backend
|
||||
*
|
||||
* @param string $controller The name of the controller tu use
|
||||
* (must be under monitoring/application/controllers)
|
||||
* @param string $backend The backend to use ('mysql', 'pgsql' or 'statusdat')
|
||||
* @return ModuleActionController The newly created controller
|
||||
*/
|
||||
public function requireController($controller, $backend)
|
||||
{
|
||||
require_once($this->moduleDir . '/library/Monitoring/Controller.php');
|
||||
require_once($this->moduleDir . '/application/controllers/'.$controller.'.php');
|
||||
$controllerName = '\Monitoring_'.ucfirst($controller);
|
||||
$request = $this->getRequest();
|
||||
if ($backend == 'statusdat') {
|
||||
$this->requireStatusDatQueries();
|
||||
$request->setParam('backend', 'statusdat-unittest');
|
||||
} else {
|
||||
$this->requireStatusDatQueries();
|
||||
$request->setParam('backend', "ido-$backend-unittest");
|
||||
}
|
||||
/** @var ActionController $controller */
|
||||
$controller = new $controllerName(
|
||||
$request,
|
||||
$this->getResponse(),
|
||||
array('noInit' => true)
|
||||
);
|
||||
$controller->setBackend($this->getBackendFor($backend));
|
||||
|
||||
// Many controllers need a view to work properly
|
||||
$controller->view = new Zend_View();
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new backend and insert the given fixture into it
|
||||
*
|
||||
* @param TestFixture $fixture The TestFixture to create
|
||||
* @param string $type The type of the backend ('mysql', 'pgsql' or 'statusdat')
|
||||
*/
|
||||
public function setupFixture(TestFixture $fixture, $type)
|
||||
{
|
||||
$dbInstance = new DataSourceTestSetup($type);
|
||||
$dbInstance->setup();
|
||||
$dbInstance->insert($fixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up and configure a new testbackend for the given type
|
||||
*
|
||||
* @param string $type The type of the backend 'mysql', 'pgsql' or 'statusdat'
|
||||
* @return Ido|Statusdat The newly created backend
|
||||
*/
|
||||
public function getBackendFor($type)
|
||||
{
|
||||
if ($type == "mysql" || $type == "pgsql") {
|
||||
$this->requireIDOQueries();
|
||||
$backendConfig = new Zend_Config(array(
|
||||
'type' => 'ido'
|
||||
));
|
||||
$resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'type' => 'db',
|
||||
'db' => $type,
|
||||
'host' => "localhost",
|
||||
'username' => "icinga_unittest",
|
||||
'password' => "icinga_unittest",
|
||||
'dbname' => "icinga_unittest"
|
||||
)
|
||||
);
|
||||
return new Backend($backendConfig, $resourceConfig);
|
||||
} elseif ($type == "statusdat") {
|
||||
$this->requireStatusDatQueries();
|
||||
$backendConfig = new Zend_Config(array(
|
||||
'type' => 'statusdat'
|
||||
));
|
||||
$resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'type' => 'statusdat',
|
||||
'status_file' => '/tmp/teststatus.dat',
|
||||
'object_file' => '/tmp/testobjects.cache',
|
||||
'no_cache' => true
|
||||
)
|
||||
);
|
||||
return new Backend(
|
||||
$backendConfig,
|
||||
$resourceConfig
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\DataSource;
|
||||
|
||||
require_once(dirname(__FILE__).'/strategies/InsertionStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/SetupStrategy.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/strategies/MySQLSetupStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/PgSQLSetupStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/PDOInsertionStrategy.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/strategies/StatusdatInsertionStrategy.php');
|
||||
require_once(dirname(__FILE__).'/strategies/StatusdatSetupStrategy.php');
|
||||
|
||||
require_once(dirname(__FILE__).'/TestFixture.php');
|
||||
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\InsertionStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\SetupStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\MySQLSetupStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\PgSQLSetupStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\PDOInsertionStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatInsertionStrategy;
|
||||
use \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatSetupStrategy;
|
||||
|
||||
/**
|
||||
* Fascade class that handles creation of test-fixture backends
|
||||
*
|
||||
* This class handles the creation and combination of SetupStrategies and InsertionStrategy
|
||||
* when testing controllers/queries with different backends.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* // TestFixtures contain the objects that should be written for testing
|
||||
* $fixture = new TestFixture();
|
||||
* $fixture->addHost(..)->... // setup fixture
|
||||
*
|
||||
* $ds = new DataSourceTestSetup('mysql');
|
||||
* $ds->setup(); // create a blank datasource
|
||||
* $ds->insert($fixture);
|
||||
* </code>
|
||||
*
|
||||
*
|
||||
*/
|
||||
class DataSourceTestSetup implements SetupStrategy, InsertionStrategy
|
||||
{
|
||||
/**
|
||||
* The SetupStrategy that is used on 'setup'
|
||||
* @var \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatSetupStrategy
|
||||
*/
|
||||
private $setupStrategy;
|
||||
|
||||
/**
|
||||
* The InsertionStrategy that is used on 'insert'
|
||||
* @var \Test\Monitoring\Testlib\Datasource\Strategies\StatusdatInsertionStrategy
|
||||
*/
|
||||
private $insertionStrategy;
|
||||
|
||||
/**
|
||||
* Create a DataSource for the backend $type.
|
||||
*
|
||||
* On creation, a suitable setup/insert combination will be used
|
||||
* for the provided backend, so the caller needn't to care about which
|
||||
* setup or insertion strategy he wants to use.
|
||||
*
|
||||
* @param String $type The type of the backend (currently 'mysql', 'pgsql' and 'statusdat')
|
||||
*/
|
||||
public function __construct($type)
|
||||
{
|
||||
if ($type == 'mysql') {
|
||||
$this->setupStrategy = new MySQLSetupStrategy();
|
||||
$this->insertionStrategy = new PDOInsertionStrategy();
|
||||
$this->insertionStrategy->datetimeFormat = "Y-m-d H:i:s";
|
||||
|
||||
} elseif ($type == 'pgsql') {
|
||||
$this->setupStrategy = new PgSQLSetupStrategy();
|
||||
$this->insertionStrategy = new PDOInsertionStrategy();
|
||||
$this->insertionStrategy->datetimeFormat = "Y-m-d H:i:s";
|
||||
} elseif ($type == 'statusdat') {
|
||||
$this->setupStrategy = new StatusdatSetupStrategy();
|
||||
$this->insertionStrategy = new StatusdatInsertionStrategy();
|
||||
} else {
|
||||
throw new \Exception('Unsupported backend '.$type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a testfixture into this datasource
|
||||
*
|
||||
* @param TestFixture $fixture The fixture to insert into the datasource
|
||||
*/
|
||||
public function insert(TestFixture $fixture) {
|
||||
$this->insertionStrategy->insert($fixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a blank datasource that can be filled with TestFixtures afterwards
|
||||
*
|
||||
* @param String $version An (optional) version to use for creation
|
||||
* @param mixed $connection An (optional) connection to use for this datasource
|
||||
*/
|
||||
public function setup($version = null, $connection = null)
|
||||
{
|
||||
$c = $this->setupStrategy->setup($version, $connection);
|
||||
|
||||
$this->insertionStrategy->setConnection($c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all testdata created in this datasource
|
||||
*
|
||||
* @param mixed $connection An optional connection to use for clean up
|
||||
*/
|
||||
public function teardown($connection = null)
|
||||
{
|
||||
$this->setupStrategy->teardown($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the connection to use for writing to this datasource
|
||||
*
|
||||
* @param mixed $connection The connection to use. The actual type depends
|
||||
* on the used backend
|
||||
*/
|
||||
public function setConnection($connection)
|
||||
{
|
||||
$this->insertionStrategy->setConnection($connection);
|
||||
}
|
||||
}
|
|
@ -1,586 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\DataSource;
|
||||
|
||||
/**
|
||||
* Status flags for objects
|
||||
*
|
||||
*/
|
||||
class ObjectFlags {
|
||||
/**
|
||||
* 1 if the test host is flapping, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $flapping = 0;
|
||||
|
||||
/**
|
||||
* 1 if the test host has notifications enabled, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $notifications = 1;
|
||||
|
||||
/**
|
||||
* 1 if the test host is active, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $active_checks = 1;
|
||||
|
||||
/**
|
||||
* 1 if the test host allows passive checks, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $passive_checks = 1;
|
||||
|
||||
/**
|
||||
* 1 if the test host is acknowledged, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $acknowledged = 0;
|
||||
|
||||
/**
|
||||
* 1 if the test host is in a downtime, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $in_downtime = 0;
|
||||
|
||||
/**
|
||||
* 1 if the test host is pending, otherwise 0
|
||||
* @var int
|
||||
*/
|
||||
public $is_pending = 0;
|
||||
|
||||
/**
|
||||
* The last check and state change time as a UNIX timestamp
|
||||
* @var int
|
||||
*/
|
||||
public $time = 0;
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags instance with default values
|
||||
*
|
||||
* @param int $ageInSeconds How old this check should be in seconds
|
||||
*/
|
||||
public function __construct($ageInSeconds = null)
|
||||
{
|
||||
if(!is_int($ageInSeconds))
|
||||
$ageInSeconds = 0;
|
||||
$this->time = time()-$ageInSeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'flapping' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function FLAPPING()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->flapping = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'pending' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function PENDING()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->is_pending = 1;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'notifications_disabled' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function DISABLE_NOTIFICATIONS()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->notifications = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that has active checks disabled but passive enabled
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function PASSIVE_ONLY()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->active_checks = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that has passive checks disabled but active enabled
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function ACTIVE_ONLY()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->passive_checks = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is neither active nor passive
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function DISABLED() {
|
||||
$flags = new ObjectFlags();
|
||||
$flags->passive_checks = 0;
|
||||
$flags->active_checks = 0;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in 'acknowledged' state
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function ACKNOWLEDGED()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->acknowledged = 1;
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new ObjectFlags object that is in a downtime
|
||||
*
|
||||
* @return ObjectFlags
|
||||
*/
|
||||
public static function IN_DOWNTIME()
|
||||
{
|
||||
$flags = new ObjectFlags();
|
||||
$flags->in_downtime = 1;
|
||||
return $flags;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal class that adds an object scope on Fixture operations
|
||||
*
|
||||
* This class allows to use $fixture->addHost('host',0)->addService() instead('svc')
|
||||
* of $fixture->addHost('host',0); $fixture->addService('host', 'svc') as it encapsulates
|
||||
* the scope of the last called object and automatically adds it as the first parameter
|
||||
* of the next call.
|
||||
*
|
||||
*/
|
||||
class TestFixtureObjectClosure
|
||||
{
|
||||
/**
|
||||
* The object (hostname or hostname/servicename pair) this scope represents
|
||||
* @var String|array
|
||||
*/
|
||||
private $scope;
|
||||
|
||||
/**
|
||||
* The Testfixture to operate on
|
||||
* @var TestFixture
|
||||
*/
|
||||
private $environment;
|
||||
|
||||
/**
|
||||
* Create a new scope using the TestFixture with the given host / service
|
||||
* as the scope
|
||||
*
|
||||
* @param TestFixture $environment The testfixture to use for subsequent calls
|
||||
* @param $scope The scope to prepend to all further calls
|
||||
*/
|
||||
public function __construct(TestFixture $environment, $scope)
|
||||
{
|
||||
$this->scope = $scope;
|
||||
$this->environment = $environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method that forwards all function calls to the environment
|
||||
* but prepends the scope.
|
||||
*
|
||||
* A call func($arg1) to this class would be rewritten to $environment->func($scope, $arg1)
|
||||
*
|
||||
* @param string $string The method that should be called with this scope
|
||||
* @param array $arguments The arguments the user passed to the function
|
||||
* @return mixed The result of the function call
|
||||
*/
|
||||
public function __call($string, $arguments)
|
||||
{
|
||||
$callArg = array($this->scope);
|
||||
$args = array_merge($callArg, $arguments);
|
||||
return call_user_func_array(array($this->environment, $string), $args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create test-states that can be persisted to different backends
|
||||
* using DataSourceTestSetup.
|
||||
*
|
||||
* This class provides not all fields used in monitoring, but the most
|
||||
* important ones (and the ones that are missing should be added during
|
||||
* developmen).
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $fixture = new TestFixture();
|
||||
* // adding a new critical, but acknowledged host
|
||||
* $fixture->addHost("hostname", 1, ObjectFlags::ACKNOWLEDGED())
|
||||
*
|
||||
* // add a comment to the host (this has to be done before adding services)
|
||||
* ->addComment("author", "comment text")
|
||||
*
|
||||
* // assign to hostgroup
|
||||
* ->addToHostgroup("myHosts")
|
||||
*
|
||||
* // and add three services to this host
|
||||
* ->addService("svc1", 0) // Service is ok
|
||||
* ->addService("svc2", 1, ObjectFlags::PASSIVE) // service is warning and passive
|
||||
* ->addService("svc3", 2, null, array("notes_url" => "test.html")) // critical with notes url
|
||||
* ->addComment("author", "what a nice service comment") // add a comment to the service
|
||||
* ->addToServicegroup("alwaysdown"); // add svc3 to servicegroup
|
||||
*
|
||||
* // Create the datasource from this fixture, here form MySQL
|
||||
* $ds = new DataSourceTestSetup("mysql");
|
||||
* $ds->setup();
|
||||
* // insert fixture
|
||||
* $ds->insert($fixture);
|
||||
* </code>
|
||||
*
|
||||
*/
|
||||
class TestFixture
|
||||
{
|
||||
/**
|
||||
* Internal dataholder for all defined hosts
|
||||
* @var array
|
||||
*/
|
||||
private $hosts = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined services
|
||||
* @var array
|
||||
*/
|
||||
private $services = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined contacts
|
||||
* @var array
|
||||
*/
|
||||
private $contacts = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined comments
|
||||
* @var array
|
||||
*/
|
||||
private $comments = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined servicegroups
|
||||
* @var array
|
||||
*/
|
||||
private $servicegroups = array();
|
||||
|
||||
/**
|
||||
* Internal holder for all defined hostgroups
|
||||
* @var array
|
||||
*/
|
||||
private $hostgroups = array();
|
||||
|
||||
/**
|
||||
* Return array with all defined hostobjects
|
||||
*
|
||||
* @return array Returns an array of host-arrays, which have the following fields
|
||||
* - 'name' : The name of the host
|
||||
* - 'state' : The state of the host (0,1,2)
|
||||
* - 'address' : The string representation of the address (127.0.0.1 as default)
|
||||
* - 'flags' : An ObjectFlags object containing additional state information
|
||||
* - 'icon_image' : The icon image of this host (default: 'icon.png')
|
||||
* - 'notes_url' : The notes url of this host (default empty string)
|
||||
* - 'action_url' : The action url of this host (default empty string)
|
||||
* - 'contacts' : An array of contact objects (having 'name' as the most important field)
|
||||
* - 'customvariables' : An associative "cv_name"=>"cv_value" array containing the customvariables
|
||||
*/
|
||||
public function getHosts()
|
||||
{
|
||||
return $this->hosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with all defined service objects
|
||||
*
|
||||
* @return array Returns an array of service-arrays, which have the following fields
|
||||
* - 'name' : The name of the service
|
||||
* - 'host' : A reference to the hostobject
|
||||
* - 'state' : The state of the service (0,1,2,3)
|
||||
* - 'flags' : An ObjectFlags object containing additional state information
|
||||
* - 'icon_image' : The icon image of this service (default: 'icon.png')
|
||||
* - 'notes_url' : The notes url of this service (default empty string)
|
||||
* - 'action_url' : The action url of this service (default empty string)
|
||||
* - 'contacts' : An array of contact objects (having 'name' as the most important field)
|
||||
* - 'customvariables' : An associative "cv_name"=>"cv_value" array containing the customvariables
|
||||
*/
|
||||
public function getServices()
|
||||
{
|
||||
return $this->services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with all defined contacts
|
||||
*
|
||||
* @return array Returns an array of contact-arrays, which have the following fields
|
||||
* - 'alias' : The name of the contact
|
||||
*/
|
||||
public function getContacts()
|
||||
{
|
||||
return $this->contacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with all defined servicegroups
|
||||
*
|
||||
* @return array Returns an array of group-arrays in the following format:
|
||||
* - 'name' : The name of the group
|
||||
* - 'members' : An array of service objects that belong to this group
|
||||
*/
|
||||
public function getServicegroups()
|
||||
{
|
||||
return $this->servicegroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array with all defined hostgroups
|
||||
*
|
||||
* @return array Returns an array of group-arrays in the following format:
|
||||
* - 'name' : The name of the group
|
||||
* - 'members' : An array of host objects that belong to this group
|
||||
*/
|
||||
public function getHostgroups()
|
||||
{
|
||||
return $this->hostgroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of service and hostcomments
|
||||
*
|
||||
* @return array Returns an array of comment arrays in the following format:
|
||||
* - 'service' (if servicecomment) : A reference to the service object this comment belongs to
|
||||
* - 'host' (if hostcomment) : A reference to the host object this comment belongs to
|
||||
* - 'author' : The author of this comment
|
||||
* - 'text' : The comment text
|
||||
*/
|
||||
public function getComments()
|
||||
{
|
||||
return $this->comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new host to this TestFixture
|
||||
*
|
||||
* @param string $name The name of the host to add
|
||||
* @param int $state The state of the host to add (0,1,2)
|
||||
* @param ObjectFlags $flags (optional) An @see ObjectFlags object defining additional state inforamtion
|
||||
* @param array $additional (optional) An array with additional object fields
|
||||
*
|
||||
* @return TestFixtureObjectClosure The TestFixture with the newly added host as the scope
|
||||
*/
|
||||
public function addHost($name, $state, ObjectFlags $flags = null, array $additional = array()) {
|
||||
if ($flags === null) {
|
||||
$flags = new ObjectFlags();
|
||||
}
|
||||
if (isset($this->hosts[$name])) {
|
||||
throw new Exception('Tried to create hosts twice');
|
||||
}
|
||||
$this->hosts[$name] = array(
|
||||
'name' => $name,
|
||||
'state' => $state,
|
||||
'address' => '127.0.0.1',
|
||||
'flags' => $flags,
|
||||
'icon_image' => 'icon.png',
|
||||
'notes_url' => '',
|
||||
'action_url' => '',
|
||||
'contacts' => array(),
|
||||
'customvariables' => array()
|
||||
|
||||
);
|
||||
$this->hosts[$name] = array_merge($this->hosts[$name], $additional);
|
||||
return new TestFixtureObjectClosure($this, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new service to this TestFixture
|
||||
*
|
||||
* @param string $host The name of the host this service belongs to (must exist prior to service creation)
|
||||
* @param string $name The name of the service to add
|
||||
* @param int $state The state of the service to add (0,1,2,3)
|
||||
* @param ObjectFlags $flags (optional) An @see ObjectFlags object defining additional state information
|
||||
* @param array $additional (optional) An array with additional object fields
|
||||
*
|
||||
* @return TestFixtureObjectClosure The TestFixture with the newly added service as the scope
|
||||
*/
|
||||
public function addService($host, $name, $state, ObjectFlags $flags = null, array $additional = array()) {
|
||||
// when called in service scope only use the host
|
||||
if (is_array($host)) {
|
||||
$host = $host[0];
|
||||
}
|
||||
if ($flags === null) {
|
||||
$flags = new ObjectFlags();
|
||||
}
|
||||
if (!isset($this->hosts[$host])) {
|
||||
throw new Exception('Tried to create service for non existing host '.$host);
|
||||
}
|
||||
if (isset($this->services[$name])) {
|
||||
throw new Exception('Tried to create service twice '.$name);
|
||||
}
|
||||
$this->services[$host.';'.$name] = array(
|
||||
'host' => &$this->hosts[$host],
|
||||
'name' => $name,
|
||||
'state' => $state,
|
||||
'contacts' => array(),
|
||||
'icon_image' => 'icon.png',
|
||||
'notes_url' => '',
|
||||
'action_url' => '',
|
||||
'customvariables' => array(),
|
||||
'flags' => $flags
|
||||
);
|
||||
$this->services[$host.';'.$name] = array_merge($this->services[$host.';'.$name], $additional);
|
||||
|
||||
return new TestFixtureObjectClosure($this, array($host, $name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new comment to the host or service provided in $hostOrServiceHostPair
|
||||
*
|
||||
* @param string|array $hostOrServiceHostPair Either a string with the hostname or an array with the hostname
|
||||
* as the first and the servicename as the second element
|
||||
* @param $author The author for the coment
|
||||
* @param $text The content of the comment
|
||||
* @return TestFixtureObjectClosure The TestFixture with the comment owner as the scope
|
||||
*/
|
||||
public function addComment($hostOrServiceHostPair, $author, $text) {
|
||||
if (is_array($hostOrServiceHostPair)) {
|
||||
if (!isset($this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting service '.$hostOrServiceHostPair[1]);
|
||||
}
|
||||
$this->comments[] = array(
|
||||
'service' => &$this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]],
|
||||
'author' => $author,
|
||||
'text' => $text
|
||||
);
|
||||
} else {
|
||||
if (!isset($this->hosts[$hostOrServiceHostPair])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting host '.$hostOrServiceHostPair);
|
||||
}
|
||||
$this->comments[] = array(
|
||||
'host' => &$this->hosts[$hostOrServiceHostPair],
|
||||
'author' => $author,
|
||||
'text' => $text
|
||||
);
|
||||
}
|
||||
return new TestFixtureObjectClosure($this, $hostOrServiceHostPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a new contact to a host or service
|
||||
*
|
||||
* @param $hostOrServiceHostPair Either a string with the hostname or an array with the hostname
|
||||
* as the first and the servicename as the second element
|
||||
* @param $contactname The contactname to assign (will be created)
|
||||
* @return TestFixtureObjectClosure The TestFixture with the host or service as the scope
|
||||
*/
|
||||
public function assignContact($hostOrServiceHostPair, $contactname) {
|
||||
$this->contacts[$contactname] = array('alias' => $contactname);
|
||||
if (is_array($hostOrServiceHostPair)) {
|
||||
if (!isset($this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting service '.$hostOrServiceHostPair[1]);
|
||||
}
|
||||
$service = $this->services[$hostOrServiceHostPair[0].';'.$hostOrServiceHostPair[1]];
|
||||
$service['contacts'][] = &$this->contacts[$contactname];
|
||||
} else {
|
||||
if (!isset($this->hosts[$hostOrServiceHostPair])) {
|
||||
throw new Exception('Tried to add a comment for a nonexisting host '.$hostOrServiceHostPair);
|
||||
}
|
||||
$host = $this->hosts[$hostOrServiceHostPair];
|
||||
$host['contacts'][] = &$this->contacts[$contactname];
|
||||
}
|
||||
return new TestFixtureObjectClosure($this, $hostOrServiceHostPair);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a host to a hostgroup
|
||||
*
|
||||
* Create the new hostgroup if it not exists yet, otherwise just add the
|
||||
* host to it
|
||||
*
|
||||
* @param string $host The name of the host to add to the hostgroup
|
||||
* @param string $groupname The name of the hostgroup
|
||||
* @return TestFixtureObjectClosure The TestFixture with the host as the scope
|
||||
*/
|
||||
public function addToHostgroup($host, $groupname) {
|
||||
// check if in service scope
|
||||
if (is_array($host)) {
|
||||
$host = $host[0];
|
||||
}
|
||||
if (!isset($this->hosts[$host])) {
|
||||
throw new Exception('Tried to add non-existing host '.$host.' to hostgroup ');
|
||||
}
|
||||
if (!isset($this->hostgroups[$groupname])) {
|
||||
$this->hostgroups[$groupname] = array("name" => $groupname, "members" => array());
|
||||
}
|
||||
$this->hostgroups[$groupname]["members"][] = &$this->hosts[$host];
|
||||
return new TestFixtureObjectClosure($this, $host);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add service to a servicegroup
|
||||
*
|
||||
* Create the new service if it not exists yet, otherwise just add the service
|
||||
*
|
||||
* @param array $serviceHostPair An array containing the hostname as the first and the
|
||||
* servicename as the second element
|
||||
* @param string $groupname The name of the servicegroup
|
||||
* @return TestFixtureObjectClosure The TestFixture with the service as the scope
|
||||
*/
|
||||
public function addToServicegroup(array $serviceHostPair, $groupname) {
|
||||
if (!isset($this->services[$serviceHostPair[0].";".$serviceHostPair[1]])) {
|
||||
throw new Exception('Tried to add non-existing service '.$serviceHostPair[1].' to servicegroup ');
|
||||
}
|
||||
$service = &$this->services[$serviceHostPair[0].";".$serviceHostPair[1]];
|
||||
if (!isset($this->servicegroups[$groupname])) {
|
||||
$this->servicegroups[$groupname] = array("name" => $groupname, "members" => array());
|
||||
}
|
||||
$this->servicegroups[$groupname]["members"][] = &$service;
|
||||
return new TestFixtureObjectClosure($this, $serviceHostPair);
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Testlib\DataSource\schemes;
|
||||
|
||||
/**
|
||||
* Container class for Objectcache object snipptes
|
||||
*
|
||||
*/
|
||||
class ObjectsCacheTemplates {
|
||||
|
||||
public static $HOST =<<<'EOF'
|
||||
define host {
|
||||
host_name\t{{HOST_NAME}}
|
||||
alias\t{{HOST_NAME}} alias
|
||||
address\t{{HOST_ADDRESS}}
|
||||
check_period\t24x7
|
||||
check_command\ttest-check-host-alive-parent!flap!$HOSTSTATE:router_00$
|
||||
contact_groups\ttest_contact
|
||||
notification_period\t24x7
|
||||
initial_state\to
|
||||
check_interval\t10.000000
|
||||
retry_interval\t1.000000
|
||||
max_check_attempts\t5
|
||||
active_checks_enabled\t1
|
||||
passive_checks_enabled\t1
|
||||
obsess_over_host\t1
|
||||
event_handler_enabled\t1
|
||||
low_flap_threshold\t0.000000
|
||||
high_flap_threshold\t0.000000
|
||||
flap_detection_enabled\t1
|
||||
flap_detection_options\to,d,u
|
||||
freshness_threshold\t0
|
||||
check_freshness\t0
|
||||
notification_options\td,u,r
|
||||
notifications_enabled\t1
|
||||
notification_interval\t0.000000
|
||||
first_notification_delay\t0.000000
|
||||
stalking_options\tn
|
||||
process_perf_data\t1
|
||||
failure_prediction_enabled\t1
|
||||
icon_image\t{{ICON_IMAGE}}
|
||||
icon_image_alt\ticon alt string
|
||||
notes\tjust a notes string
|
||||
notes_url\t{{NOTES_URL}}
|
||||
action_url\t{{ACTION_URL}}
|
||||
retain_status_information\t1
|
||||
retain_nonstatus_information\t1
|
||||
}
|
||||
EOF;
|
||||
public static $SERVICE =<<<'EOF'
|
||||
define service {
|
||||
host_name\t{{HOST_NAME}}
|
||||
service_description\t{{SERVICE_NAME}}
|
||||
check_period\t24x7
|
||||
check_command\tcheck_service!critical
|
||||
contact_groups\ttest_contact
|
||||
notification_period\t24x7
|
||||
initial_state\to
|
||||
check_interval\t5.000000
|
||||
retry_interval\t2.000000
|
||||
max_check_attempts\t3
|
||||
is_volatile\t0
|
||||
parallelize_check\t1
|
||||
active_checks_enabled\t1
|
||||
passive_checks_enabled\t1
|
||||
obsess_over_service\t1
|
||||
event_handler_enabled\t1
|
||||
low_flap_threshold\t0.000000
|
||||
high_flap_threshold\t0.000000
|
||||
flap_detection_enabled\t1
|
||||
flap_detection_options\to,w,u,c
|
||||
freshness_threshold\t0
|
||||
check_freshness\t0
|
||||
notification_options\tu,w,c,r
|
||||
notifications_enabled\t1
|
||||
notification_interval\t0.000000
|
||||
first_notification_delay\t0.000000
|
||||
stalking_options\tn
|
||||
process_perf_data\t1
|
||||
failure_prediction_enabled\t1
|
||||
icon_image\t{{ICON_IMAGE}}
|
||||
icon_image_alt\ticon alt string
|
||||
notes\tjust a notes string
|
||||
notes_url\t{{NOTES_URL}}
|
||||
action_url\t{{ACTION_URL}}
|
||||
retain_status_information\t1
|
||||
retain_nonstatus_information\t1
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $GROUP =<<<'EOF'
|
||||
define {{TYPE}}group {
|
||||
{{TYPE}}group_name\t{{NAME}}
|
||||
alias\t{{NAME}}
|
||||
members\t{{MEMBERS}}
|
||||
}
|
||||
EOF;
|
||||
|
||||
};
|
|
@ -1,173 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* User: moja
|
||||
* Date: 7/17/13
|
||||
* Time: 10:25 AM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
|
||||
namespace Test\Monitoring\Testlib\DataSource\schemes;
|
||||
|
||||
/**
|
||||
* Container class for Statusdat object snippets
|
||||
*
|
||||
*/
|
||||
class StatusdatTemplates {
|
||||
|
||||
public static $HOST =<<<'EOF'
|
||||
hoststatus {
|
||||
host_name={{HOST_NAME}}
|
||||
modified_attributes=0
|
||||
check_command=test-check-host-alive-parent!pending!$HOSTSTATE:router_01$
|
||||
check_period=24x7
|
||||
notification_period=24x7
|
||||
check_interval=10.000000
|
||||
retry_interval=1.000000
|
||||
event_handler=
|
||||
has_been_checked=0
|
||||
should_be_scheduled=0
|
||||
check_execution_time=0.000
|
||||
check_latency=0.000
|
||||
check_type=0
|
||||
current_state={{HOST_STATUS}}
|
||||
last_hard_state=0
|
||||
last_event_id=14750
|
||||
current_event_id=14756
|
||||
current_problem_id=6016
|
||||
last_problem_id=6010
|
||||
plugin_output=Plugin output for host {{HOST_NAME}}
|
||||
long_plugin_output=Long plugin output for host {{HOST_NAME}}
|
||||
performance_data=
|
||||
last_check={{TIME}}
|
||||
next_check=1374002661
|
||||
check_options=0
|
||||
current_attempt=2
|
||||
max_attempts=5
|
||||
state_type=0
|
||||
last_state_change={{TIME}}
|
||||
last_hard_state_change={{TIME}}
|
||||
last_time_up=1373984768
|
||||
last_time_down=1373984818
|
||||
last_time_unreachable=1373984748
|
||||
last_notification=0
|
||||
next_notification=0
|
||||
no_more_notifications=1
|
||||
current_notification_number=0
|
||||
current_down_notification_number=0
|
||||
current_unreachable_notification_number=0
|
||||
current_notification_id=0
|
||||
notifications_enabled={{NOTIFICATIONS_ENABLED}}
|
||||
problem_has_been_acknowledged={{ACKNOWLEDGED}}
|
||||
acknowledgement_type=0
|
||||
acknowledgement_end_time=0
|
||||
active_checks_enabled={{ACTIVE_ENABLED}}
|
||||
passive_checks_enabled={{PASSIVE_ENABLED}}
|
||||
event_handler_enabled=1
|
||||
flap_detection_enabled=1
|
||||
failure_prediction_enabled=1
|
||||
process_performance_data=1
|
||||
obsess_over_host=1
|
||||
last_update=1374002209
|
||||
is_flapping={{FLAPPING}}
|
||||
percent_state_change=0.00
|
||||
scheduled_downtime_depth={{IN_DOWNTIME}}
|
||||
{{CVS}}
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $SERIVCE =<<<'EOF'
|
||||
servicestatus {
|
||||
host_name={{HOST_NAME}}
|
||||
service_description={{SERVICE_NAME}}
|
||||
modified_attributes=0
|
||||
check_command=check_service!critical
|
||||
check_period=24x7
|
||||
notification_period=24x7
|
||||
check_interval=5.000000
|
||||
retry_interval=2.000000
|
||||
event_handler=
|
||||
has_been_checked=1
|
||||
should_be_scheduled=1
|
||||
check_execution_time=0.250
|
||||
check_latency=0.113
|
||||
check_type=0
|
||||
current_state={{SERVICE_STATUS}}
|
||||
last_hard_state=2
|
||||
last_event_id=0
|
||||
current_event_id=6179
|
||||
current_problem_id=2434
|
||||
last_problem_id=0
|
||||
current_attempt=3
|
||||
max_attempts=3
|
||||
state_type=1
|
||||
last_state_change={{TIME}}
|
||||
last_hard_state_change={{TIME}}
|
||||
last_time_ok=0
|
||||
last_time_warning=0
|
||||
last_time_unknown=0
|
||||
last_time_critical=1373024663
|
||||
plugin_output=Plugin output for service {{SERVICE_NAME}}
|
||||
long_plugin_output=Long plugin output for service {{SERVICE_NAME}}
|
||||
performance_data=runtime=0.012226
|
||||
last_check=1373087666
|
||||
next_check=1374002401
|
||||
check_options=0
|
||||
current_notification_number=0
|
||||
current_warning_notification_number=0
|
||||
current_critical_notification_number=0
|
||||
current_unknown_notification_number=0
|
||||
current_notification_id=0
|
||||
last_notification=0
|
||||
next_notification=0
|
||||
no_more_notifications=1
|
||||
notifications_enabled={{NOTIFICATIONS_ENABLED}}
|
||||
active_checks_enabled={{ACTIVE_ENABLED}}
|
||||
passive_checks_enabled={{PASSIVE_ENABLED}}
|
||||
event_handler_enabled=1
|
||||
problem_has_been_acknowledged={{ACKNOWLEDGED}}
|
||||
acknowledgement_type=1
|
||||
acknowledgement_end_time=0
|
||||
flap_detection_enabled=1
|
||||
failure_prediction_enabled=1
|
||||
process_performance_data=1
|
||||
obsess_over_service=1
|
||||
last_update=1374002209
|
||||
is_flapping={{FLAPPING}}
|
||||
percent_state_change=6.25
|
||||
scheduled_downtime_depth={{IN_DOWNTIME}}
|
||||
{{CVS}}
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $SERVICECOMMENT =<<<'EOF'
|
||||
servicecomment {
|
||||
host_name={{HOST_NAME}}
|
||||
service_description={{SERVICE_NAME}}
|
||||
entry_type=3
|
||||
comment_id={{ID}}
|
||||
source=0
|
||||
persistent=0
|
||||
entry_time={{TIME}}
|
||||
expires=0
|
||||
expire_time=0
|
||||
author={{AUTHOR}}
|
||||
comment_data={{TEXT}
|
||||
}
|
||||
EOF;
|
||||
|
||||
public static $HOSTCOMMENT =<<<'EOF'
|
||||
hostcomment {
|
||||
host_name={{HOST_NAME}}
|
||||
entry_type=3
|
||||
comment_id={{ID}}
|
||||
source=0
|
||||
persistent=0
|
||||
entry_time={{TIME}}
|
||||
expires=0
|
||||
expire_time=0
|
||||
author={{AUTHOR}}
|
||||
comment_data={{TEXT}}
|
||||
}
|
||||
EOF;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
|
||||
/**
|
||||
* Generic interface for Fixture insertion implementations
|
||||
*
|
||||
* These implementations can create Icinga-compatible Datatsources
|
||||
* from TestFixture classes and are therefore rather free in their
|
||||
* implementation
|
||||
*
|
||||
*/
|
||||
interface InsertionStrategy {
|
||||
/**
|
||||
* Tell the class to use the given ressource as the
|
||||
* connection identifier
|
||||
*
|
||||
* @param $connection A generic connection identifier,
|
||||
* the concrete class depends on the implementation
|
||||
*/
|
||||
public function setConnection($connection);
|
||||
|
||||
/**
|
||||
* Insert the passed fixture into the datasource and allow
|
||||
* the icinga backends to query it.
|
||||
*
|
||||
* @param TestFixture $fixture
|
||||
*/
|
||||
public function insert(TestFixture $fixture);
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
|
||||
/**
|
||||
* SetupStrategy implementation for MySQL based IDO-Backends
|
||||
*
|
||||
* This strategy creates a new MySQL Database and removes old ones
|
||||
* if necessary. Per default the database user is icinga_unittest:icinga_unittest
|
||||
* and the database to be created is also icinga_unittest. The user must
|
||||
* have all Privileges on the test database, so its best to create him
|
||||
* with:
|
||||
*
|
||||
* mysql -u root
|
||||
* # CREATE USER `icinga_unittest`@`localhost` IDENTIFIED BY 'icinga_unittest';
|
||||
* # CREATE DATABASE icinga_unittest;
|
||||
* # GRANT ALL PRIVILEGES ON icinga_unittest.* TO `icinga_unittest`@`localhost`
|
||||
*
|
||||
**/
|
||||
class MySQLSetupStrategy implements SetupStrategy {
|
||||
|
||||
/**
|
||||
* Tears down any existing databases and creates a new blank IDO scheme.
|
||||
*
|
||||
* The database is created according to the passed version (or using the newest version if no version is provided),
|
||||
* using the idoMySQL-%VERSION%.sql underneath the schemes folder.
|
||||
* A \PDO Connection can be provided, if not the icinga_unittest default
|
||||
* connection will be established and used.
|
||||
*
|
||||
* @param String $version An optional version to use as the db scheme
|
||||
* @param \PDO $connection An optional connection to use instead of icinga_unittest
|
||||
* @return \PDO The connection that has been created
|
||||
*
|
||||
* @throws \PDOException In case connecting to or creating the database fails
|
||||
* @throws \Exception In case of an invalid/non-existing DB scheme
|
||||
*/
|
||||
public function setup($version = null, $connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO("mysql:dbname=icinga_unittest", "icinga_unittest", "icinga_unittest");
|
||||
}
|
||||
|
||||
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$this->teardown($connection);
|
||||
|
||||
// the latest schema doesn't have a suffix, so if no version is given this one is used
|
||||
$sqlFileName = 'idoMySQL'.($version !== null ? '-'.$version : '' ).'.sql';
|
||||
$path = realpath(dirname(__FILE__).'/../schemes/'.$sqlFileName);
|
||||
if (!file_exists($path)) {
|
||||
throw new \Exception('File '.$path.' not found: Could not create scheme for IDO mysql backend '.($version ? '(version : '.$version.')' :''));
|
||||
}
|
||||
|
||||
$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
|
||||
|
||||
if ($connection->query(file_get_contents($path)) === false) {
|
||||
$error = $connection->errorInfo();;
|
||||
throw new \PDOException($error[0].' : '.$error[2]);
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all tables from the connection via DROP TABLE
|
||||
*
|
||||
* @param \PDO $connection An optional connection to use, if none is
|
||||
* given the icinga_unittest default will be used
|
||||
*
|
||||
*/
|
||||
public function teardown($connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO("mysql:dbname=icinga_unittest", "icinga_unittest", "icinga_unittest");
|
||||
}
|
||||
|
||||
$tables = $connection->query("SHOW TABLES")->fetchAll();
|
||||
foreach($tables as $table) {
|
||||
$connection->query("DROP TABLE ".$table[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
|
||||
/**
|
||||
* TestFixture insertion implementation for PDO based backends
|
||||
*
|
||||
* This class allows to create the actual IDO databases from TestFixture
|
||||
* classes using PDO.
|
||||
*
|
||||
*/
|
||||
class PDOInsertionStrategy
|
||||
{
|
||||
/**
|
||||
* Points to the (icinga) objectId of the next inserted object
|
||||
* @var int
|
||||
*/
|
||||
private $objectId = 0;
|
||||
|
||||
/**
|
||||
* The fixture that is being inserted by this object
|
||||
* @var TestFixture
|
||||
*/
|
||||
private $fixture;
|
||||
|
||||
/**
|
||||
* The database (PDO) connection to use for inserting
|
||||
* @var \PDO
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* The date format that will be used for inserting
|
||||
* date values, see @link http://php.net/manual/en/function.date.php
|
||||
* for possible values
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $datetimeFormat = "U";
|
||||
|
||||
/**
|
||||
* @see InsertionStrategy::setConnection
|
||||
*
|
||||
* @param \PDO $connection The PDO connection to use
|
||||
*/
|
||||
public function setConnection($connection) {
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the provided @see TestFixture into this database
|
||||
*
|
||||
* @param TestFixture $fixture The fixture to insert into the database
|
||||
*/
|
||||
public function insert(TestFixture $fixture)
|
||||
{
|
||||
$this->fixture = $fixture;
|
||||
|
||||
$this->insertContacts();
|
||||
|
||||
$this->insertHosts();
|
||||
$this->insertServices();
|
||||
$this->insertComments();
|
||||
|
||||
$this->insertHostgroups();
|
||||
$this->insertServicegroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all hosts from the current fixture into the IDO Database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_hosts, icinga_hoststatus
|
||||
* and icinga_customvariablestatus tables with the host values provided
|
||||
* by the internal fixture (@see PDOInsertStrategy::insert)
|
||||
*
|
||||
*/
|
||||
private function insertHosts()
|
||||
{
|
||||
$hosts = $this->fixture->getHosts();
|
||||
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1, is_active) VALUES (?, 1, ?, 1);'
|
||||
);
|
||||
$insertHostQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hosts ('.
|
||||
'host_id, alias, display_name, address, host_object_id, '.
|
||||
'icon_image, notes_url, action_url'.
|
||||
') VALUES (?, ?, ?, ?, ?, ?, ?, ?);'
|
||||
);
|
||||
$insertContactQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_host_contacts (host_id, contact_object_id) VALUES (?, ?);'
|
||||
);
|
||||
$insertHostStatusQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hoststatus'.
|
||||
'(host_object_id, current_state, last_check, last_state_change, notifications_enabled, '.
|
||||
'active_checks_enabled, passive_checks_enabled, is_flapping, scheduled_downtime_depth,'.
|
||||
'output, long_output, '.
|
||||
'problem_has_been_acknowledged, has_been_checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$insertCVQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_customvariablestatus'.
|
||||
'(object_id, varname, varvalue) VALUES (?, ?, ?)'
|
||||
);
|
||||
foreach($hosts as &$host) {
|
||||
$flags = $host["flags"];
|
||||
|
||||
$insertObjectQuery->execute(array($this->objectId, $host["name"]));
|
||||
$insertHostQuery->execute(array(
|
||||
$this->objectId, $host["name"]." alias", $host["name"], $host["address"], $this->objectId,
|
||||
$host["icon_image"], $host["notes_url"], $host["action_url"]
|
||||
));
|
||||
$insertHostStatusQuery->execute(array(
|
||||
$this->objectId, $host["state"], date($this->datetimeFormat, $flags->time),
|
||||
date($this->datetimeFormat, $flags->time), $flags->notifications, $flags->active_checks,
|
||||
$flags->passive_checks, $flags->flapping, $flags->in_downtime, "Plugin output for host ".$host["name"],
|
||||
"Long plugin output for host ".$host["name"], $flags->acknowledged, $flags->is_pending == 0
|
||||
));
|
||||
|
||||
foreach($host["contacts"] as $contact) {
|
||||
$insertContactQuery->execute(array($this->objectId, $contact["object_id"]));
|
||||
}
|
||||
foreach($host["customvariables"] as $cvName=>$cvValue) {
|
||||
$insertCVQuery->execute(array($this->objectId, $cvName, $cvValue));
|
||||
}
|
||||
|
||||
$host["object_id"] = $this->objectId;
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all services from the provided fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_services, icinga_servicestatus,
|
||||
* icinga_service_contacts, icinga_customvariablestatus
|
||||
*/
|
||||
private function insertServices()
|
||||
{
|
||||
$services = $this->fixture->getServices();
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1, name2, is_active) VALUES (?, 2, ?, ?, 1);'
|
||||
);
|
||||
$insertServiceQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_services ('.
|
||||
'service_id, host_object_id, service_object_id, display_name, '.
|
||||
'icon_image, notes_url, action_url'.
|
||||
') VALUES (?, ?, ?, ?, ?, ?, ?)'
|
||||
);
|
||||
$insertServiceStatusQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_servicestatus'.
|
||||
'(service_object_id, current_state, last_check, last_state_change, notifications_enabled, '.
|
||||
'active_checks_enabled, passive_checks_enabled, is_flapping, scheduled_downtime_depth,'.
|
||||
'output, long_output, '.
|
||||
'problem_has_been_acknowledged, has_been_checked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '
|
||||
);
|
||||
$insertContactQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_service_contacts (host_id, contact_object_id) VALUES (?, ?);'
|
||||
);
|
||||
$insertCVQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_customvariablestatus '.
|
||||
'(object_id, varname, varvalue) VALUES (?, ?, ?)'
|
||||
);
|
||||
|
||||
foreach($services as &$service) {
|
||||
$flags = $service["flags"];
|
||||
|
||||
$insertObjectQuery->execute(array($this->objectId, $service["host"]["name"], $service["name"]));
|
||||
$insertServiceQuery->execute(array(
|
||||
$this->objectId, $service['host']['object_id'], $this->objectId, $service['name'],
|
||||
$service["icon_image"], $service["notes_url"], $service["action_url"]
|
||||
));
|
||||
$insertServiceStatusQuery->execute(array(
|
||||
$this->objectId, $service["state"], date($this->datetimeFormat, $flags->time),
|
||||
date($this->datetimeFormat, $flags->time), $flags->notifications, $flags->active_checks,
|
||||
$flags->passive_checks, $flags->flapping, $flags->in_downtime, "Plugin output for service ".$service["name"],
|
||||
"Long plugin output for service ".$service["name"], $flags->acknowledged,
|
||||
$flags->is_pending == 0 ? '1' : '0'
|
||||
));
|
||||
|
||||
foreach($service["contacts"] as $contact) {
|
||||
$insertContactQuery->execute(array($this->objectId, $contact["object_id"]));
|
||||
}
|
||||
|
||||
foreach($service["customvariables"] as $cvName=>$cvValue) {
|
||||
$insertCVQuery->execute(array($this->objectId, $cvName, $cvValue));
|
||||
}
|
||||
|
||||
$service["object_id"] = $this->objectId;
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the contacts provided by the fixture into the database
|
||||
*
|
||||
* This method updates the icinga_objects and icinga_contacts tables
|
||||
* according to the provided fixture
|
||||
*/
|
||||
private function insertContacts()
|
||||
{
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1) VALUES (?, 10, ?);'
|
||||
);
|
||||
$insertContactQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_contacts (contact_object_id, alias) VALUES (?, ?);'
|
||||
);
|
||||
$contacts = $this->fixture->getContacts();
|
||||
foreach($contacts as &$contact) {
|
||||
$insertObjectQuery->execute($this->objectId, $contact["alias"]);
|
||||
$insertContactQuery->execute($this->objectId, $contact["alias"]);
|
||||
$contact["object_id"] = $this->objectId;
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert comments provided by the fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_comments table according to the provided
|
||||
* fixture
|
||||
*/
|
||||
private function insertComments()
|
||||
{ $comment_id=0;
|
||||
$insertCommentsQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_comments (object_id, comment_type, internal_comment_id, author_name, comment_data)'.
|
||||
' VALUES (?, ?, ?, ?, ?);'
|
||||
);
|
||||
$comments = $this->fixture->getComments();
|
||||
foreach ($comments as $comment) {
|
||||
if (isset($comment["host"])) {
|
||||
$type = 1;
|
||||
$object_id = $comment["host"]["object_id"];
|
||||
} elseif (isset($comment["service"])) {
|
||||
$type = 2;
|
||||
$object_id = $comment["service"]["object_id"];
|
||||
}
|
||||
$insertCommentsQuery->execute(array(
|
||||
$object_id, $type, $comment_id++, $comment["author"], $comment["text"]
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert hostgroups from the provided fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_hostgroups and icinga_hostgroup_members
|
||||
* table with the values provide by the fixture
|
||||
*/
|
||||
private function insertHostgroups()
|
||||
{
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1) VALUES (?, 3, ?)'
|
||||
);
|
||||
$insertHostgroupQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hostgroups (hostgroup_id, hostgroup_object_id, alias) VALUES (?, ?, ?)'
|
||||
);
|
||||
$insertHostgroupMemberQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_hostgroup_members (hostgroup_id, host_object_id) VALUES (?, ?)'
|
||||
);
|
||||
$hostgroups = $this->fixture->getHostgroups();
|
||||
|
||||
foreach ($hostgroups as &$hostgroup) {
|
||||
$insertObjectQuery->execute(array($this->objectId, $hostgroup["name"]));
|
||||
$insertHostgroupQuery->execute(array($this->objectId, $this->objectId, $hostgroup["name"]));
|
||||
foreach ($hostgroup["members"] as $member) {
|
||||
$insertHostgroupMemberQuery->execute(array($this->objectId, $member["object_id"]));
|
||||
}
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert servicegroups from the provided fixture into the IDO database
|
||||
*
|
||||
* This method updates the icinga_objects, icinga_servicegroups and icinga_servicegroup_members
|
||||
* table with the values provide by the fixture
|
||||
*/
|
||||
private function insertServicegroups()
|
||||
{
|
||||
$insertObjectQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_objects (object_id, objecttype_id, name1) VALUES (?, 4, ?)'
|
||||
);
|
||||
$insertServicegroupQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_servicegroups (servicegroup_id, servicegroup_object_id, alias) VALUES (?, ?, ?)'
|
||||
);
|
||||
$insertServicegroupMemberQuery = $this->connection->prepare(
|
||||
'INSERT INTO icinga_servicegroup_members (servicegroup_id, service_object_id) VALUES (?, ?)'
|
||||
);
|
||||
$servicegroups = $this->fixture->getServicegroups();
|
||||
|
||||
foreach ($servicegroups as &$servicegroup) {
|
||||
$insertObjectQuery->execute(array($this->objectId, $servicegroup["name"]));
|
||||
$insertServicegroupQuery->execute(array($this->objectId, $this->objectId, $servicegroup["name"]));
|
||||
foreach ($servicegroup["members"] as $member) {
|
||||
$insertServicegroupMemberQuery->execute(array($this->objectId, $member["object_id"]));
|
||||
}
|
||||
$this->objectId++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
|
||||
/***
|
||||
* SetupStrategy implementation for PostgreSQL based IDO-Backends
|
||||
*
|
||||
* This strategy creates a new PostgreSQL Database and removes old ones
|
||||
* if necessary. Per default the database user is icinga_unittest:icinga_unittest
|
||||
* and the database to be created is also icinga_unittest.
|
||||
**/
|
||||
class PgSQLSetupStrategy implements SetupStrategy {
|
||||
|
||||
/**
|
||||
* Tears down any existing databases and creates a new blank IDO scheme.
|
||||
*
|
||||
* The database is created according to the passed version (or using the
|
||||
* newest version if no version is provided), using the idoPgSQL-%VERSION%.sql
|
||||
* underneath the schemes folder.
|
||||
* A \PDO Connection can be provided, if not the icinga_unittest default
|
||||
* connection will be established and used.
|
||||
*
|
||||
* @param String $version An optional version to use as the db scheme
|
||||
* @param \PDO $connection An optional connection to use instead of icinga_unittest
|
||||
* @return \PDO The connection that has been created
|
||||
*
|
||||
* @throws \PDOException In case connecting to or creating the database fails
|
||||
* @throws \Exception In case of an invalid/non-existing DB scheme
|
||||
*/
|
||||
public function setup($version = null, $connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO('pgsql:dbname=icinga_unittest', 'icinga_unittest', 'icinga_unittest');
|
||||
}
|
||||
|
||||
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
$this->teardown($connection);
|
||||
|
||||
// the latest schema doesn't have a suffix, so if no version is given this one is used
|
||||
$sqlFileName = 'idoPgSQL'.($version !== null ? '-'.$version : '' ).'.sql';
|
||||
$path = realpath(dirname(__FILE__).'/../schemes/'.$sqlFileName);
|
||||
if (!file_exists($path)) {
|
||||
throw new \Exception('File '.$path.' not found: Could not create scheme for IDO pgsql backend '.($version ? '(version : '.$version.')' :''));
|
||||
}
|
||||
$connection->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
|
||||
|
||||
if ($connection->query(file_get_contents($path)) === false) {
|
||||
$error = $connection->errorInfo();;
|
||||
throw new \PDOException($error[0].' : '.$error[2]);
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drops all tables from the connection via DROP TABLE
|
||||
*
|
||||
* @param \PDO $connection An optional connection to use, if none is
|
||||
* given the icinga_unittest default will be used
|
||||
*
|
||||
*/
|
||||
public function teardown($connection = null)
|
||||
{
|
||||
if ($connection === null) {
|
||||
$connection = new \PDO('pgsql:dbname=icinga_unittest', 'icinga_unittest', 'icinga_unittest');
|
||||
}
|
||||
$tables = $connection
|
||||
->query('SELECT table_schema,table_name FROM information_schema.tables WHERE table_type = \'BASE TABLE\''.
|
||||
'AND table_schema = \'public\' ORDER BY table_schema,table_name;')
|
||||
->fetchAll();
|
||||
|
||||
foreach($tables as $table) {
|
||||
$connection->query('DROP TABLE '.$table['table_name']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
/**
|
||||
* Interface for setup classes that provide a clean starting point
|
||||
* for @see InsertionStrategy classes to setup TestFixtures.
|
||||
*
|
||||
* As the backend for the setupstrategy can be anything from a database to
|
||||
* a file to a socket, the resource is a mixed php type and the
|
||||
* concrete requirement on the type is defined by the subclass implementing
|
||||
* this interface.
|
||||
*
|
||||
*/
|
||||
interface SetupStrategy {
|
||||
|
||||
/**
|
||||
* Set up a new clean datastore icinga backends can use for querying data
|
||||
*
|
||||
* The resource parameter should be optional, as the setup class should provide
|
||||
* a default setup method most testing setups can use
|
||||
*
|
||||
* @param String $version The optional version of the storage implementation to create
|
||||
* @param mixed $resource The optional resource to use for setting up the storage
|
||||
*
|
||||
* @return mixed The connection or resource that has been created
|
||||
*/
|
||||
public function setup($version = null, $resource = null);
|
||||
|
||||
/**
|
||||
* Remove all data from the given resource (or the default resource if none is given)
|
||||
*
|
||||
* @param mixed $resource
|
||||
*/
|
||||
public function teardown($resource = null);
|
||||
}
|
|
@ -1,320 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
use Test\Monitoring\Testlib\DataSource\schemes\ObjectsCacheTemplates;
|
||||
use \Test\Monitoring\Testlib\DataSource\TestFixture;
|
||||
use \Test\Monitoring\Testlib\DataSource\schemes\StatusdatTemplates;
|
||||
|
||||
require_once(dirname(__FILE__).'/../schemes/ObjectsCacheTemplates.php');
|
||||
require_once(dirname(__FILE__).'/../schemes/StatusdatTemplates.php');
|
||||
|
||||
/**
|
||||
* An @see InsertionStrategy for creating status.dat and objects.cache
|
||||
* files from a TestFixture
|
||||
*
|
||||
* This class helps testing status.dat backends by writing testfixtures
|
||||
* to according objects.cache and status.dat files which then can be read
|
||||
* by the Statusdat parser and used in tests.
|
||||
*
|
||||
* The Templates for insertion can be found under schemes/objectsCacheTemplates.php
|
||||
* and schemes/StatusdatTempaltes.php
|
||||
*
|
||||
*/
|
||||
class StatusdatInsertionStrategy implements InsertionStrategy {
|
||||
|
||||
/**
|
||||
* The status.dat filename to write the object-state to
|
||||
* @var String
|
||||
*/
|
||||
private $statusDatFile;
|
||||
|
||||
/**
|
||||
* The objects.cache filename to write the object structure to
|
||||
* @var String
|
||||
*/
|
||||
private $objectsCacheFile;
|
||||
|
||||
/**
|
||||
* The TestFixture that will be written to a status.dat compatible format
|
||||
* @var TestFixture
|
||||
*/
|
||||
private $fixture;
|
||||
|
||||
/**
|
||||
* The content of the status.dat file that will be written
|
||||
* @var String
|
||||
*/
|
||||
private $statusDat;
|
||||
|
||||
/**
|
||||
* The content of the objects.cache file that will be written
|
||||
* @var String
|
||||
*/
|
||||
private $objectsCache;
|
||||
|
||||
/**
|
||||
* Tell this object to use the status.dat/objects.cache file combination
|
||||
* provided in $resource
|
||||
*
|
||||
* @param Array $ressource An associative array containing the following keys:
|
||||
* - "status_file" : The location where to write the status.dat to
|
||||
* - "objects_file" : The location to write the objects cache to
|
||||
*/
|
||||
public function setConnection($ressource)
|
||||
{
|
||||
$this->statusDatFile = $ressource['status_file'];
|
||||
$this->objectsCacheFile = $ressource['object_file'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the provided fixture into the status.dat and objects.cache files for testing
|
||||
*
|
||||
* @param TestFixture $fixture The fixture to create status.dat and objects.cache files from
|
||||
*/
|
||||
public function insert(TestFixture $fixture)
|
||||
{
|
||||
$this->fixture = $fixture;
|
||||
$this->statusDat = '# Automatically created test statusdat from fixture\n';
|
||||
$this->objectsCache = '';
|
||||
$this->insertHoststatus();
|
||||
$this->insertHosts();
|
||||
$this->insertServicestatus();
|
||||
$this->insertServices();
|
||||
|
||||
$this->insertHostgroups();
|
||||
$this->insertServicegroups();
|
||||
$this->insertComments();
|
||||
|
||||
file_put_contents($this->statusDatFile, $this->statusDat);
|
||||
file_put_contents($this->objectsCacheFile, $this->objectsCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the host monitoring state from the provided fixture to the internal
|
||||
* statusdat string $statusDat
|
||||
*
|
||||
*/
|
||||
private function insertHoststatus()
|
||||
{
|
||||
$hosts = $this->fixture->getHosts();
|
||||
foreach ($hosts as $host) {
|
||||
$cvs = '';
|
||||
foreach ($host['customvariables'] as $name=>$var) {
|
||||
$cvs .= '_'.$name.'='.$var."\n";
|
||||
}
|
||||
$flags = $host['flags'];
|
||||
$hostStatus = str_replace(
|
||||
array(
|
||||
'{{HOST_NAME}}', '{{TIME}}', '{{NOTIFICATIONS_ENABLED}}',
|
||||
'{{ACKNOWLEDGED}}', '{{ACTIVE_ENABLED}}', '{{PASSIVE_ENABLED}}',
|
||||
'{{FLAPPING}}', '{{IN_DOWNTIME}}', '{{HOST_STATUS}}','{{CVS}}')
|
||||
, array(
|
||||
$host['name'], $flags->time, $flags->notifications, $flags->acknowledged,
|
||||
$flags->active_checks, $flags->passive_checks, $flags->flapping,
|
||||
$flags->in_downtime, $host['state'], $cvs
|
||||
), StatusdatTemplates::$HOST);
|
||||
$this->statusDat .= "\n".$hostStatus;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the host object state into the internal objects.cache representation
|
||||
* $objectsCache
|
||||
*
|
||||
*/
|
||||
private function insertHosts()
|
||||
{
|
||||
$hosts = $this->fixture->getHosts();
|
||||
foreach ($hosts as $host) {
|
||||
if ($host['flags']->is_pending) {
|
||||
continue; // Pending states are not written to status.dat yet
|
||||
}
|
||||
$hostDefinition = str_replace(
|
||||
array('\t',
|
||||
'{{HOST_NAME}}', '{{HOST_ADDRESS}}', '{{ICON_IMAGE}}',
|
||||
'{{NOTES_URL}}', '{{ACTION_URL}}'
|
||||
),
|
||||
array("\t",
|
||||
$host['name'], $host['address'], $host['icon_image'],
|
||||
$host['notes_url'], $host['action_url']
|
||||
),
|
||||
ObjectsCacheTemplates::$HOST
|
||||
);
|
||||
$this->objectsCache .= "\n".$hostDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the service monitoring state from the provided fixture to the internal
|
||||
* statusdat string $statusDat
|
||||
*
|
||||
*/
|
||||
private function insertServicestatus()
|
||||
{
|
||||
$services = $this->fixture->getServices();
|
||||
foreach ($services as $service) {
|
||||
if ($service['flags']->is_pending) {
|
||||
continue; // Pending states are not written to status.dat yet
|
||||
}
|
||||
$cvs = '';
|
||||
foreach ($service['customvariables'] as $name=>$var) {
|
||||
$cvs .= '_'.$name.'='.$var;
|
||||
}
|
||||
|
||||
$flags = $service['flags'];
|
||||
$serviceStatus = str_replace(
|
||||
array(
|
||||
'{{HOST_NAME}}','{{SERVICE_NAME}}', '{{TIME}}', '{{NOTIFICATIONS_ENABLED}}',
|
||||
'{{ACKNOWLEDGED}}', '{{ACTIVE_ENABLED}}', '{{PASSIVE_ENABLED}}',
|
||||
'{{FLAPPING}}', '{{IN_DOWNTIME}}', '{{SERVICE_STATUS}}','{{CVS}}')
|
||||
, array(
|
||||
$service['host']['name'], $service['name'], $flags->time, $flags->notifications,
|
||||
$flags->acknowledged, $flags->active_checks, $flags->passive_checks,
|
||||
$flags->flapping, $flags->in_downtime, $service['state'], $cvs
|
||||
), StatusdatTemplates::$SERIVCE);
|
||||
|
||||
$this->statusDat .= "\n".$serviceStatus;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the service object state into the internal objects.cache representation
|
||||
* $objectsCache
|
||||
*
|
||||
*/
|
||||
private function insertServices()
|
||||
{
|
||||
$services = $this->fixture->getServices();
|
||||
foreach ($services as $service) {
|
||||
$serviceDefinition = str_replace(
|
||||
array('\t',
|
||||
'{{HOST_NAME}}', '{{SERVICE_NAME}}', '{{ICON_IMAGE}}',
|
||||
'{{NOTES_URL}}', '{{ACTION_URL}}'
|
||||
),
|
||||
array("\t",
|
||||
$service['host']['name'], $service['name'], $service['icon_image'],
|
||||
$service['notes_url'], $service['action_url']
|
||||
),
|
||||
ObjectsCacheTemplates::$SERVICE
|
||||
);
|
||||
$this->objectsCache .= "\n".$serviceDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a group object into the object.cache file
|
||||
*
|
||||
* @param String $type The type of the group ('host' or 'service')
|
||||
* @param String $name The name of the group to insert
|
||||
* @param array $members A String array of the members names to use
|
||||
*/
|
||||
private function insertGroup($type, $name, array $members)
|
||||
{
|
||||
$groupDefinition = str_replace(
|
||||
array('\t',
|
||||
'{{TYPE}}', '{{NAME}}', '{{MEMBERS}}'
|
||||
),
|
||||
array("\t",
|
||||
$type, $name, implode(",", $members)
|
||||
),
|
||||
ObjectsCacheTemplates::$GROUP
|
||||
);
|
||||
$this->objectsCache .= "\n".$groupDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert all hostgroups from the fixtures into the objects.cache
|
||||
*
|
||||
*/
|
||||
private function insertHostgroups()
|
||||
{
|
||||
$hostgroups = $this->fixture->getHostgroups();
|
||||
foreach ($hostgroups as $hostgroup) {
|
||||
$memberNames = array();
|
||||
foreach ($hostgroup["members"] as $member) {
|
||||
$memberNames[] = $member["name"];
|
||||
}
|
||||
$this->insertGroup("host", $hostgroup["name"], $memberNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all servicegroups from the fixtures into the objects.cache
|
||||
*
|
||||
*/
|
||||
private function insertServicegroups()
|
||||
{
|
||||
$servicegroups = $this->fixture->getServicegroups();
|
||||
foreach ($servicegroups as $servicegroup) {
|
||||
$memberNames = array();
|
||||
foreach ($servicegroup["members"] as $member) {
|
||||
$memberNames[] = $member["host"]["name"];
|
||||
$memberNames[] = $member["name"];
|
||||
}
|
||||
$this->insertGroup("service", $servicegroup["name"], $memberNames);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all comments from the fixtures into the status.dat string
|
||||
* $statusDat
|
||||
*
|
||||
*/
|
||||
private function insertComments()
|
||||
{
|
||||
$comments = $this->fixture->getComments();
|
||||
$commentId = 1;
|
||||
foreach($comments as $comment) {
|
||||
if (isset($comment["service"])) {
|
||||
$service = $comment["service"];
|
||||
$commentDefinition = str_replace(
|
||||
array('{{HOST_NAME}}', '{{SERVICE_NAME}}', '{{TIME}}', '{{AUTHOR}}', '{{TEXT}}', '{{ID}}'),
|
||||
array(
|
||||
$service["host"]["name"], $service["name"], $service["flags"]->time,
|
||||
$comment["author"], $comment["text"], $commentId++
|
||||
),
|
||||
StatusdatTemplates::$SERVICECOMMENT
|
||||
);
|
||||
} elseif (isset($comment["host"])) {
|
||||
$host = $comment["host"];
|
||||
$commentDefinition = str_replace(
|
||||
array('{{HOST_NAME}}', '{{TIME}}', '{{AUTHOR}}', '{{TEXT}}', '{{ID}}'),
|
||||
array(
|
||||
$host["name"], $host["flags"]->time,
|
||||
$comment["author"], $comment["text"], $commentId++
|
||||
),
|
||||
StatusdatTemplates::$HOSTCOMMENT
|
||||
);
|
||||
}
|
||||
$this->statusDat .= "\n".$commentDefinition;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Monitoring\Testlib\Datasource\Strategies;
|
||||
|
||||
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
|
||||
/**
|
||||
* SetupStrategy for status dat.
|
||||
*
|
||||
* This class is used for setting up a test enviromnent for querying
|
||||
* statusdat fixtures.
|
||||
*
|
||||
*/
|
||||
class StatusdatSetupStrategy implements SetupStrategy {
|
||||
|
||||
/**
|
||||
* Recursively require all php files underneath $folder
|
||||
*
|
||||
* @param String $folder The folder to require
|
||||
*/
|
||||
private function requireFolder($folder)
|
||||
{
|
||||
$files = scandir($folder);
|
||||
foreach($files as $file) {
|
||||
if ($file[0] == ".") {
|
||||
continue;
|
||||
}
|
||||
if (is_dir($folder."/".$file)) {
|
||||
$this->requireFolder($folder."/".$file);
|
||||
} elseif (preg_match("/\.php/", $file)) {
|
||||
require_once(realpath($folder."/".$file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all classes needed to work with the status.dat Reader
|
||||
*
|
||||
* This includes the Status.dat Reader and Parser classes
|
||||
* from Icinga/PRotocol as well as a few dependencies (Logging, Zend_Cache)
|
||||
*
|
||||
*/
|
||||
private function requireStatusDat()
|
||||
{
|
||||
require_once 'library/Icinga/Protocol/Statusdat/StatusdatTestLoader.php';
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the status.dat and objects.cache files for using testfixtures
|
||||
*
|
||||
* Remove existing files for status.dat testfixtures and create new
|
||||
* (empty) files at /tmp/ when no resource is given.
|
||||
*
|
||||
* @param String $version The version to use, will be ignored
|
||||
* @param array $resource An optional associative array pointing to the
|
||||
* objects_cache and status.dat files. The keys are as following:
|
||||
* - "status_file" : Path to the status.dat to remove and recreate
|
||||
* - "objects_file" : Path to the objects.cache file to remove and recreate
|
||||
* @return array An path array (see $resource) that contains the used file paths
|
||||
*/
|
||||
public function setup($version = null, $resource = null)
|
||||
{
|
||||
if ($resource == null) {
|
||||
$resource = array(
|
||||
"status_file" => "/tmp/teststatus.dat",
|
||||
"object_file" => "/tmp/testobjects.cache"
|
||||
);
|
||||
}
|
||||
$this->requireStatusDat();
|
||||
$this->teardown($resource);
|
||||
touch($resource["status_file"]);
|
||||
touch($resource["object_file"]);
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove test status.dat and objects.cache files
|
||||
*
|
||||
* @param array $resource An optional associative array pointing to the
|
||||
* objects_cache and status.dat files. The keys are as following:
|
||||
* - "status_file" : Path to the status.dat to remove
|
||||
* - "objects_file" : Path to the objects.cache file to remove
|
||||
*/
|
||||
public function teardown($resource = null)
|
||||
{
|
||||
if ($resource == null) {
|
||||
$resource = array(
|
||||
"status_file" => "/tmp/teststatus.dat",
|
||||
"object_file" => "/tmp/testobjects.cache"
|
||||
);
|
||||
}
|
||||
if (file_exists($resource["status_file"])) {
|
||||
unlink($resource["status_file"]);
|
||||
}
|
||||
if (file_exists($resource["object_file"])) {
|
||||
unlink($resource["object_file"]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Application\Controller;
|
||||
|
||||
require 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
require 'Zend/Config.php';
|
||||
require 'Zend/Application.php';
|
||||
require 'Zend/Config/Ini.php';
|
||||
require 'Zend/Controller/Action.php';
|
||||
|
||||
require '../../library/Icinga/Exception/ProgrammingError.php';
|
||||
require '../../library/Icinga/Application/Benchmark.php';
|
||||
require '../../library/Icinga/Application/Config.php';
|
||||
require '../../library/Icinga/Application/Icinga.php';
|
||||
require '../../library/Icinga/Web/Controller/ActionController.php';
|
||||
require '../../library/Icinga/Web/Notification.php';
|
||||
require '../../library/Icinga/Application/Platform.php';
|
||||
|
||||
use Icinga\Application\Icinga;
|
||||
|
||||
class IndexControllerTest extends \Zend_Test_PHPUnit_ControllerTestCase {
|
||||
private $applicationPath;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->applicationPath = realpath(__DIR__. '/../../../../application');
|
||||
|
||||
if (!defined('APPLICATION_PATH')) {
|
||||
define('APPLICATION_PATH', $this->applicationPath);
|
||||
}
|
||||
|
||||
if (!defined('APPLICATION_ENV')) {
|
||||
define('APPLICATION_ENV', 'test');
|
||||
}
|
||||
|
||||
// Assign and instantiate in one step:
|
||||
$this->bootstrap = array($this, 'appBootstrap');
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function appBootstrap()
|
||||
{
|
||||
$this->getFrontController()->setControllerDirectory($this->applicationPath. '/controllers');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
{
|
||||
$this->markTestSkipped('Static can not be detached from bootstrap');
|
||||
$this->dispatch('/index/welcome');
|
||||
$this->assertController('error');
|
||||
}
|
||||
}
|
|
@ -1,92 +1,23 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Form\Config;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
|
||||
require_once BaseTestCase::$testDir . '/library/Icinga/Web/RequestMock.php';
|
||||
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Url.php';
|
||||
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/BaseBackendForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/DbBackendForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/LdapBackendForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/Authentication/ReorderForm.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Tests\Icinga\Form\Config;
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Url;
|
||||
use \Tests\Icinga\Web\RequestMock;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Test for the authentication provider form
|
||||
*
|
||||
*/
|
||||
class AuthenticationFormTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Return a test configuration containing a database and a ldap backend
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
private function getTestConfig()
|
||||
public function setUp()
|
||||
{
|
||||
return new Zend_Config(
|
||||
array(
|
||||
'test-db' => array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => 'db_resource'
|
||||
),
|
||||
'test-ldap' => array(
|
||||
'backend' => 'ldap',
|
||||
'target' => 'user',
|
||||
'hostname' => 'test host',
|
||||
'root_dn' => 'ou=test,dc=icinga,dc=org',
|
||||
'bind_dn' => 'cn=testuser,cn=config',
|
||||
'bind_pw' => 'password',
|
||||
'user_class' => 'testClass',
|
||||
'user_name_attribute' => 'testAttribute'
|
||||
)
|
||||
)
|
||||
);
|
||||
parent::setUp();
|
||||
$this->viewMock = Mockery::mock('\Zend_View');
|
||||
$this->viewMock->shouldReceive('icon')->andReturn('');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,7 +25,6 @@ class AuthenticationFormTest extends BaseTestCase
|
|||
*/
|
||||
public function testLdapProvider()
|
||||
{
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\LdapBackendForm');
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
|
@ -127,7 +57,6 @@ class AuthenticationFormTest extends BaseTestCase
|
|||
*/
|
||||
public function testDbProvider()
|
||||
{
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\DbBackendForm');
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
|
@ -164,16 +93,13 @@ class AuthenticationFormTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test whether order modifications via 'priority' are considered
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testModifyOrder()
|
||||
{
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||
$form->setAuthenticationBackend('backend2');
|
||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
|
@ -204,17 +130,14 @@ class AuthenticationFormTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test whether the reorder form doesn't display senseless ordering (like moving the uppermost element up or
|
||||
* the lowermose down)
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
* the lowermost down)
|
||||
*/
|
||||
public function testInvalidOrderingNotShown()
|
||||
{
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||
$form->setAuthenticationBackend('backend1');
|
||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
|
|
|
@ -1,61 +1,29 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Form\Config;
|
||||
namespace Tests\Icinga\Form\Config;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
|
||||
require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/Translator.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Mockery;
|
||||
use \DOMDocument;
|
||||
use \Zend_Config;
|
||||
use \Zend_View;
|
||||
use \Zend_View_Helper_DateFormat;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class GeneralFormTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewMock = Mockery::mock('\Zend_View');
|
||||
$this->viewMock->shouldReceive('icon')->andReturn('');
|
||||
}
|
||||
|
||||
private function isHiddenElement($value, $htmlString)
|
||||
{
|
||||
$html = new DOMDocument();
|
||||
|
@ -74,13 +42,9 @@ class GeneralFormTest extends BaseTestCase
|
|||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
public function testCorrectFieldPopulation()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setConfiguration(
|
||||
|
@ -110,8 +74,10 @@ class GeneralFormTest extends BaseTestCase
|
|||
)
|
||||
);
|
||||
$form->setConfigDir('/tmp');
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$form->getValue('environment'),
|
||||
|
@ -156,8 +122,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
|
||||
public function testCorrectConditionalIniFieldRendering()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setConfiguration(
|
||||
|
@ -178,8 +142,9 @@ class GeneralFormTest extends BaseTestCase
|
|||
)
|
||||
)
|
||||
);
|
||||
$form->create();
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$view = new Zend_View();
|
||||
|
||||
$this->assertFalse(
|
||||
|
@ -194,8 +159,6 @@ class GeneralFormTest extends BaseTestCase
|
|||
|
||||
public function testCorrectConditionalDbFieldRendering()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setConfiguration(
|
||||
|
@ -217,6 +180,8 @@ class GeneralFormTest extends BaseTestCase
|
|||
)
|
||||
)
|
||||
);
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$view = new Zend_View();
|
||||
|
||||
|
|
|
@ -1,63 +1,22 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Form\Config;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Form.php';
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/GeneralForm.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Config/LoggingForm.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Tests\Icinga\Form\Config;
|
||||
|
||||
use \Zend_Config;
|
||||
Use Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Test for the authentication provider form
|
||||
*
|
||||
*/
|
||||
class LoggingFormTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Test the logging form to be correctly populated from configuration
|
||||
*
|
||||
*/
|
||||
public function testLoggingFormPopulation()
|
||||
{
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Config\LoggingForm');
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
|
@ -102,11 +61,9 @@ class LoggingFormTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test the logging form to create correct modified configurations when submit
|
||||
*
|
||||
*/
|
||||
public function testCorrectConfigCreation()
|
||||
{
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm(
|
||||
'Icinga\Form\Config\LoggingForm',
|
||||
array(
|
||||
|
|
|
@ -1,55 +1,16 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Form\Preference;
|
||||
namespace Tests\Icinga\Form\Preference;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(ICINGA_APPDIR . '/views/helpers/DateFormat.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Form/Element/Select.php';
|
||||
require_once 'Zend/View/Helper/Abstract.php';
|
||||
require_once BaseTestCase::$libDir . '/User/Preferences.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Form.php';
|
||||
require_once BaseTestCase::$appDir . '/forms/Preference/GeneralForm.php';
|
||||
require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/DateTimeFactory.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \DateTimeZone;
|
||||
use \Icinga\User\Preferences;
|
||||
use \Zend_View_Helper_DateFormat;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\User\Preferences;
|
||||
|
||||
/**
|
||||
* Test for general form, mainly testing enable/disable behaviour
|
||||
|
@ -58,12 +19,9 @@ class GeneralFormTest extends BaseTestCase
|
|||
{
|
||||
/**
|
||||
* Test whether fields using the default values have input disabled
|
||||
*
|
||||
*/
|
||||
public function testDisableFormIfUsingDefault()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setRequest($this->getRequest());
|
||||
|
@ -77,12 +35,9 @@ class GeneralFormTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test whether fields with preferences are enabled
|
||||
*
|
||||
*/
|
||||
public function testEnableFormIfUsingPreference()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
$this->requireFormLibraries();
|
||||
$form = $this->createForm('Icinga\Form\Preference\GeneralForm');
|
||||
$form->setDateFormatter(new Zend_View_Helper_DateFormat($this->getRequest()));
|
||||
$form->setRequest($this->getRequest());
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
$applicationPath = realpath(dirname(__FILE__) . '/../../application/');
|
||||
$modulePath = realpath(dirname(__FILE__) . '/../../modules/');
|
||||
$libraryPath = realpath(dirname(__FILE__) . '/../../library/');
|
||||
$testLibraryPath = realpath(dirname(__FILE__) . '/library/');
|
||||
$configPath = realpath($libraryPath . '/../config');
|
||||
|
||||
// Is usually done in the application's bootstrap and is used by some of our internals
|
||||
if (!defined('ICINGA_APPDIR')) {
|
||||
define('ICINGA_APPDIR', $applicationPath);
|
||||
}
|
||||
if (!defined('ICINGA_LIBDIR')) {
|
||||
define('ICINGA_LIBDIR', $libraryPath);
|
||||
}
|
||||
|
||||
// This is needed to get the Zend Plugin loader working
|
||||
set_include_path(implode(PATH_SEPARATOR, array($libraryPath, get_include_path())));
|
||||
|
||||
require_once 'Mockery/Loader.php';
|
||||
require_once 'Hamcrest/Hamcrest.php';
|
||||
$mockeryLoader = new \Mockery\Loader;
|
||||
$mockeryLoader->register();
|
||||
|
||||
require_once($libraryPath . '/Icinga/Application/Loader.php');
|
||||
|
||||
$loader = new Icinga\Application\Loader();
|
||||
$loader->registerNamespace('Tests', $testLibraryPath);
|
||||
$loader->registerNamespace('Icinga', $libraryPath . '/Icinga');
|
||||
$loader->registerNamespace('Icinga\\Form', $applicationPath . '/forms');
|
||||
|
||||
$modules = scandir($modulePath);
|
||||
foreach ($modules as $module) {
|
||||
if ($module === '.' || $module === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$moduleNamespace = 'Icinga\\Module\\' . ucfirst($module);
|
||||
$moduleLibraryPath = $modulePath . '/' . $module . '/library/' . ucfirst($module);
|
||||
|
||||
if (is_dir($moduleLibraryPath)) {
|
||||
$loader->registerNamespace($moduleNamespace, $moduleLibraryPath);
|
||||
}
|
||||
|
||||
$moduleTestPath = $modulePath . '/' . $module . '/test/php';
|
||||
if (is_dir($moduleTestPath)) {
|
||||
$loader->registerNamespace('Tests\\' . $moduleNamespace, $moduleTestPath);
|
||||
}
|
||||
|
||||
$moduleFormPath = $modulePath . '/' . $module . '/application/forms';
|
||||
if (is_dir($moduleFormPath)) {
|
||||
$loader->registerNamespace($moduleNamespace . '\\Form', $moduleFormPath);
|
||||
}
|
||||
}
|
||||
|
||||
$loader->register();
|
||||
|
||||
require_once 'Zend/Loader/Autoloader.php';
|
||||
\Zend_Loader_Autoloader::getInstance();
|
||||
|
||||
Icinga\Application\Config::$configDir = $configPath;
|
|
@ -1,53 +1,33 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Application/Config.php');
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
|
||||
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
class ConfigTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Set up config dir
|
||||
*
|
||||
* Utilizes singleton IcingaConfig
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->configDir = IcingaConfig::$configDir;
|
||||
IcingaConfig::$configDir = dirname(__FILE__) . '/Config/files';
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset config dir
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
IcingaConfig::$configDir = $this->configDir;
|
||||
}
|
||||
|
||||
public function testAppConfig()
|
||||
{
|
||||
$config = IcingaConfig::app();
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
require_once __DIR__. '/../../../../../library/Icinga/Exception/ProgrammingError.php';
|
||||
require_once __DIR__. '/../../../../../library/Icinga/Application/Loader.php';
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Application\Loader;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Loader
|
||||
* Created Thu, 07 Feb 2013 10:07:13 +0000
|
||||
*
|
||||
**/
|
||||
class LoaderTest extends \PHPUnit_Framework_TestCase
|
||||
class LoaderTest extends BaseTestCase
|
||||
{
|
||||
private static $classFile = 'test/My/Library/TestStruct.php';
|
||||
|
||||
|
@ -33,16 +27,18 @@ class TestStruct
|
|||
|
||||
EOD;
|
||||
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$tempDir = sys_get_temp_dir();
|
||||
$this->baseDir = tempnam($tempDir, 'icinga2-web');
|
||||
system('mkdir -p '. $this->baseDir. dirname(self::$classFile));
|
||||
file_put_contents($this->baseDir. self::$classFile, self::$classContent);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
system('rm -rf '. $this->baseDir);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,57 +1,20 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once BaseTestCase::$libDir . '/Logger/Logger.php';
|
||||
require_once BaseTestCase::$libDir . '/Logger/LogWriter.php';
|
||||
require_once BaseTestCase::$libDir . '/Logger/Writer/StreamWriter.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class LoggerTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testLogfileCreation()
|
||||
{
|
||||
$target = tempnam(sys_get_temp_dir(), 'log');
|
||||
unlink($target);
|
||||
Logger::create(
|
||||
new Logger(
|
||||
new Zend_Config(
|
||||
array(
|
||||
'enable' => true,
|
||||
|
@ -66,14 +29,13 @@ class LoggerTest extends BaseTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @backupStaticAttributes enabled
|
||||
* @depends testLogfileCreation
|
||||
*/
|
||||
public function testLoggingErrorMessages()
|
||||
{
|
||||
$target = tempnam(sys_get_temp_dir(), 'log');
|
||||
unlink($target);
|
||||
Logger::create(
|
||||
$logger = new Logger(
|
||||
new Zend_Config(
|
||||
array(
|
||||
'enable' => true,
|
||||
|
@ -83,7 +45,7 @@ class LoggerTest extends BaseTestCase
|
|||
)
|
||||
)
|
||||
);
|
||||
Logger::error('This is a test error');
|
||||
$logger->log('This is a test error', Logger::$ERROR);
|
||||
$log = file_get_contents($target);
|
||||
unlink($target);
|
||||
$this->assertContains('This is a test error', $log, 'Log does not contain the error "This is a test error"');
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Application\Module\Manager;
|
||||
|
||||
require_once("../../library/Icinga/Application/Modules/Manager.php");
|
||||
require_once("../../library/Icinga/Exception/ProgrammingError.php");
|
||||
require_once("../../library/Icinga/Exception/ConfigurationError.php");
|
||||
require_once("../../library/Icinga/Exception/SystemPermissionException.php");
|
||||
|
||||
use Icinga\Application\Modules\Manager as ModuleManager;
|
||||
|
||||
class ModuleMock
|
||||
{
|
||||
|
||||
public $name = "";
|
||||
public $dir = "";
|
||||
|
||||
public function __construct($app, $name, $dir)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->dir = $dir;
|
||||
}
|
||||
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class ManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
const MODULE_TARGET = "/tmp";
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$moduleDir = self::MODULE_TARGET;
|
||||
if (!is_writable($moduleDir)) {
|
||||
$this->markTestSkipped("Temporary folder not writable for this user");
|
||||
return;
|
||||
}
|
||||
if (is_dir($moduleDir."/enabledModules")) {
|
||||
exec("rm -r $moduleDir/enabledModules");
|
||||
}
|
||||
|
||||
mkdir($moduleDir."/enabledModules");
|
||||
}
|
||||
|
||||
public function testDetectEnabledModules()
|
||||
{
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("none"));
|
||||
$this->assertEmpty($manager->listEnabledModules());
|
||||
|
||||
symlink(getcwd()."/res/testModules/module1", "/tmp/enabledModules/module1");
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("none"));
|
||||
$this->assertEquals(array("module1"), $manager->listEnabledModules());
|
||||
symlink(getcwd()."/res/testModules/module2", "/tmp/enabledModules/module2");
|
||||
symlink(getcwd()."/res/???", "/tmp/enabledModules/module3");
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("none"));
|
||||
$this->assertEquals(array("module1", "module2"), $manager->listEnabledModules());
|
||||
}
|
||||
|
||||
public function testLoadModule()
|
||||
{
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("./res/testModules"));
|
||||
$this->assertEmpty($manager->getLoadedModules());
|
||||
$manager->loadModule("module1", "Tests\Icinga\Application\Module\Manager\ModuleMock");
|
||||
$elems = $manager->getLoadedModules();
|
||||
$this->assertNotEmpty($elems);
|
||||
$this->assertTrue(isset($elems["module1"]));
|
||||
// assert the changes not to be permanent:
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("./res/testModules"));
|
||||
$this->assertEmpty($manager->getLoadedModules());
|
||||
}
|
||||
|
||||
public function testEnableModule()
|
||||
{
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array(getcwd()."/res/testModules"));
|
||||
$this->assertEmpty($manager->listEnabledModules());
|
||||
$manager->enableModule("module1");
|
||||
$elems = $manager->listEnabledModules();
|
||||
$this->assertNotEmpty($elems);
|
||||
$this->assertEquals($elems[0], "module1");
|
||||
$this->assertTrue(is_link("/tmp/enabledModules/module1"));
|
||||
// assert the changes to be permanent:
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("./res/testModules"));
|
||||
$this->assertNotEmpty($manager->listEnabledModules());
|
||||
}
|
||||
|
||||
public function testDisableModule()
|
||||
{
|
||||
clearstatcache(true);
|
||||
symlink(getcwd()."/res/testModules/module1", "/tmp/enabledModules/module1");
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array(getcwd()."/res/testModules"));
|
||||
$elems = $manager->listEnabledModules();
|
||||
$this->assertNotEmpty($elems);
|
||||
$this->assertEquals($elems[0], "module1");
|
||||
$manager->disableModule("module1");
|
||||
$this->assertFalse(file_exists("/tmp/enabledModules/module1"));
|
||||
$this->assertEmpty($manager->listEnabledModules());
|
||||
// assert the changes to be permanent:
|
||||
$manager = new ModuleManager(null, "/tmp/enabledModules", array("./res/testModules"));
|
||||
$this->assertEmpty($manager->listEnabledModules());
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$moduleDir = self::MODULE_TARGET;
|
||||
exec("rm -r $moduleDir/enabledModules");
|
||||
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Application;
|
||||
|
||||
/**
|
||||
* Partially emulate the functionality of Zend_Db
|
||||
*/
|
||||
class ZendDbMock
|
||||
{
|
||||
|
||||
/**
|
||||
* The config that was used in the last call of the factory function
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private static $config;
|
||||
|
||||
/**
|
||||
* Name of the adapter class that was used in the last call of the factory function
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private static $adapter;
|
||||
|
||||
/**
|
||||
* Mock the factory-method of Zend_Db and save the given parameters
|
||||
*
|
||||
* @param $adapter String name of base adapter class, or Zend_Config object
|
||||
* @param $config mixed OPTIONAL; an array or Zend_Config object with adapter
|
||||
* parameters
|
||||
*
|
||||
* @return stdClass Empty object
|
||||
*/
|
||||
public static function factory($adapter, $config)
|
||||
{
|
||||
self::$config = $config;
|
||||
self::$adapter = $adapter;
|
||||
return new \stdClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the adapter class that was used in the last call
|
||||
* of the factory function
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static function getAdapter()
|
||||
{
|
||||
return self::$adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config that was used in the last call of the factory function
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getConfig()
|
||||
{
|
||||
return self::$config;
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/UserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/User.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Authentication\Credential;
|
||||
use \Icinga\Authentication\UserBackend as UserBackend;
|
||||
use \Icinga\User;
|
||||
|
||||
/**
|
||||
* Simple backend mock that takes an config object
|
||||
* with the property "credentials", which is an array
|
||||
* of Credential this backend authenticates
|
||||
**/
|
||||
class BackendMock implements UserBackend
|
||||
{
|
||||
public $allowedCredentials = array();
|
||||
public $name;
|
||||
|
||||
public function __construct(Zend_Config $config = null)
|
||||
{
|
||||
if ($config === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset ($config->credentials)) {
|
||||
$this->allowedCredentials = $config->credentials;
|
||||
}
|
||||
|
||||
if ($config->name) {
|
||||
$this->name = $config->name;
|
||||
} else {
|
||||
$this->name = 'TestBackendMock-' . uniqid();
|
||||
}
|
||||
}
|
||||
|
||||
public function hasUsername(Credential $userCredentials)
|
||||
{
|
||||
foreach ($this->allowedCredentials as $credential) {
|
||||
if ($credential->getUsername() == $userCredentials->getUsername()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public static function getDummyUser()
|
||||
{
|
||||
return new User(
|
||||
'Username',
|
||||
'Firstname',
|
||||
'Lastname',
|
||||
'user@test.local'
|
||||
);
|
||||
}
|
||||
|
||||
public function getUserCount() {
|
||||
return count($this->allowedCredentials);
|
||||
}
|
||||
|
||||
public function authenticate(Credential $credentials)
|
||||
{
|
||||
if (!in_array($credentials, $this->allowedCredentials)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return self::getDummyUser();
|
||||
}
|
||||
|
||||
public function setCredentials(array $credentials)
|
||||
{
|
||||
$this->allowedCredentials = $credentials;
|
||||
}
|
||||
|
||||
public function connect()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,316 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once 'Zend/Db/Adapter/Abstract.php';
|
||||
require_once 'Zend/Db.php';
|
||||
require_once 'Zend/Log.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/ProgrammingError.php';
|
||||
require_once BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/UserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/Protocol/Ldap/Exception.php';
|
||||
require_once BaseTestCase::$libDir . '/Application/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Backend/DbUserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/User.php';
|
||||
require_once BaseTestCase::$libDir . '/Application/Logger.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \PDO;
|
||||
use \Zend_Db_Adapter_Pdo_Abstract;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Icinga\Authentication\Credential;
|
||||
use \Icinga\User;
|
||||
use \Icinga\Application\Config;
|
||||
|
||||
/**
|
||||
* Test Class fpr DbUserBackend
|
||||
*/
|
||||
class DbUserBackendTest extends BaseTestCase
|
||||
{
|
||||
const USER_NAME_COLUMN = 'username';
|
||||
|
||||
const SALT_COLUMN = 'salt';
|
||||
|
||||
const PASSWORD_COLUMN = 'password';
|
||||
|
||||
const ACTIVE_COLUMN = 'active';
|
||||
|
||||
/**
|
||||
* The table that is used to store the authentication data
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $testTable = 'account';
|
||||
|
||||
/**
|
||||
* Example users
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $userData = array(
|
||||
array(
|
||||
self::USER_NAME_COLUMN => 'user1',
|
||||
self::PASSWORD_COLUMN => 'secret1',
|
||||
self::SALT_COLUMN => '8a7487a539c5d1d6766639d04d1ed1e6',
|
||||
self::ACTIVE_COLUMN => 1
|
||||
),
|
||||
array(
|
||||
self::USER_NAME_COLUMN => 'user2',
|
||||
self::PASSWORD_COLUMN => 'secret2',
|
||||
self::SALT_COLUMN => '04b5521ddd761b5a5b633be83faa494d',
|
||||
self::ACTIVE_COLUMN => 1
|
||||
),
|
||||
array(
|
||||
self::USER_NAME_COLUMN => 'user3',
|
||||
self::PASSWORD_COLUMN => 'secret3',
|
||||
self::SALT_COLUMN => '08bb94ba3120338ae56db80ef551d324',
|
||||
self::ACTIVE_COLUMN => 0
|
||||
)
|
||||
);
|
||||
|
||||
private function createDbBackendConfig($resource, $name = null)
|
||||
{
|
||||
if ($name === null) {
|
||||
$name = 'TestDbUserBackend-' . uniqid();
|
||||
}
|
||||
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'name' => $name,
|
||||
'resource' => $resource
|
||||
)
|
||||
);
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the authentication functions of the DbUserBackend using PostgreSQL as backend.
|
||||
*
|
||||
* @dataProvider pgsqlDb
|
||||
*/
|
||||
public function testCorrectUserLoginForPgsql($db)
|
||||
{
|
||||
$this->setupDbProvider($db);
|
||||
$backend = new DbUserBackend($this->createDbBackendConfig($db));
|
||||
$backend->connect();
|
||||
$this->runBackendAuthentication($backend);
|
||||
$this->runBackendUsername($backend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the authentication functions of the DbUserBackend using MySQL as backend.
|
||||
*
|
||||
* @dataProvider mysqlDb
|
||||
*/
|
||||
public function testCorrectUserLoginForMySQL($db)
|
||||
{
|
||||
$this->setupDbProvider($db);
|
||||
$backend = new DbUserBackend($this->createDbBackendConfig($db));
|
||||
$backend->connect();
|
||||
$this->runBackendAuthentication($backend);
|
||||
$this->runBackendUsername($backend);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Zend_Db_Adapter_Pdo_Abstract $resource
|
||||
*/
|
||||
public function setupDbProvider($resource)
|
||||
{
|
||||
parent::setupDbProvider($resource);
|
||||
|
||||
$type = $resource->getConnection()->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
|
||||
$dumpFile = BaseTestCase::$etcDir . '/schema/accounts.' . $type . '.sql';
|
||||
|
||||
$this->assertFileExists($dumpFile);
|
||||
|
||||
$this->loadSql($resource, $dumpFile);
|
||||
|
||||
for ($i = 0; $i < count($this->userData); $i++) {
|
||||
$usr = $this->userData[$i];
|
||||
$data = array(
|
||||
self::USER_NAME_COLUMN => $usr[self::USER_NAME_COLUMN],
|
||||
self::PASSWORD_COLUMN => hash_hmac(
|
||||
'sha256',
|
||||
$usr[self::PASSWORD_COLUMN],
|
||||
$usr[self::SALT_COLUMN]
|
||||
),
|
||||
self::ACTIVE_COLUMN => $usr[self::ACTIVE_COLUMN],
|
||||
self::SALT_COLUMN => $usr[self::SALT_COLUMN]
|
||||
);
|
||||
$resource->insert($this->testTable, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the hasUsername test against an instance of DbUserBackend
|
||||
*
|
||||
* @param DbUserBackend $backend The backend that will be tested.
|
||||
*/
|
||||
private function runBackendUsername($backend)
|
||||
{
|
||||
// Known user
|
||||
$this->assertTrue(
|
||||
$backend->hasUsername(
|
||||
new Credential(
|
||||
$this->userData[0][self::USER_NAME_COLUMN],
|
||||
$this->userData[0][self::PASSWORD_COLUMN]
|
||||
)
|
||||
),
|
||||
'Assert that the user is known by the backend'
|
||||
);
|
||||
|
||||
// Unknown user
|
||||
$this->assertFalse(
|
||||
$backend->hasUsername(
|
||||
new Credential(
|
||||
'unknown user',
|
||||
'secret'
|
||||
)
|
||||
),
|
||||
'Assert that the user is not known by the backend'
|
||||
);
|
||||
|
||||
// Inactive user
|
||||
$this->assertFalse(
|
||||
$backend->hasUsername(
|
||||
new Credential(
|
||||
$this->userData[2][self::USER_NAME_COLUMN],
|
||||
$this->userData[2][self::PASSWORD_COLUMN]
|
||||
)
|
||||
),
|
||||
'Assert that the user is inactive and therefore not known by the backend'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the authentication test against an instance of DbUserBackend
|
||||
*
|
||||
* @param DbUserBackend $backend The backend that will be tested.
|
||||
*/
|
||||
private function runBackendAuthentication($backend)
|
||||
{
|
||||
// Known user
|
||||
$this->assertNotNull(
|
||||
$backend->authenticate(
|
||||
new Credential(
|
||||
$this->userData[0][self::USER_NAME_COLUMN],
|
||||
$this->userData[0][self::PASSWORD_COLUMN]
|
||||
)
|
||||
),
|
||||
'Assert that an existing, active user with the right credentials can authenticate.'
|
||||
);
|
||||
|
||||
// Wrong password
|
||||
$this->assertNull(
|
||||
$backend->authenticate(
|
||||
new Credential(
|
||||
$this->userData[1][self::USER_NAME_COLUMN],
|
||||
'wrongpassword'
|
||||
)
|
||||
),
|
||||
'Assert that an existing user with an invalid password cannot authenticate'
|
||||
);
|
||||
|
||||
// Nonexisting user
|
||||
$this->assertNull(
|
||||
$backend->authenticate(
|
||||
new Credential(
|
||||
'nonexisting user',
|
||||
$this->userData[1][self::PASSWORD_COLUMN]
|
||||
)
|
||||
),
|
||||
'Assert that a non-existing user cannot authenticate.'
|
||||
);
|
||||
|
||||
// Inactive user
|
||||
$this->assertNull(
|
||||
$backend->authenticate(
|
||||
new Credential(
|
||||
$this->userData[2][self::USER_NAME_COLUMN],
|
||||
$this->userData[2][self::PASSWORD_COLUMN]
|
||||
)
|
||||
),
|
||||
'Assert that an inactive user cannot authenticate.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mysqlDb
|
||||
*/
|
||||
public function testBackendNameAssignment($db)
|
||||
{
|
||||
$this->setupDbProvider($db);
|
||||
|
||||
$testName = 'test-name-123123';
|
||||
$backend = new DbUserBackend($this->createDbBackendConfig($db, $testName));
|
||||
$backend->connect();
|
||||
$this->assertSame($testName, $backend->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mysqlDb
|
||||
*/
|
||||
public function testCountUsersMySql($db)
|
||||
{
|
||||
$this->setupDbProvider($db);
|
||||
$testName = 'test-name-123123';
|
||||
$backend = new DbUserBackend($this->createDbBackendConfig($db, $testName));
|
||||
$backend->connect();
|
||||
|
||||
$this->assertGreaterThan(0, $backend->getUserCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider pgsqlDb
|
||||
*/
|
||||
public function testCountUsersPgSql($db)
|
||||
{
|
||||
$this->setupDbProvider($db);
|
||||
$testName = 'test-name-123123';
|
||||
$backend = new DbUserBackend($this->createDbBackendConfig($db, $testName));
|
||||
$backend->connect();
|
||||
|
||||
$this->assertGreaterThan(0, $backend->getUserCount());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,132 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/UserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/User.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Authentication\Credential;
|
||||
use \Icinga\Authentication\UserBackend as UserBackend;
|
||||
use \Icinga\User;
|
||||
|
||||
/**
|
||||
* Simple backend mock that takes an config object
|
||||
* with the property "credentials", which is an array
|
||||
* of Credential this backend authenticates
|
||||
**/
|
||||
class ErrorProneBackendMock implements UserBackend
|
||||
{
|
||||
public static $throwOnCreate = false;
|
||||
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Creates a new object
|
||||
*
|
||||
* @param Zend_Config $config
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __construct(Zend_Config $config)
|
||||
{
|
||||
if (self::$throwOnCreate === true) {
|
||||
throw new Exception('__construct error: Could not create');
|
||||
}
|
||||
|
||||
if ($config->name) {
|
||||
$this->name = $config->name;
|
||||
} else {
|
||||
$this->name = 'TestBackendErrorProneMock-' . uniqid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the username exists
|
||||
*
|
||||
* @param Credential $credentials
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public function hasUsername(Credential $credentials)
|
||||
{
|
||||
throw new Exception('hasUsername error: ' . $credentials->getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @param Credential $credentials
|
||||
*
|
||||
* @return User
|
||||
* @throws Exception
|
||||
*/
|
||||
public function authenticate(Credential $credentials)
|
||||
{
|
||||
throw new Exception('authenticate error: ' . $credentials->getUsername());
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the backend
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of users available through this backend
|
||||
*
|
||||
* @return int
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getUserCount()
|
||||
{
|
||||
throw new Exception('getUserCount error: No users in this error prone backend');
|
||||
}
|
||||
|
||||
public function connect()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -1,233 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Authentication\Credential;
|
||||
use \Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Protocol/Ldap/Connection.php';
|
||||
require_once BaseTestCase::$libDir . '/Protocol/Ldap/Query.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/UserBackend.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Backend/LdapUserBackend.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use Icinga\Protocol\Ldap\Connection as LdapConnection;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Ldapuserbackend
|
||||
* Created Mon, 10 Jun 2013 07:54:34 +0000
|
||||
*
|
||||
**/
|
||||
class LdapUserBackendTest extends BaseTestCase
|
||||
{
|
||||
// Change this according to your ldap test server
|
||||
const ADMIN_DN = 'cn=admin,dc=icinga,dc=org';
|
||||
const ADMIN_PASS = 'admin';
|
||||
|
||||
private $users = array(
|
||||
'cn=Richard Miles,ou=icinga-unittest,dc=icinga,dc=org' => array(
|
||||
'cn' => 'Richard Miles',
|
||||
'sn' => 'Miles',
|
||||
'objectclass' => 'inetOrgPerson',
|
||||
'givenName' => 'Richard',
|
||||
'mail' => 'richard@doe.local',
|
||||
'uid' => 'rmiles',
|
||||
'userPassword' => 'passrmiles'
|
||||
),
|
||||
'cn=Jane Woe,ou=icinga-unittest,dc=icinga,dc=org' => array(
|
||||
'cn' => 'Jane Woe',
|
||||
'sn' => 'Woe',
|
||||
'objectclass' => 'inetOrgPerson',
|
||||
'givenName' => 'Jane',
|
||||
'mail' => 'jane@woe.local',
|
||||
'uid' => 'jwoe',
|
||||
'userPassword' => 'passjwoe'
|
||||
)
|
||||
);
|
||||
|
||||
private $baseOu = array(
|
||||
'ou=icinga-unittest,dc=icinga,dc=org' => array(
|
||||
'objectclass' => 'organizationalUnit',
|
||||
'ou' => 'icinga-unittest'
|
||||
)
|
||||
);
|
||||
|
||||
private function getLDAPConnection()
|
||||
{
|
||||
$ldapConn = ldap_connect('localhost', 389);
|
||||
|
||||
if (!$ldapConn) {
|
||||
$this->markTestSkipped('Could not connect to test-ldap server, skipping test');
|
||||
}
|
||||
$bind = @ldap_bind($ldapConn, self::ADMIN_DN, self::ADMIN_PASS);
|
||||
|
||||
if (!$bind) {
|
||||
$this->markTestSkipped('Could not bind to test-ldap server, skipping test');
|
||||
}
|
||||
|
||||
return $ldapConn;
|
||||
}
|
||||
|
||||
private function clearTestData($connection)
|
||||
{
|
||||
foreach ($this->users as $ou => $info) {
|
||||
@ldap_delete($connection, $ou);
|
||||
}
|
||||
|
||||
foreach ($this->baseOu as $ou => $info) {
|
||||
@ldap_delete($connection, $ou);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertTestdata($connection)
|
||||
{
|
||||
foreach ($this->baseOu as $ou => $info) {
|
||||
if (ldap_add($connection, $ou, $info) === false) {
|
||||
$this->markTestSkipped('Couldn\'t set up test-ldap users, skipping test');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->users as $ou => $info) {
|
||||
if (ldap_add($connection, $ou, $info) === false) {
|
||||
$this->markTestSkipped('Couldn\'t set up test-ldap users, skipping test');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$conn = $this->getLDAPConnection();
|
||||
$this->clearTestData($conn);
|
||||
$this->insertTestData($conn);
|
||||
|
||||
$result = ldap_list($conn, 'ou=icinga-unittest, dc=icinga, dc=org', '(cn=Richard Miles)');
|
||||
|
||||
if (ldap_count_entries($conn, $result) < 1) {
|
||||
$this->markTestSkipped('Couldn\'t set up test users, skipping test');
|
||||
}
|
||||
|
||||
$result = ldap_list($conn, 'ou=icinga-unittest, dc=icinga, dc=org', '(cn=Jane Woe)');
|
||||
|
||||
if (ldap_count_entries($conn, $result) < 1) {
|
||||
$this->markTestSkipped('Couldn\'t set up test users, skipping test');
|
||||
}
|
||||
|
||||
ldap_close($conn);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$conn = $this->getLDAPConnection();
|
||||
|
||||
// $this->clearTestData($conn);
|
||||
ldap_close($conn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a backend config and initialise the LdapConnection to the testing backend manually,
|
||||
* to prevent the LdapUserBackend from calling the unitialised ResourceFactory
|
||||
*
|
||||
* @return Zend_Config The authentication backend configuration
|
||||
*/
|
||||
private function createBackendConfig()
|
||||
{
|
||||
$resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'hostname' => 'localhost',
|
||||
'root_dn' => 'ou=icinga-unittest,dc=icinga,dc=org',
|
||||
'bind_dn' => 'cn=admin,cn=config',
|
||||
'bind_pw' => 'admin'
|
||||
)
|
||||
);
|
||||
$backendConfig = new Zend_Config(
|
||||
array(
|
||||
'resource' => new LdapConnection($resourceConfig),
|
||||
'target' => 'user',
|
||||
'user_class' => 'inetOrgPerson',
|
||||
'user_name_attribute' => 'uid'
|
||||
)
|
||||
);
|
||||
return $backendConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LdapUserBackend::HasUsername()
|
||||
**/
|
||||
public function testHasUsername()
|
||||
{
|
||||
$backend = new LdapUserBackend($this->createBackendConfig());
|
||||
$this->assertTrue($backend->hasUsername(new Credential('jwoe')));
|
||||
$this->assertTrue($backend->hasUsername(new Credential('rmiles')));
|
||||
$this->assertFalse($backend->hasUsername(new Credential('DoesNotExist')));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for LdapUserBackend::Authenticate()
|
||||
*/
|
||||
public function testAuthenticate()
|
||||
{
|
||||
$backend = new LdapUserBackend($this->createBackendConfig());
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'\Icinga\User',
|
||||
$backend->authenticate(new Credential('jwoe', 'passjwoe'))
|
||||
);
|
||||
|
||||
$this->assertNull($backend->authenticate(new Credential('jwoe', 'passjwoe22')));
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'\Icinga\User',
|
||||
$backend->authenticate(new Credential('rmiles', 'passrmiles'))
|
||||
);
|
||||
|
||||
$this->assertNull($backend->authenticate(new Credential('rmiles', 'passrmiles33')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Cannot fetch single DN for
|
||||
*/
|
||||
public function testAuthenticateUnknownUser()
|
||||
{
|
||||
$backend = new LdapUserBackend($this->createBackendConfig());
|
||||
$this->assertFalse($backend->authenticate(new Credential('unknown123', 'passunknown123')));
|
||||
}
|
||||
}
|
|
@ -1,358 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once 'Zend/Log.php';
|
||||
require_once 'Zend/Config.php';
|
||||
require_once BaseTestCase::$libDir . '/Logger/Logger.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Manager.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Membership.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Credential.php';
|
||||
require_once BaseTestCase::$libDir . '/Authentication/Membership.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/ConfigurationError.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/ProgrammingError.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/NotReadableError.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Session.php';
|
||||
require_once 'BackendMock.php';
|
||||
require_once 'ErrorProneBackendMock.php';
|
||||
require_once 'SessionMock.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Authentication\Manager as AuthManager;
|
||||
use Icinga\Authentication\Credential;
|
||||
use Icinga\Exception\ConfigurationError;
|
||||
|
||||
/**
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class ManagerTest extends BaseTestCase
|
||||
{
|
||||
public function getTestCredentials()
|
||||
{
|
||||
return array(
|
||||
new Credential("jdoe", "passjdoe"),
|
||||
new Credential("root", "passroot"),
|
||||
new Credential("test", "passtest")
|
||||
);
|
||||
}
|
||||
|
||||
public function getManagerInstance(
|
||||
&$session = null,
|
||||
$write = false,
|
||||
$nobackend = false,
|
||||
Zend_Config $managerConfig = null
|
||||
) {
|
||||
if ($session == null) {
|
||||
$session = new SessionMock();
|
||||
}
|
||||
|
||||
if ($managerConfig === null) {
|
||||
$managerConfig = new Zend_Config(array());
|
||||
}
|
||||
|
||||
Session::create($session);
|
||||
$manager = AuthManager::getInstance($managerConfig);
|
||||
|
||||
if ($nobackend === false) {
|
||||
$backend = new BackendMock();
|
||||
$backend->allowedCredentials = $this->getTestCredentials();
|
||||
$manager->addUserBackend($backend);
|
||||
}
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
public function testManagerInstanciation()
|
||||
{
|
||||
$authMgr = $this->getManagerInstance();
|
||||
$this->assertSame($authMgr, AuthManager::getInstance());
|
||||
}
|
||||
|
||||
public function testManagerProducingDependencies()
|
||||
{
|
||||
$authMgr = $this->getManagerInstance($session, true);
|
||||
$this->assertSame($authMgr, AuthManager::getInstance());
|
||||
|
||||
$backend = new BackendMock();
|
||||
$backend->setCredentials($this->getTestCredentials());
|
||||
|
||||
$authMgr->addUserBackend($backend);
|
||||
|
||||
$this->assertTrue(
|
||||
$authMgr->authenticate(
|
||||
new Credential('jdoe', 'passjdoe')
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf('Icinga\User', $authMgr->getUser());
|
||||
$this->assertSame('Username', $authMgr->getUser()->getUsername());
|
||||
|
||||
$session->isOpen = true;
|
||||
$authMgr->removeAuthorization();
|
||||
|
||||
$this->assertNull($authMgr->getUser());
|
||||
}
|
||||
|
||||
public function testAuthentication()
|
||||
{
|
||||
$auth = $this->getManagerInstance();
|
||||
$this->assertFalse(
|
||||
$auth->authenticate(
|
||||
new Credential("jhoe", "passjdoe"),
|
||||
false
|
||||
)
|
||||
);
|
||||
$this->assertFalse(
|
||||
$auth->authenticate(
|
||||
new Credential("joe", "passjhoe"),
|
||||
false
|
||||
)
|
||||
);
|
||||
$this->assertTrue(
|
||||
$auth->authenticate(
|
||||
new Credential("jdoe", "passjdoe"),
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPersistAuthInSession()
|
||||
{
|
||||
$session = new SessionMock();
|
||||
$auth = $this->getManagerInstance($session, true);
|
||||
$this->assertFalse($auth->isAuthenticated(true));
|
||||
$auth->authenticate(new Credential("jdoe", "passjdoe"));
|
||||
$this->assertNotEquals(null, $session->get("user"));
|
||||
$user = $session->get("user");
|
||||
$this->assertEquals("Username", $user->getUsername());
|
||||
$this->assertTrue($auth->isAuthenticated(true));
|
||||
}
|
||||
|
||||
public function testAuthenticateFromSession()
|
||||
{
|
||||
$session = new SessionMock();
|
||||
$session->set("user", BackendMock::getDummyUser());
|
||||
$auth = $this->getManagerInstance($session, false);
|
||||
$this->assertFalse($auth->isAuthenticated(true));
|
||||
$this->assertTrue($auth->isAuthenticated());
|
||||
$this->assertTrue($auth->isAuthenticated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Icinga\Exception\ConfigurationError
|
||||
* @expectedExceptionMessage No authentication backend set
|
||||
*/
|
||||
public function testErrorProneBackendsFromConfigurationWhenInitiate()
|
||||
{
|
||||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
ErrorProneBackendMock::$throwOnCreate = true;
|
||||
|
||||
$authManager = $this->getManagerInstance($session, true, true, $managerConfig);
|
||||
|
||||
$this->assertNull(
|
||||
$authManager->getUserBackend('provider1')
|
||||
);
|
||||
|
||||
$authManager->authenticate(
|
||||
new Credential('jdoe', 'passjdoe')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Icinga\Exception\ConfigurationError
|
||||
* @expectedExceptionMessage No working backend found. Unable to authenticate any
|
||||
*/
|
||||
public function testErrorProneBackendsFromConfigurationWhenAuthenticate()
|
||||
{
|
||||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider2' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
ErrorProneBackendMock::$throwOnCreate = false;
|
||||
|
||||
$authManager = $this->getManagerInstance($session, false, true, $managerConfig);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\ErrorProneBackendMock',
|
||||
$authManager->getUserBackend('provider1')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\ErrorProneBackendMock',
|
||||
$authManager->getUserBackend('provider2')
|
||||
);
|
||||
|
||||
$authManager->authenticate(
|
||||
new Credential('jdoe', 'passjdoe')
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthenticationChainWithGoodProviders()
|
||||
{
|
||||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\BackendMock'
|
||||
),
|
||||
'provider2' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\BackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$authManager = $this->getManagerInstance($session, true, true, $managerConfig);
|
||||
|
||||
$authManager->getUserBackend('provider1')->setCredentials(
|
||||
array(
|
||||
new Credential('p1-user1', 'p1-passwd1'),
|
||||
new Credential('p1-user2', 'p1-passwd2')
|
||||
)
|
||||
);
|
||||
|
||||
$authManager->getUserBackend('provider2')->setCredentials(
|
||||
array(
|
||||
new Credential('p2-user1', 'p2-passwd1'),
|
||||
new Credential('p2-user2', 'p2-passwd2')
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$authManager->authenticate(new Credential('p2-user2', 'p2-passwd2'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthenticationChainWithBadProviders()
|
||||
{
|
||||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider2' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider3' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\ErrorProneBackendMock'
|
||||
),
|
||||
'provider4' => array(
|
||||
'class' => 'Tests\Icinga\Authentication\BackendMock'
|
||||
)
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$authManager = $this->getManagerInstance($session, false, true, $managerConfig);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\ErrorProneBackendMock',
|
||||
$authManager->getUserBackend('provider1')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Tests\Icinga\Authentication\BackendMock',
|
||||
$authManager->getUserBackend('provider4')
|
||||
);
|
||||
|
||||
$authManager->getUserBackend('provider4')->setCredentials(
|
||||
array(
|
||||
new Credential('p4-user1', 'p4-passwd1'),
|
||||
new Credential('p4-user2', 'p4-passwd2')
|
||||
)
|
||||
);
|
||||
|
||||
$session->isOpen = true;
|
||||
|
||||
$this->assertTrue(
|
||||
$authManager->authenticate(new Credential('p4-user2', 'p4-passwd2'))
|
||||
);
|
||||
|
||||
$session->isOpen = true;
|
||||
|
||||
$this->assertTrue(
|
||||
$authManager->authenticate(new Credential('p4-user1', 'p4-passwd1'))
|
||||
);
|
||||
|
||||
$session->isOpen = true;
|
||||
|
||||
$this->assertFalse(
|
||||
$authManager->authenticate(new Credential('p4-user2', 'p4-passwd1-WRONG123123'))
|
||||
);
|
||||
}
|
||||
|
||||
public function testErrorConditionsInConfiguration()
|
||||
{
|
||||
$managerConfig = new Zend_Config(
|
||||
array(
|
||||
'provider1' => array(
|
||||
'backend' => 'db'
|
||||
),
|
||||
'provider2' => array(
|
||||
'target' => 'user'
|
||||
),
|
||||
'provider3' => array(
|
||||
'class' => 'Uhh\Ahh\WeDoNotCare123'
|
||||
)
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
$authManager = $this->getManagerInstance($session, true, true, $managerConfig);
|
||||
|
||||
$this->assertNull($authManager->getUserBackend('provider1'));
|
||||
$this->assertNull($authManager->getUserBackend('provider2'));
|
||||
$this->assertNull($authManager->getUserBackend('provider3'));
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
require_once("../../library/Icinga/Session/SessionNamespace.php");
|
||||
require_once("../../library/Icinga/Session/Session.php");
|
||||
|
||||
use Icinga\Web\Session\Session;
|
||||
|
||||
class SessionMock extends Session
|
||||
{
|
||||
public $isOpen = false;
|
||||
public $isWritten = false;
|
||||
|
||||
public function open()
|
||||
{
|
||||
if (!$this->isOpen && $this->isWritten) {
|
||||
throw new \Exception("Session write after close");
|
||||
}
|
||||
$this->isOpen = true;
|
||||
}
|
||||
|
||||
public function read($keepOpen = false)
|
||||
{
|
||||
$this->open();
|
||||
if (!$keepOpen) {
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
|
||||
public function write($keepOpen = false)
|
||||
{
|
||||
$this->open();
|
||||
if (!$keepOpen) {
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
|
||||
public function close()
|
||||
{
|
||||
$this->isOpen = false;
|
||||
$this->isWritten = true;
|
||||
}
|
||||
|
||||
public function purge()
|
||||
{
|
||||
}
|
||||
|
||||
public function refreshId()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,51 +1,13 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Chart;
|
||||
|
||||
use DOMXPath;
|
||||
use DOMDocument;
|
||||
|
||||
use \DOMXPath;
|
||||
use \DOMDocument;
|
||||
use Icinga\Chart\GridChart;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
// TODO: Use autoloader #4673
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$testDir . '/library/Icinga/LibraryLoader.php');
|
||||
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Primitive/Drawable.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Primitive/Styleable.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Primitive/Animatable.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Unit/AxisUnit.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Unit/LinearUnit.php');
|
||||
LibraryLoader::loadFolder(realpath(BaseTestCase::$libDir . '/Chart'));
|
||||
|
||||
class GraphChartTest extends BaseTestCase
|
||||
{
|
||||
|
|
|
@ -1,52 +1,13 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Chart;
|
||||
|
||||
use DOMXPath;
|
||||
use DOMDocument;
|
||||
|
||||
use Icinga\Chart\GridChart;
|
||||
use \DOMXPath;
|
||||
use \DOMDocument;
|
||||
use Icinga\Chart\PieChart;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
// TODO: Use autoloader #4673
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$testDir . '/library/Icinga/LibraryLoader.php');
|
||||
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Primitive/Drawable.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Primitive/Styleable.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Primitive/Animatable.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Unit/AxisUnit.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Chart/Unit/LinearUnit.php');
|
||||
LibraryLoader::loadFolder(realpath(BaseTestCase::$libDir . '/Chart'));
|
||||
|
||||
class PieChartTest extends BaseTestCase
|
||||
{
|
||||
|
|
|
@ -1,46 +1,15 @@
|
|||
<?php
|
||||
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\PreservingIniWriterTest;
|
||||
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Config/Ini.php';
|
||||
require_once 'Zend/Config/Writer/Ini.php';
|
||||
require_once('../../library/Icinga/Config/IniEditor.php');
|
||||
require_once('../../library/Icinga/Config/PreservingIniWriter.php');
|
||||
namespace Tests\Icinga\Config;
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Config\PreservingIniWriter;
|
||||
use Zend_Config;
|
||||
|
||||
class PreservingIniWriterTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
class PreservingIniWriterTest extends BaseTestCase
|
||||
{
|
||||
private $tmpfiles = array();
|
||||
|
||||
/**
|
||||
|
@ -48,6 +17,8 @@ class PreservingIniWriterTest extends \PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$ini =
|
||||
'
|
||||
trailing1="wert"
|
||||
|
@ -140,6 +111,7 @@ prop2="5"
|
|||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
foreach ($this->tmpfiles as $filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
|
|
|
@ -1,30 +1,5 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Filter;
|
||||
|
@ -35,20 +10,8 @@ use Icinga\Filter\Type\TextFilter;
|
|||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Filter\Domain;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/FilterAttribute.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Domain.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Type/TextFilter.php');
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class DomainTest extends BaseTestCase
|
||||
{
|
||||
|
||||
public function testDomainRecognitionInQueryString()
|
||||
{
|
||||
$domain = new Domain('host');
|
||||
|
@ -99,5 +62,4 @@ class DomainTest extends BaseTestCase
|
|||
$this->assertEquals($node->right, 'my host', 'Assert a domain to insert the value as the right side of a treenode');
|
||||
$this->assertEquals($node->operator, Node::OPERATOR_EQUALS, 'Assert the correct operator to be set in a single query');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,53 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Tests\Icinga\Filter;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
use Icinga\Filter\FilterAttribute;
|
||||
use Icinga\Filter\Filter;
|
||||
use Icinga\Filter\Type\TextFilter;
|
||||
use Icinga\Filter\Query\Node;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Filter.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/FilterAttribute.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Domain.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Query/Tree.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Filter/Type/TextFilter.php');
|
||||
|
||||
// @codingStandardsIgnoreEnd
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class FilterTest extends BaseTestCase
|
||||
{
|
||||
|
@ -77,7 +38,6 @@ class FilterTest extends BaseTestCase
|
|||
$searchEngine->getProposalsForQuery('Host name Is test and Hostname contains'),
|
||||
'Assert only proposals for the last query part being made'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public function testSingleQueryTreeCreation()
|
||||
|
@ -245,7 +205,6 @@ class FilterTest extends BaseTestCase
|
|||
->setHandledAttributes('attr5')
|
||||
);
|
||||
|
||||
|
||||
$query = 'attr1 is not \'Hans wurst\''
|
||||
. ' or attr2 contains something '
|
||||
. ' and attr3 starts with bla'
|
||||
|
@ -298,5 +257,4 @@ class FilterTest extends BaseTestCase
|
|||
'Assert the root->right->right->type node to be an OPERATOR (query :"' . $query . '")'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,80 +1,33 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Tests\Icinga\Filter;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Filter\FilterAttribute;
|
||||
use Icinga\Filter\Type\FilterType;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Domain.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/FilterAttribute.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/FilterType.php');
|
||||
|
||||
class TypeMock extends FilterType
|
||||
{
|
||||
public function isValidQuery($query)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function createTreeNode($query, $leftOperand)
|
||||
{
|
||||
$node = new Node();
|
||||
$node->left = $leftOperand;
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
public function getProposalsForQuery($query)
|
||||
{
|
||||
return $this->getOperators();
|
||||
}
|
||||
|
||||
public function getOperators()
|
||||
{
|
||||
return array('op1', 'is better than', 'is worse than');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class QueryHandlerTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$typeMock = Mockery::mock('Icinga\Filter\Type\FilterType');
|
||||
$typeMock->shouldReceive('isValidQuery')->with(Mockery::type('string'))->andReturn(true)
|
||||
->shouldReceive('getOperators')->andReturn(array('op1', 'is better than', 'is worse than'))
|
||||
->shouldReceive('getProposalsForQuery')->with(Mockery::type('string'))->andReturnUsing(
|
||||
function ($query) use ($typeMock) { return $typeMock->getOperators(); }
|
||||
)->shouldReceive('createTreeNode')->with(Mockery::type('string'), Mockery::any())->andReturnUsing(
|
||||
function ($query, $leftOperand) { $node = new Node(); $node->left = $leftOperand; return $node; }
|
||||
);
|
||||
$this->typeMock = $typeMock;
|
||||
}
|
||||
|
||||
public function testQueryHandlerSetup()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
$handler->setField('current_status');
|
||||
$handler->setHandledAttributes('State', 'Status', 'Current State');
|
||||
$this->assertTrue(
|
||||
|
@ -93,7 +46,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||
|
||||
public function testQueryProposal()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
|
||||
$handler->setField('current_status');
|
||||
$handler->setHandledAttributes('Status', 'State', 'Current State');
|
||||
|
@ -119,8 +72,7 @@ class QueryHandlerTest extends BaseTestCase
|
|||
|
||||
public function testOperatorProposal()
|
||||
{
|
||||
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
$handler->setField('current_status')
|
||||
->setHandledAttributes('status', 'state', 'current state');
|
||||
$this->assertEquals(
|
||||
|
@ -132,11 +84,10 @@ class QueryHandlerTest extends BaseTestCase
|
|||
|
||||
public function testAttributeRecognition()
|
||||
{
|
||||
$handler = new FilterAttribute(new TypeMock());
|
||||
$handler = new FilterAttribute($this->typeMock);
|
||||
$handler->setField('current_status')
|
||||
->setHandledAttributes('status', 'state', 'current state');
|
||||
$node = $handler->convertToTreeNode('status is not \’some kind of magic\'');
|
||||
$this->assertEquals($node->left, 'current_status', 'Assert status to be set to the field');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +1,15 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
|
||||
namespace Tests\Icinga\Filter;
|
||||
|
||||
use Icinga\Filter\Type\BooleanFilter;
|
||||
use Icinga\Filter\Type\TimeRangeSpecifier;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/BooleanFilter.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/TimeRangeSpecifier.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class BooleanFilterTest extends BaseTestCase
|
||||
{
|
||||
|
||||
public function testOperatorProposal()
|
||||
{
|
||||
$filter = new BooleanFilter(array());
|
||||
|
@ -124,7 +87,6 @@ class BooleanFilterTest extends BaseTestCase
|
|||
$this->assertEquals(Node::OPERATOR_EQUALS, $node->operator, 'Assert the operator to be equals');
|
||||
$this->assertEquals(1, $node->right[0], 'Assert the value to be 1');
|
||||
|
||||
|
||||
$node = $filter->createTreeNode('is not with problem', 'host_status');
|
||||
$this->assertEquals('host_problem', $node->left, 'Assert the left part of the node to be host_problem');
|
||||
$this->assertEquals(Node::OPERATOR_EQUALS, $node->operator, 'Assert the operator to be equals');
|
||||
|
@ -149,6 +111,5 @@ class BooleanFilterTest extends BaseTestCase
|
|||
$this->assertEquals('host_problem', $node->right->left, 'Assert the right part of the node to be host_problem');
|
||||
$this->assertEquals(Node::OPERATOR_EQUALS, $node->right->operator, 'Assert the operator to be equals');
|
||||
$this->assertEquals(1, $node->right->right[0], 'Assert the value to be 1');
|
||||
|
||||
}
|
||||
}
|
|
@ -1,30 +1,5 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Filter;
|
||||
|
@ -33,14 +8,6 @@ use Icinga\Filter\Type\TextFilter;
|
|||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/TextFilter.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class TextFilterTest extends BaseTestCase
|
||||
{
|
||||
public function testOperatorProposal()
|
||||
|
@ -65,13 +32,11 @@ class TextFilterTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
public function testGetOperatorAndValueFromQuery()
|
||||
{
|
||||
$textFilter = new TextFilter();
|
||||
list($operator, $value) = $textFilter->getOperatorAndValueFromQuery('is not \'something\'');
|
||||
$this->assertEquals(Node::OPERATOR_EQUALS_NOT, $operator, 'Asserting text operators to be split via TextFilter');
|
||||
$this->assertEquals('something', $value, 'Asserting quoted values to be recognized in TextFilter');
|
||||
|
||||
}
|
||||
}
|
|
@ -1,46 +1,12 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Filter;
|
||||
|
||||
use Icinga\Filter\Type\TimeRangeSpecifier;
|
||||
use Icinga\Filter\Query\Node;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Query/Node.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/QueryProposer.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/FilterType.php');
|
||||
require_once realpath(BaseTestCase::$libDir .'/Filter/Type/TimeRangeSpecifier.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
class TimeRangeSpecifierTest extends BaseTestCase
|
||||
{
|
||||
public function testIsValid()
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
namespace Test\Icinga;
|
||||
|
||||
abstract class LibraryLoader {
|
||||
|
||||
public static function getBasePath()
|
||||
{
|
||||
$path = realpath(dirname(__FILE__));
|
||||
while (!preg_match('/.*test$/', $path) && $path != '/') {
|
||||
$path = realpath($path.'/../');
|
||||
}
|
||||
return realpath($path.'/../');
|
||||
}
|
||||
|
||||
public static function getLibraryPath()
|
||||
{
|
||||
return realpath(self::getBasePath().'/library/Icinga/');
|
||||
}
|
||||
|
||||
public static function getModulePath($module = '')
|
||||
{
|
||||
return realpath(self::getBasePath().'/module/'.$module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Require all php files in the folder $folder
|
||||
*
|
||||
* @param $folder The path to the folder containing PHP files
|
||||
*/
|
||||
public static function loadFolder($folder, $recursive = true)
|
||||
{
|
||||
$files = scandir($folder);
|
||||
foreach ($files as $file) {
|
||||
if ($file[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
if ($recursive && is_dir(realpath($folder."/".$file))) {
|
||||
|
||||
self::loadFolder(realpath($folder."/".$file));
|
||||
}
|
||||
if (!preg_match('/php$/', $file)) {
|
||||
continue;
|
||||
}
|
||||
require_once(realpath($folder.'/'.$file));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be abstract but in php this should not be
|
||||
*/
|
||||
public static function requireLibrary()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
require_once('./library/Icinga/LibraryLoader.php');
|
||||
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
class CommandPipeLoader extends LibraryLoader {
|
||||
|
||||
public static function requireLibrary()
|
||||
{
|
||||
require_once('Zend/Config.php');
|
||||
require_once('Zend/Log.php');
|
||||
require_once(realpath('../../library/Icinga/Application/Logger.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Command.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Comment.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/CommandPipe.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/PropertyModifier.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Transport/Transport.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php'));
|
||||
require_once(realpath('../../library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/AddCommentCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/ScheduleDowntimeCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php'));
|
||||
require_once(realpath('../../modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php'));
|
||||
}
|
||||
}
|
|
@ -1,41 +1,13 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Commandpipe;
|
||||
|
||||
require_once(realpath(__DIR__ . '/CommandPipeLoader.php'));
|
||||
CommandPipeLoader::requireLibrary();
|
||||
|
||||
use Zend_Config;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Protocol\Commandpipe\Comment;
|
||||
use Icinga\Protocol\Commandpipe\Commandpipe as Commandpipe;
|
||||
use Icinga\Protocol\Commandpipe\CommandPipe;
|
||||
use Icinga\Protocol\Commandpipe\PropertyModifier as MONFLAG;
|
||||
use Icinga\Protocol\Ldap\Exception;
|
||||
use Icinga\Module\Monitoring\Command\AcknowledgeCommand;
|
||||
|
@ -56,7 +28,7 @@ if (!defined('EXTCMD_TEST_BIN')) {
|
|||
* Uses the helper script extcmd_test, which is basically the extracted command
|
||||
* parser functions from the icinga core
|
||||
*/
|
||||
class CommandPipeTest extends PHPUnit_Framework_TestCase
|
||||
class CommandPipeTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Return the path of the test pipe used in these tests
|
||||
|
@ -71,7 +43,7 @@ class CommandPipeTest extends PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up for the local test pipe
|
||||
*
|
||||
* @return Commandpipe
|
||||
* @return CommandPipe
|
||||
*/
|
||||
private function getLocalTestPipe()
|
||||
{
|
||||
|
@ -86,14 +58,14 @@ class CommandPipeTest extends PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
return new Commandpipe($cfg);
|
||||
return new CommandPipe($cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a @see Icinga\Protocal\CommandPipe\CommandPipe instance set up
|
||||
* for the local test pipe, but with ssh as the transport layer
|
||||
*
|
||||
* @return Commandpipe
|
||||
* @return CommandPipe
|
||||
*/
|
||||
private function getSSHTestPipe()
|
||||
{
|
||||
|
@ -112,7 +84,7 @@ class CommandPipeTest extends PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
return new Commandpipe($cfg);
|
||||
return new CommandPipe($cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Protocol\Ldap;
|
||||
require_once '../../library/Icinga/Protocol/Ldap/Query.php';
|
||||
require_once '../../library/Icinga/Protocol/Ldap/Connection.php';
|
||||
require_once '../../library/Icinga/Protocol/Ldap/LdapUtils.php';
|
||||
require_once('Zend/Config.php');
|
||||
/**
|
||||
*
|
||||
* Test class for Query
|
||||
* Created Wed, 13 Mar 2013 12:57:11 +0000
|
||||
*
|
||||
**/
|
||||
class QueryTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Protocol\Ldap\Connection;
|
||||
|
||||
class QueryTest extends BaseTestCase
|
||||
{
|
||||
private function emptySelect()
|
||||
{
|
||||
$config = new \Zend_Config(
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'hostname' => 'localhost',
|
||||
'root_dn' => 'dc=example,dc=com',
|
||||
|
@ -23,7 +21,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
$connection = new \Icinga\Protocol\Ldap\Connection($config);
|
||||
$connection = new Connection($config);
|
||||
return $connection->select();
|
||||
}
|
||||
|
||||
|
@ -39,18 +37,6 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
return $select;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Count() - shall be tested with connection
|
||||
*
|
||||
**/
|
||||
public function testCount()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Limit()
|
||||
*
|
||||
**/
|
||||
public function testLimit()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
|
@ -58,10 +44,6 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(4, $select->getOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasLimit()
|
||||
*
|
||||
**/
|
||||
public function testHasLimit()
|
||||
{
|
||||
$select = $this->emptySelect();
|
||||
|
@ -70,10 +52,6 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($select->hasLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::HasOffset()
|
||||
*
|
||||
**/
|
||||
public function testHasOffset()
|
||||
{
|
||||
$select = $this->emptySelect();
|
||||
|
@ -82,99 +60,39 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue($select->hasOffset());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetLimit()
|
||||
*
|
||||
**/
|
||||
public function testGetLimit()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertEquals(10, $select->getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetOffset()
|
||||
*
|
||||
**/
|
||||
public function testGetOffset()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$this->assertEquals(10, $select->getLimit());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchTree()
|
||||
*
|
||||
**/
|
||||
public function testFetchTree()
|
||||
{
|
||||
$this->markTestIncomplete('testFetchTree is not implemented yet - requires real LDAP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchAll() - shall be tested with connection
|
||||
*
|
||||
**/
|
||||
public function testFetchAll()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchRow() - shall be tested with connection
|
||||
*
|
||||
**/
|
||||
public function testFetchRow()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchOne()
|
||||
*
|
||||
**/
|
||||
public function testFetchOne()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::FetchPairs()
|
||||
*
|
||||
**/
|
||||
public function testFetchPairs()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::From()
|
||||
*
|
||||
**/
|
||||
public function testFrom()
|
||||
{
|
||||
return $this->testListFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Where()
|
||||
*
|
||||
**/
|
||||
public function testWhere()
|
||||
{
|
||||
$this->markTestIncomplete('testWhere is not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Order()
|
||||
*
|
||||
**/
|
||||
public function testOrder()
|
||||
{
|
||||
$select = $this->emptySelect()->order('bla');
|
||||
// tested by testGetSortColumns
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::ListFields()
|
||||
*
|
||||
**/
|
||||
public function testListFields()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
|
@ -184,10 +102,6 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::GetSortColumns()
|
||||
*
|
||||
**/
|
||||
public function testGetSortColumns()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
|
@ -195,31 +109,10 @@ class QueryTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('testIntColumn', $cols[0][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::Paginate() - requires real result
|
||||
*
|
||||
**/
|
||||
public function testPaginate()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::__toString()
|
||||
*
|
||||
**/
|
||||
public function test__toString()
|
||||
{
|
||||
$select = $this->prepareSelect();
|
||||
$res = '(&(objectClass=dummyClass)(testIntColumn=1)(testStringColumn=test)(testWildcard=abc*))';
|
||||
$this->assertEquals($res, (string) $select);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Query::__destruct()
|
||||
*
|
||||
**/
|
||||
public function test__destruct()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once("Zend/Config.php");;
|
||||
require_once("Zend/Log.php");;
|
||||
|
||||
use \Icinga\Protocol\Statusdat as SD;
|
||||
|
||||
/**
|
||||
* This is a high level test for the whole statusdat component, i.e. all parts put together
|
||||
* and called like they would be in a real situation. This should work when all isolated tests have passed.
|
||||
*/
|
||||
class StatusdatComponentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getReader() {
|
||||
require_once(dirname(__FILE__)."/../StatusdatTestLoader.php");
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
$reader = new SD\Reader(new \Zend_Config(array(
|
||||
"status_file" => dirname(__FILE__)."/status.dat",
|
||||
"object_file" => dirname(__FILE__)."/objects.cache"
|
||||
)),null,true);
|
||||
return $reader;
|
||||
}
|
||||
|
||||
public function testServicegroupFilterFromService() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('a1','b2'));
|
||||
$result = $r->select()->from("services")->where("group IN ?",$group)->getResult();
|
||||
|
||||
$this->assertCount(9, $result, 'Assert items to be returned in a servicegroup filter');
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
|
||||
public function testServicegroupFilterFromHost() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('a1','b2'));
|
||||
$result = $r->select()->from("hosts")->where("services.group IN ?",$group)->getResult();
|
||||
$this->assertCount(3, $result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
|
||||
public function testHostgroupFilterFromHost() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('exc-hostb'));
|
||||
$result = $r->select()->from("hosts")->where("group IN ?",$group)->getResult();
|
||||
$this->assertCount(3, $result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
|
||||
public function testHostgroupFilterFromService() {
|
||||
$r = $this->getReader();
|
||||
$group = array(array('exc-hostb'));
|
||||
$result = $r->select()->from("services")->where("host.group IN ?",$group)->getResult();
|
||||
|
||||
$this->assertCount(9, $result);
|
||||
foreach($result as $obj) {
|
||||
$this->assertTrue(is_object($obj));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
define servicegroup {
|
||||
servicegroup_name sv1
|
||||
alias testsv1
|
||||
members hosta,servicea1,hostb,serviceb1,hostc,servicec1
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name a1
|
||||
alias testsa1
|
||||
members hosta,servicea1
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name b2
|
||||
alias testsb2
|
||||
members hostb,serviceb2
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name sv2
|
||||
alias testsv2
|
||||
members hosta,servicea2,hostb,serviceb2,hostc,servicec2
|
||||
}
|
||||
|
||||
define hostgroup {
|
||||
hostgroup_name all-hosts
|
||||
alias All hosts
|
||||
members hosta,hostb,hostc
|
||||
}
|
||||
|
||||
define hostgroup {
|
||||
hostgroup_name exc-hostb
|
||||
alias Excluded host b
|
||||
members hosta,hostc
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name hosta
|
||||
alias hosta
|
||||
address 127.0.0.5
|
||||
parents hosta
|
||||
check_period 24x7
|
||||
check_command check-host-alive
|
||||
contact_groups admins
|
||||
notification_period workhours
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name hostb
|
||||
alias hostb
|
||||
address 127.0.0.5
|
||||
parents hostb
|
||||
check_period 24x7
|
||||
check_command check-host-alive
|
||||
contact_groups admins
|
||||
notification_period workhours
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name hostc
|
||||
alias hostc
|
||||
address 127.0.0.5
|
||||
parents hostc
|
||||
check_period 24x7
|
||||
check_command check-host-alive
|
||||
contact_groups admins
|
||||
notification_period workhours
|
||||
}
|
||||
|
||||
define service {
|
||||
host_name hosta
|
||||
service_description servicea1
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
|
||||
define service {
|
||||
host_name hosta
|
||||
service_description servicea2
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hosta
|
||||
service_description servicea3
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostb
|
||||
service_description serviceb1
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostb
|
||||
service_description serviceb2
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostb
|
||||
service_description serviceb3
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostc
|
||||
service_description servicec1
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostc
|
||||
service_description servicec2
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
||||
define service {
|
||||
host_name hostc
|
||||
service_description servicec3
|
||||
check_period 24x7
|
||||
check_command check_icinga_startup_delay
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
namespace Icinga\Protocol\Statusdat\Exceptions;
|
||||
|
||||
class ParsingException extends RuntimeException
|
||||
{
|
||||
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once(realpath("../../library/Icinga/Protocol/Statusdat/Exception/ParsingException.php"));
|
||||
require_once(realpath("../../library/Icinga/Exception/ProgrammingError.php"));
|
||||
require_once(realpath("../../library/Icinga/Protocol/Statusdat/Parser.php"));
|
||||
use Icinga\Protocol\Statusdat\Parser;
|
||||
/**
|
||||
*
|
||||
* Test class for Parser
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private function getStringAsFileHandle($string)
|
||||
{
|
||||
$maxsize = strlen($string)*2;
|
||||
$fhandle = fopen("php://memory", 'r+');
|
||||
fputs($fhandle,$string);
|
||||
rewind($fhandle);
|
||||
return $fhandle;
|
||||
}
|
||||
|
||||
public function testSimpleObjectCacheParsing()
|
||||
{
|
||||
$fd = $this->getStringAsFileHandle("
|
||||
define hostescalation {
|
||||
host_name\ttest
|
||||
key\tvalue
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name\ttest
|
||||
alias\ttest123
|
||||
}
|
||||
|
||||
define host {
|
||||
host_name\ttest2
|
||||
alias\ttest123
|
||||
}
|
||||
|
||||
define service {
|
||||
host_name\ttest
|
||||
service_description\tCurrent Users
|
||||
}
|
||||
|
||||
define servicegroup {
|
||||
servicegroup_name\tgroup
|
||||
members\ttest,Current Users
|
||||
}
|
||||
");
|
||||
$testParser = new Parser($fd);
|
||||
$testParser->parseObjectsFile();
|
||||
$state = $testParser->getRuntimeState();
|
||||
$this->assertTrue(is_array($state));
|
||||
$this->assertTrue(isset($state["host"]));
|
||||
$this->assertTrue(isset($state["service"]));
|
||||
$this->assertEquals("test",$state["host"]["test"]->host_name);
|
||||
$this->assertTrue(is_array($state["host"]["test"]->escalation));
|
||||
$this->assertTrue(isset($state["service"]["test;Current Users"]->group));
|
||||
$this->assertTrue(is_array($state["service"]["test;Current Users"]->group));
|
||||
$this->assertCount(1,$state["service"]["test;Current Users"]->group);
|
||||
$this->assertEquals("group",$state["service"]["test;Current Users"]->group[0]);
|
||||
$this->assertEquals("value",$state["host"]["test"]->escalation[0]->key);
|
||||
$this->assertEquals("test2",$state["host"]["test2"]->host_name);
|
||||
}
|
||||
|
||||
public function testRuntimeParsing()
|
||||
{
|
||||
$baseState = array(
|
||||
"host" => array(
|
||||
"test" => (object) array(
|
||||
"host_name" => "test"
|
||||
),
|
||||
"test2" => (object) array(
|
||||
"host_name" => "test2"
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"test;Current Users" => (object) array(
|
||||
"host_name" => "test",
|
||||
"service_description" => "Current Users"
|
||||
)
|
||||
)
|
||||
);
|
||||
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE1);
|
||||
|
||||
$testParser = new Parser($fd, $baseState);
|
||||
$testParser->parseRuntimeState();
|
||||
$state = $testParser->getRuntimeState();
|
||||
|
||||
$this->assertTrue(isset($state["host"]["test"]->status));
|
||||
$this->assertEquals(3,$state["host"]["test"]->status->current_state);
|
||||
|
||||
$this->assertTrue(is_array($state["host"]["test"]->comment));
|
||||
$this->assertEquals(2,count($state["host"]["test"]->comment));
|
||||
}
|
||||
|
||||
public function testOverwriteRuntime()
|
||||
{
|
||||
$baseState = array(
|
||||
"host" => array(
|
||||
"test" => (object) array(
|
||||
"host_name" => "test"
|
||||
),
|
||||
"test2" => (object) array(
|
||||
"host_name" => "test2"
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"test;Current Users" => (object) array(
|
||||
"host_name" => "test",
|
||||
"service_description" => "Current Users"
|
||||
)
|
||||
)
|
||||
);
|
||||
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE1);
|
||||
|
||||
$testParser = new Parser($fd, $baseState);
|
||||
$testParser->parseRuntimeState();
|
||||
$state = $testParser->getRuntimeState();
|
||||
|
||||
$this->assertTrue(isset($state["host"]["test"]->status));
|
||||
$this->assertEquals(3,$state["host"]["test"]->status->current_state);
|
||||
|
||||
$this->assertTrue(is_array($state["host"]["test"]->comment));
|
||||
$this->assertEquals(2,count($state["host"]["test"]->comment));
|
||||
|
||||
$fd = $this->getStringAsFileHandle(self::RUNTIME_STATE2);
|
||||
$testParser->parseRuntimeState($fd);
|
||||
$state = $testParser->getRuntimeState();
|
||||
|
||||
$this->assertTrue(isset($state["host"]["test"]->status));
|
||||
$this->assertEquals(2,$state["host"]["test"]->status->current_state);
|
||||
$this->assertTrue(is_array($state["host"]["test"]->comment));
|
||||
$this->assertEquals(3,count($state["host"]["test"]->comment));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert no errors occuring
|
||||
*/
|
||||
public function testRuntimeParsingForBigFile()
|
||||
{
|
||||
//$this->markTestSkipped('Skipped slow tests');
|
||||
$objects = fopen("./res/status/icinga.objects.cache","r");
|
||||
$status = fopen("./res/status/icinga.status.dat","r");
|
||||
$testParser = new Parser($objects);
|
||||
$testParser->parseObjectsFile();
|
||||
$testParser->parseRuntimeState($status);
|
||||
}
|
||||
|
||||
const RUNTIME_STATE1 = "
|
||||
|
||||
hoststatus {
|
||||
host_name=test
|
||||
current_state=3
|
||||
test=test123
|
||||
}
|
||||
|
||||
hoststatus {
|
||||
host_name=test2
|
||||
current_state=3
|
||||
test=test123
|
||||
}
|
||||
|
||||
servicestatus {
|
||||
host_name=test
|
||||
service_description=Current Users
|
||||
current_state=3
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value1
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value2
|
||||
}";
|
||||
const RUNTIME_STATE2 = "
|
||||
|
||||
hoststatus {
|
||||
host_name=test
|
||||
current_state=2
|
||||
test=test123
|
||||
}
|
||||
|
||||
hoststatus {
|
||||
host_name=test2
|
||||
current_state=2
|
||||
test=test123
|
||||
}
|
||||
|
||||
servicestatus {
|
||||
host_name=test
|
||||
service_description=Current Users
|
||||
current_state=2
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value14
|
||||
}
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value15
|
||||
}
|
||||
|
||||
hostcomment {
|
||||
host_name=test
|
||||
key=value24
|
||||
}";
|
||||
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat\Query;
|
||||
|
||||
require_once("../../library/Icinga/Protocol/Statusdat/Query/IQueryPart.php");
|
||||
require_once("../../library/Icinga/Protocol/Statusdat/Query/Expression.php");
|
||||
|
||||
use Icinga\Protocol\Statusdat\Query\Expression;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Expression
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ExpressionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for Expression::FromString()
|
||||
*
|
||||
**/
|
||||
public function testFromStringParsing()
|
||||
{
|
||||
$assertions = array(
|
||||
"expression > ?" => "isGreater",
|
||||
"expression >= ?" => "isGreaterEq",
|
||||
"expression <= ?" => "isLessEq",
|
||||
"expression < ?" => "isLess",
|
||||
"expression = ?" => "isEqual",
|
||||
"expression != ?" => "isNotEqual",
|
||||
"expression like ?" => "isLike",
|
||||
"expression IN ? " => "isIn"
|
||||
);
|
||||
|
||||
foreach ($assertions as $query => $callback) {
|
||||
$expression = new Expression();
|
||||
$value = array(10);
|
||||
$expression->fromString($query, $value);
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("expression", $expression->getField());
|
||||
$this->assertEquals($callback, $expression->CB);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNumericComparisons()
|
||||
{
|
||||
$assertions = array( // subarrays are (TEST,MATCHES)
|
||||
"expression < ?" => array(5, array(1, 2, 3, 4)),
|
||||
"expression <= ?" => array(5, array(1, 2, 3, 4, 5)),
|
||||
"expression >= ?" => array(5, array(5, 6, 7)),
|
||||
"expression > ?" => array(5, array(6, 7)),
|
||||
"expression = ?" => array(5, array(5)),
|
||||
"expression != ?" => array(5, array(1, 2, 3, 4, 6, 7)),
|
||||
"expression IN ?" => array(array(1, 5, 7), array(1, 5, 7))
|
||||
);
|
||||
|
||||
foreach ($assertions as $query => $test) {
|
||||
$expression = new Expression();
|
||||
|
||||
$value = array($test[0]);
|
||||
$testArray = array(
|
||||
(object)array("expression" => 1),
|
||||
(object)array("expression" => 2),
|
||||
(object)array("expression" => 3),
|
||||
(object)array("expression" => 4),
|
||||
(object)array("expression" => 5),
|
||||
(object)array("expression" => 6),
|
||||
(object)array("expression" => 7)
|
||||
);
|
||||
$expression->fromString($query, $value);
|
||||
$this->assertCount(0, $value);
|
||||
$result = $expression->filter($testArray);
|
||||
foreach ($result as $index) {
|
||||
$this->assertContains($index + 1, $test[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testNestedComparison()
|
||||
{
|
||||
|
||||
$testArray = array(
|
||||
(object)array(
|
||||
"expression" => "atest",
|
||||
"state" => (object)array("value" => 1)
|
||||
),
|
||||
(object)array(
|
||||
"expression" => "testa",
|
||||
"state" => (object)array("value" => 2)
|
||||
)
|
||||
|
||||
);
|
||||
$expression = new Expression();
|
||||
$value = array(1);
|
||||
$expression->fromString("state.value > ?", $value);
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$result = $expression->filter($testArray);
|
||||
$this->assertEquals(1, count($result));
|
||||
$this->assertEquals(2, $testArray[$result[1]]->state->value);
|
||||
}
|
||||
|
||||
public function testNestedComparisonInArray()
|
||||
{
|
||||
$testArray = array(
|
||||
(object)array(
|
||||
"expression" => "atest",
|
||||
"state" => array((object) array("test"=>"1","test2"=>1))
|
||||
),
|
||||
(object)array(
|
||||
"expression" => "testa",
|
||||
"state" => array((object) array("test"=>"2","test2"=>2))
|
||||
)
|
||||
|
||||
);
|
||||
$expression = new Expression();
|
||||
$value = array(1);
|
||||
$expression->fromString("state.test > ?", $value);
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$result = $expression->filter($testArray);
|
||||
$this->assertEquals(1, count($result));
|
||||
|
||||
}
|
||||
|
||||
public function testCountQuery()
|
||||
{
|
||||
$testArray = array(
|
||||
(object)array(
|
||||
"expression" => "atest",
|
||||
"multiple" => array("test"=>"1","test2"=>1)
|
||||
),
|
||||
(object)array(
|
||||
"expression" => "testa",
|
||||
"multiple" => array("test"=>"2","test2"=>2,"test5"=>2,"test1"=>2,"test3"=>2,"test4"=>2)
|
||||
)
|
||||
);
|
||||
$expression = new Expression();
|
||||
$value = array(2);
|
||||
$expression->fromString("COUNT{multiple} > ?", $value);
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$result = $expression->filter($testArray);
|
||||
$this->assertEquals(1, count($result));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Expression::Filter()
|
||||
*
|
||||
**/
|
||||
public function testFilter()
|
||||
{
|
||||
$this->markTestIncomplete('testFilter is not implemented yet');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,211 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat\Query;
|
||||
require_once("../../library/Icinga/Protocol/Statusdat/Query/IQueryPart.php");
|
||||
require_once("../../library/Icinga/Protocol/Statusdat/Query/Group.php");
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Group
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
use Icinga\Protocol\Statusdat as Statusdat;
|
||||
|
||||
class QueryExpressionMock implements Statusdat\Query\IQueryPart
|
||||
{
|
||||
public $rawExpression;
|
||||
public $value;
|
||||
public $filter = array();
|
||||
|
||||
public function __construct($expression = null, &$value = array())
|
||||
{
|
||||
$this->value = array_shift($value);
|
||||
$this->rawExpression = $expression;
|
||||
|
||||
}
|
||||
|
||||
public function filter(array &$base, &$idx = null)
|
||||
{
|
||||
return array_intersect(array_values($idx), array_values($this->filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional information about the query this filter belongs to
|
||||
*
|
||||
* @param $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
// TODO: Implement setQuery() method.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class GroupTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testParsingSingleCondition()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4);
|
||||
$testQuery->fromString("numeric_val >= ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(1, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
|
||||
$expression = $testQuery->getItems();
|
||||
$expression = $expression[0];
|
||||
|
||||
$this->assertEquals("numeric_val >= ?", $expression->rawExpression);
|
||||
$this->assertEquals(4, $expression->value);
|
||||
|
||||
}
|
||||
|
||||
public function testParsingSimpleAndCondition()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? AND host_name = ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("AND", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$expression1 = $items[1];
|
||||
$this->assertEquals("host_name = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("hosta", $expression1->value);
|
||||
}
|
||||
|
||||
public function testParsingSimpleORCondition()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? OR host_name = ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("OR", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$expression1 = $items[1];
|
||||
$this->assertEquals("host_name = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("hosta", $expression1->value);
|
||||
}
|
||||
|
||||
public function testParsingExplicitSubgroup()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'service1', 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? AND (service_description = ? OR host_name = ?)", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("AND", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$subgroup = $items[1];
|
||||
$this->assertInstanceOf("Icinga\Protocol\Statusdat\Query\Group", $subgroup);
|
||||
$this->assertEquals("OR", $subgroup->getType());
|
||||
$orItems = $subgroup->getItems();
|
||||
|
||||
$expression1 = $orItems[0];
|
||||
$this->assertEquals("service_description = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("service1", $expression1->value);
|
||||
|
||||
$expression2 = $orItems[1];
|
||||
$this->assertEquals("host_name = ?", $expression2->rawExpression);
|
||||
$this->assertEquals("hosta", $expression2->value);
|
||||
}
|
||||
|
||||
public function testParsingImplicitSubgroup()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$value = array(4, 'service1', 'hosta');
|
||||
$testQuery->fromString("numeric_val >= ? AND service_description = ? OR host_name = ?", $value, "Tests\Icinga\Protocol\Statusdat\Query\QueryExpressionMock");
|
||||
$this->assertCount(2, $testQuery->getItems());
|
||||
$this->assertCount(0, $value);
|
||||
$this->assertEquals("AND", $testQuery->getType());
|
||||
$items = $testQuery->getItems();
|
||||
|
||||
$expression0 = $items[0];
|
||||
$this->assertEquals("numeric_val >= ?", $expression0->rawExpression);
|
||||
$this->assertEquals(4, $expression0->value);
|
||||
|
||||
$subgroup = $items[1];
|
||||
$this->assertInstanceOf("Icinga\Protocol\Statusdat\Query\Group", $subgroup);
|
||||
$this->assertEquals("OR", $subgroup->getType());
|
||||
$orItems = $subgroup->getItems();
|
||||
|
||||
$expression1 = $orItems[0];
|
||||
$this->assertEquals("service_description = ?", $expression1->rawExpression);
|
||||
$this->assertEquals("service1", $expression1->value);
|
||||
|
||||
$expression2 = $orItems[1];
|
||||
$this->assertEquals("host_name = ?", $expression2->rawExpression);
|
||||
$this->assertEquals("hosta", $expression2->value);
|
||||
}
|
||||
|
||||
public function testAndFilter()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$testQuery->setType(Statusdat\Query\Group::TYPE_AND);
|
||||
$exp1 = new QueryExpressionMock();
|
||||
$exp1->filter = array(1, 2, 3, 4, 5, 6, 8);
|
||||
$exp2 = new QueryExpressionMock();
|
||||
$exp2->filter = array(3, 4, 8);
|
||||
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
$this->assertEquals(array(3, 4, 8), array_values($testQuery->addItem($exp1)->addItem($exp2)->filter($base)));
|
||||
|
||||
}
|
||||
|
||||
public function testOrFilter()
|
||||
{
|
||||
$testQuery = new Statusdat\Query\Group();
|
||||
$testQuery->setType(Statusdat\Query\Group::TYPE_OR);
|
||||
$exp1 = new QueryExpressionMock();
|
||||
$exp1->filter = array(1, 2, 3);
|
||||
$exp2 = new QueryExpressionMock();
|
||||
$exp2->filter = array(3, 4, 6, 8);
|
||||
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
$this->assertEquals(array(1, 2, 3, 4, 6, 8), array_values($testQuery->addItem($exp1)->addItem($exp2)->filter($base)));
|
||||
}
|
||||
|
||||
public function testCombinedFilter()
|
||||
{
|
||||
$testQuery_and = new Statusdat\Query\Group();
|
||||
$testQuery_and->setType(Statusdat\Query\Group::TYPE_AND);
|
||||
$testQuery_or = new Statusdat\Query\Group();
|
||||
$testQuery_or->setType(Statusdat\Query\Group::TYPE_OR);
|
||||
$base = array(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
$and_exp1 = new QueryExpressionMock();
|
||||
$and_exp1->filter = array(1, 2, 3, 4, 5, 6, 8);
|
||||
$and_exp2 = new QueryExpressionMock();
|
||||
$and_exp2->filter = array(3, 4, 8);
|
||||
|
||||
$or_exp1 = new QueryExpressionMock();
|
||||
$or_exp1->filter = array(1, 2, 3);
|
||||
$or_exp2 = new QueryExpressionMock();
|
||||
$or_exp2->filter = array(3, 4, 6, 8);
|
||||
$this->assertEquals(array(3, 4, 8), array_values(
|
||||
$testQuery_and
|
||||
->addItem($and_exp1)
|
||||
->addItem($and_exp2)
|
||||
->addItem($testQuery_or->addItem($or_exp1)->addItem($or_exp2))
|
||||
->filter($base))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once('../../library/Icinga/Filter/Filterable.php');
|
||||
require_once('../../library/Icinga/Data/BaseQuery.php');
|
||||
require_once('../../library/Icinga/Protocol/Statusdat/Query.php');
|
||||
require_once(dirname(__FILE__)."/ReaderMock.php");
|
||||
|
||||
use Icinga\Protocol\Statusdat as Statusdat;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Query
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class QueryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testSimpleServiceSelect()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$objects = $readerMock->getObjects();
|
||||
|
||||
$result = $query->select()->from("services")->getResult();
|
||||
$this->assertCount(count($objects["service"]), $result);
|
||||
}
|
||||
|
||||
public function testSimpleHostSelect()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$objects = $readerMock->getObjects();
|
||||
|
||||
$result = $query->from("hosts")->getResult();
|
||||
$this->assertCount(count($objects["host"]), $result);
|
||||
|
||||
}
|
||||
|
||||
public function testLimit()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
|
||||
$result = $query->from("services")->limit(2)->getResult();
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testOffset()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
|
||||
$result = $query->from("services")->limit(2, 4)->getResult();
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
}
|
||||
|
||||
public function testGroupByColumn()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = $query->from("services")->groupByColumns("numeric_val")->getResult();
|
||||
$this->assertCount(3,$result);
|
||||
foreach($result as $value) {
|
||||
$this->assertTrue(isset($value->count));
|
||||
$this->assertTrue(isset($value->columns));
|
||||
$this->assertEquals(2,$value->count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testOrderedGroupByColumn()
|
||||
{
|
||||
$readerMock = $this->getServiceTestReader();
|
||||
$objects = $readerMock->getObjects();
|
||||
$query = new Statusdat\Query($readerMock);
|
||||
$result = $query->from("services")->order('numeric_val ASC')->groupByColumns("numeric_val")->getResult();
|
||||
$this->assertCount(3,$result);
|
||||
foreach($result as $sstatus) {
|
||||
$this->assertTrue(isset($sstatus->count));
|
||||
$this->assertTrue(isset($sstatus->columns));
|
||||
$this->assertEquals(2, $sstatus->count);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function getServiceTestReader()
|
||||
{
|
||||
$readerMock = new ReaderMock(array(
|
||||
"host" => array(
|
||||
"hosta" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"numeric_val" => 0,
|
||||
"services" => array(0, 1, 2)
|
||||
),
|
||||
"hostb" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"numeric_val" => 0,
|
||||
"services" => array(3, 4, 5)
|
||||
)
|
||||
),
|
||||
"service" => array(
|
||||
"hosta;service1" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service1",
|
||||
"numeric_val" => 1
|
||||
),
|
||||
"hosta;service2" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service2",
|
||||
"numeric_val" => 3
|
||||
),
|
||||
"hosta;service3" => (object) array(
|
||||
"host_name" => "hosta",
|
||||
"service_description" => "service3",
|
||||
"numeric_val" => 2
|
||||
),
|
||||
"hostb;service1" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service1",
|
||||
"numeric_val" => 1
|
||||
),
|
||||
"hostb;service2" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service2",
|
||||
"numeric_val" => 3
|
||||
),
|
||||
"hostb;service3" => (object) array(
|
||||
"host_name" => "hostb",
|
||||
"service_description" => "service3",
|
||||
"numeric_val" => 2
|
||||
)
|
||||
)
|
||||
));
|
||||
return $readerMock;
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
require_once("../../library/Icinga/Protocol/Statusdat/IReader.php");
|
||||
require_once(realpath("../../library/Icinga/Data/DatasourceInterface.php"));
|
||||
use Icinga\Data\DatasourceInterface;
|
||||
use Icinga\Protocol\Statusdat\IReader;
|
||||
|
||||
class ReaderMock implements IReader, DatasourceInterface
|
||||
{
|
||||
private $objects;
|
||||
private $indices;
|
||||
|
||||
public function __construct(array $objects = array())
|
||||
{
|
||||
$this->objects = $objects;
|
||||
}
|
||||
|
||||
public function getState()
|
||||
{
|
||||
return $this->objects;
|
||||
}
|
||||
|
||||
public function getInternalState()
|
||||
{
|
||||
|
||||
return array(
|
||||
"objects" => $this->objects,
|
||||
"indices" => $this->indices
|
||||
);
|
||||
}
|
||||
|
||||
public function getObjects()
|
||||
{
|
||||
return $this->objects;
|
||||
}
|
||||
|
||||
public function __call($arg1,$arg2) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function select()
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectByName($type, $idx)
|
||||
{
|
||||
if (isset($this->objects[$type]) && isset($this->objects[$type][$idx]))
|
||||
return $this->objects[$type][$idx];
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
|
||||
require_once("StatusdatTestLoader.php");
|
||||
|
||||
use Icinga\Protocol\Statusdat\Reader as Reader;
|
||||
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
|
||||
if (!defined('APPLICATION_PATH')) {
|
||||
define("APPLICATION_PATH", "./"); // TODO: test boostrap
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Test class for Reader
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class ConfigMock
|
||||
{
|
||||
function __construct($data)
|
||||
{
|
||||
foreach ($data as $key => $val) {
|
||||
$this->$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
function get($attr)
|
||||
{
|
||||
return $this->$attr;
|
||||
}
|
||||
}
|
||||
|
||||
class ParserMock
|
||||
{
|
||||
|
||||
public $runtime = array();
|
||||
public $objects = array();
|
||||
|
||||
public function parseObjectsFile()
|
||||
{
|
||||
return $this->objects;
|
||||
}
|
||||
|
||||
public function parseRuntimeState()
|
||||
{
|
||||
return $this->runtime;
|
||||
}
|
||||
|
||||
public function getRuntimeState()
|
||||
{
|
||||
return $this->runtime;
|
||||
}
|
||||
}
|
||||
|
||||
class ReaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function tearDown()
|
||||
{
|
||||
if (file_exists('./tmp')) {
|
||||
@system("rm -rf ./tmp");
|
||||
}
|
||||
}
|
||||
|
||||
public function testFileCaching()
|
||||
{
|
||||
if (!file_exists('./tmp')) {
|
||||
mkdir('./tmp');
|
||||
}
|
||||
$parser = new ParserMock();
|
||||
$parser->runtime = array(
|
||||
"host" => array(
|
||||
"test" => (object)array(
|
||||
"host_name" => "test"
|
||||
)
|
||||
)
|
||||
);
|
||||
$object_file = tempnam("./dir", "object");
|
||||
$status_file = tempnam("./dir", "status");
|
||||
$reader = new Reader(new ConfigMock(array(
|
||||
"cache_path" => "/tmp",
|
||||
"object_file" => $object_file,
|
||||
"status_file" => $status_file
|
||||
)), $parser);
|
||||
unlink($object_file);
|
||||
unlink($status_file);
|
||||
$this->assertTrue(file_exists("/tmp/zend_cache---object" . md5($object_file)));
|
||||
$this->assertTrue(file_exists("/tmp/zend_cache---state" . md5($object_file)));
|
||||
system("rm /tmp/zend_cache*");
|
||||
}
|
||||
|
||||
public function testEmptyFileException()
|
||||
{
|
||||
|
||||
$this->setExpectedException("Icinga\Exception\ConfigurationError");
|
||||
$parser = new ParserMock();
|
||||
$reader = new Reader(new ConfigMock(array(
|
||||
"cache_path" => "/tmp",
|
||||
"object_file" => "",
|
||||
"status_file" => "",
|
||||
)), $parser);
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
|
||||
require_once("../../library/Icinga/Protocol/Statusdat/RuntimeStateContainer.php");
|
||||
|
||||
class RuntimestatecontainerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test for RuntimeStateContainer::__get()
|
||||
*
|
||||
**/
|
||||
public function testPropertyResolving()
|
||||
{
|
||||
|
||||
$container = new \Icinga\Protocol\Statusdat\RuntimeStateContainer("
|
||||
host_name=test host
|
||||
current_state=0
|
||||
plugin_output=test 1234 test test
|
||||
test=dont read
|
||||
");
|
||||
$container->test = "test123";
|
||||
$this->assertEquals("test host",$container->host_name);
|
||||
$this->assertEquals($container->test,"test123");
|
||||
$this->assertEquals(0,$container->current_state);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Protocol\Statusdat;
|
||||
|
||||
use Test\Icinga\LibraryLoader;
|
||||
|
||||
require_once(realpath(dirname(__FILE__) . '/../../LibraryLoader.php'));
|
||||
|
||||
class StatusdatTestLoader extends LibraryLoader
|
||||
{
|
||||
public static function requireLibrary()
|
||||
{
|
||||
$libPath = LibraryLoader::getLibraryPath();
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Cache.php';
|
||||
require_once 'Zend/Log.php';
|
||||
require_once($libPath . '/Data/BaseQuery.php');
|
||||
require_once($libPath . '/Application/Logger.php');
|
||||
require_once($libPath . '/Filter/Filterable.php');
|
||||
require_once($libPath . '/Data/DatasourceInterface.php');
|
||||
$statusdat = realpath($libPath . '/Protocol/Statusdat/');
|
||||
require_once($statusdat . '/View/AccessorStrategy.php');
|
||||
require_once($statusdat . '/PrintableObject.php');
|
||||
require_once($statusdat . '/View/MonitoringObjectList.php');
|
||||
require_once($statusdat . '/ObjectContainer.php');
|
||||
require_once($statusdat . '/IReader.php');
|
||||
require_once($statusdat . '/RuntimeStateContainer.php');
|
||||
require_once($statusdat . '/Query.php');
|
||||
require_once($statusdat . '/Parser.php');
|
||||
require_once($statusdat . '/Reader.php');
|
||||
require_once($statusdat . '/TreeToStatusdatQueryParser.php');
|
||||
require_once($statusdat . '/Exception/ParsingException.php');
|
||||
require_once($statusdat . '/Query/IQueryPart.php');
|
||||
require_once($statusdat . '/Query/Expression.php');
|
||||
require_once($statusdat . '/Query/Group.php');
|
||||
}
|
||||
}
|
|
@ -1,49 +1,10 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Authentication;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Tests\Icinga\Session;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once BaseTestCase::$libDir . '/Web/Session/SessionNamespace.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Session/Session.php';
|
||||
require_once BaseTestCase::$libDir . '/Web/Session/PhpSession.php';
|
||||
require_once BaseTestCase::$libDir . '/Logger/Logger.php';
|
||||
require_once BaseTestCase::$libDir . '/Exception/ConfigurationError.php';
|
||||
require_once 'Zend/Log.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Web\Session\PhpSession;
|
||||
|
||||
class PhpSessionTest extends BaseTestCase
|
||||
|
@ -102,7 +63,7 @@ class PhpSessionTest extends BaseTestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* Test whether session namespaces are properly written and loaded
|
||||
* Test whether session namespaces are properly written, cleared and loaded
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
|
@ -114,9 +75,45 @@ class PhpSessionTest extends BaseTestCase
|
|||
$namespace->set('an_array', array(1, 2, 3));
|
||||
$session->write();
|
||||
$session->clear();
|
||||
$this->assertFalse($session->hasNamespace('test'));
|
||||
$session->read();
|
||||
$namespace = $session->getNamespace('test');
|
||||
$this->assertEquals($namespace->get('some_key'), 'some_val');
|
||||
$this->assertEquals($namespace->get('an_array'), array(1, 2, 3));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether session values are properly removed
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testValueRemoval()
|
||||
{
|
||||
$session = $this->getSession();
|
||||
$session->set('key', 'value');
|
||||
$session->write();
|
||||
$session->delete('key');
|
||||
$session->write();
|
||||
$session->clear();
|
||||
$session->read();
|
||||
$this->assertNull($session->get('key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether session namespaces are properly removed
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testNamespaceRemoval()
|
||||
{
|
||||
$session = $this->getSession();
|
||||
$namespace = $session->getNamespace('test');
|
||||
$namespace->key = 'value';
|
||||
$session->write();
|
||||
$session->removeNamespace('test');
|
||||
$session->write();
|
||||
$session->clear();
|
||||
$session->read();
|
||||
$this->assertFalse($session->hasNamespace('test'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once BaseTestCase::$libDir . '/Web/Session/SessionNamespace.php';
|
||||
// @codingStandardsIgnoreEnd
|
||||
namespace Tests\Icinga\Session;
|
||||
|
||||
use \Exception;
|
||||
use \Mockery;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Session\SessionNamespace;
|
||||
|
||||
|
||||
class SessionNamespaceTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
|
@ -105,4 +73,39 @@ class SessionNamespaceTest extends BaseTestCase
|
|||
$ns = new SessionNamespace();
|
||||
$ns->missing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether iterating over session namespaces works
|
||||
*/
|
||||
public function testIteration()
|
||||
{
|
||||
$ns = new SessionNamespace();
|
||||
$values = array('key1' => 'val1', 'key2' => 'val2');
|
||||
$ns->setAll($values);
|
||||
foreach ($ns as $key => $value) {
|
||||
$this->assertEquals($value, $values[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage Cannot save, session not set
|
||||
*/
|
||||
public function testInvalidParentWrite()
|
||||
{
|
||||
$ns = new SessionNamespace();
|
||||
$ns->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether it is possible to write a namespace's parent
|
||||
*/
|
||||
public function testValidParentWrite()
|
||||
{
|
||||
$sessionMock = Mockery::mock('Icinga\Web\Session\Session');
|
||||
$sessionMock->shouldReceive('write')->atLeast()->times(1);
|
||||
|
||||
$ns = new SessionNamespace($sessionMock);
|
||||
$ns->write();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,70 +1,30 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Test;
|
||||
|
||||
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';
|
||||
require_once 'Zend/Db/Adapter/Pdo/Pgsql.php';
|
||||
require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
|
||||
use \PDO;
|
||||
use \RuntimeException;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class BaseTestCaseDbTest extends BaseTestCase
|
||||
{
|
||||
private $emptySqlDumpFile;
|
||||
|
||||
protected function tearDown()
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
if ($this->emptySqlDumpFile) {
|
||||
unlink($this->emptySqlDumpFile);
|
||||
}
|
||||
}
|
||||
|
||||
public function testExistingTestDirectories()
|
||||
{
|
||||
$this->assertFileExists(self::$appDir);
|
||||
$this->assertFileExists(self::$libDir);
|
||||
$this->assertFileExists(self::$etcDir);
|
||||
$this->assertFileExists(self::$testDir);
|
||||
$this->assertFileExists(self::$moduleDir);
|
||||
// $this->assertFileExists(self::$shareDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mysqlDb
|
||||
*/
|
||||
public function testMySqlProviderAnnotation($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource->getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,10 +33,10 @@ class BaseTestCaseDbTest extends BaseTestCase
|
|||
public function testMySqlCreateTablePart1($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
/** @var \Zend_Db_Adapter_Pdo_Abstract $resource **/
|
||||
$resource->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
$adapter = $resource->getConnection();
|
||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
|
||||
$tables = $resource->listTables();
|
||||
$tables = $adapter->listTables();
|
||||
$this->assertCount(1, $tables);
|
||||
}
|
||||
|
||||
|
@ -86,13 +46,12 @@ class BaseTestCaseDbTest extends BaseTestCase
|
|||
public function testMySqlCreateTablePart2($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$tables = $resource->listTables();
|
||||
$tables = $resource->getConnection()->listTables();
|
||||
$this->assertCount(0, $tables);
|
||||
}
|
||||
|
||||
private function dbAdapterSqlLoadTable($resource)
|
||||
{
|
||||
/** @var $resource \Zend_Db_Adapter_Pdo_Abstract **/
|
||||
$this->setupDbProvider($resource);
|
||||
|
||||
$sqlContent = array();
|
||||
|
@ -106,7 +65,7 @@ class BaseTestCaseDbTest extends BaseTestCase
|
|||
|
||||
$this->loadSql($resource, $tempFile);
|
||||
|
||||
$count = (int)$resource->fetchOne('SELECT COUNT(*) as cntX from dummyData;');
|
||||
$count = (int) $resource->getConnection()->fetchOne('SELECT COUNT(*) as cntX from dummyData;');
|
||||
$this->assertSame(20, $count);
|
||||
|
||||
$this->assertTrue(unlink($tempFile));
|
||||
|
@ -126,7 +85,7 @@ class BaseTestCaseDbTest extends BaseTestCase
|
|||
public function testPgSqlProviderAnnotation($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource);
|
||||
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource->getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -135,10 +94,10 @@ class BaseTestCaseDbTest extends BaseTestCase
|
|||
public function testPgSqlCreateTablePart1($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
/** @var \Zend_Db_Adapter_Pdo_Abstract $resource **/
|
||||
$resource->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
$adapter = $resource->getConnection();
|
||||
$adapter->exec('CREATE TABLE test(uid INT NOT NULL PRIMARY KEY);');
|
||||
|
||||
$tables = $resource->listTables();
|
||||
$tables = $adapter->listTables();
|
||||
$this->assertCount(1, $tables);
|
||||
}
|
||||
|
||||
|
@ -148,7 +107,7 @@ class BaseTestCaseDbTest extends BaseTestCase
|
|||
public function testPgSqlCreateTablePart2($resource)
|
||||
{
|
||||
$this->setupDbProvider($resource);
|
||||
$tables = $resource->listTables();
|
||||
$tables = $resource->getConnection()->listTables();
|
||||
$this->assertCount(0, $tables);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,66 +1,31 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga;
|
||||
|
||||
require_once __DIR__ . '/../../../../library/Icinga/User.php';
|
||||
require_once __DIR__ . '/../../../../library/Icinga/User/Preferences.php';
|
||||
|
||||
use \DateTimeZone;
|
||||
use Icinga\User as IcingaUser;
|
||||
use Icinga\User\Preferences as UserPreferences;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class UserTest extends \PHPUnit_Framework_TestCase
|
||||
class UserTest extends BaseTestCase
|
||||
{
|
||||
|
||||
public function testListGroups()
|
||||
{
|
||||
$this->markTestIncomplete('testListGroups is not implemented yet');
|
||||
}
|
||||
|
||||
public function testIsMemberOf()
|
||||
{
|
||||
$this->markTestIncomplete('testIsMemberOf is not implemented yet');
|
||||
}
|
||||
|
||||
public function testGetPermissionList()
|
||||
{
|
||||
$this->markTestIncomplete('testGetPermissionList is not implemented yet');
|
||||
}
|
||||
|
||||
public function testHasPermission()
|
||||
{
|
||||
$this->markTestIncomplete('testHasPermission is not implemented yet');
|
||||
}
|
||||
|
||||
public function testGrantPermission()
|
||||
{
|
||||
$this->markTestIncomplete('testGrantPermission is not implemented yet');
|
||||
}
|
||||
|
||||
public function testRevokePermission()
|
||||
{
|
||||
$this->markTestIncomplete('testRevokePermission is not implemented yet');
|
||||
}
|
||||
|
||||
public function testGetDefaultTimezoneIfTimezoneNotSet()
|
||||
{
|
||||
$defaultTz = 'UTC';
|
||||
date_default_timezone_set($defaultTz);
|
||||
$user = new IcingaUser('unittest');
|
||||
$prefs = new UserPreferences(array());
|
||||
$user = new User('unittest');
|
||||
$prefs = new Preferences(array());
|
||||
$user->setPreferences($prefs);
|
||||
$this->assertEquals($user->getTimeZone(), new DateTimeZone($defaultTz),
|
||||
$this->assertEquals($user->getTimeZone(), new DateTimeZone(date_default_timezone_get()),
|
||||
'User\'s timezone does not match the default timezone'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetTimezoneIfTimezoneSet()
|
||||
{
|
||||
$defaultTz = 'UTC';
|
||||
$explicitTz = 'Europe/Berlin';
|
||||
date_default_timezone_set($defaultTz);
|
||||
$user = new IcingaUser('unittest');
|
||||
$prefs = new UserPreferences(array(
|
||||
$user = new User('unittest');
|
||||
$prefs = new Preferences(array(
|
||||
'timezone' => $explicitTz
|
||||
));
|
||||
$user->setPreferences($prefs);
|
||||
|
|
|
@ -1,20 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Util;
|
||||
|
||||
require_once("../../library/Icinga/Util/Dimension.php");
|
||||
use Icinga\Util\Dimension;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Tests for the dimension class
|
||||
*
|
||||
*/
|
||||
class DimensionTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* Test Dimension creation from string
|
||||
*
|
||||
*/
|
||||
class DimensionTest extends BaseTestCase
|
||||
{
|
||||
public function testStringFactoryWithValidInput()
|
||||
{
|
||||
$d = Dimension::fromString("200px");
|
||||
|
@ -34,10 +28,6 @@ class DimensionTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals(Dimension::UNIT_PT, $d->getUnit(), "Asserting the unit of pt input to be correctly parsed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test string creation from Dimension
|
||||
*
|
||||
*/
|
||||
public function testStringCreation()
|
||||
{
|
||||
$d = new Dimension(1000, Dimension::UNIT_PX);
|
||||
|
@ -47,9 +37,6 @@ class DimensionTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertEquals("40pt", (string) $d, "Asserting float values being truncated by now");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testInvalidDimensions()
|
||||
{
|
||||
$d = new Dimension(-20, Dimension::UNIT_PX);
|
||||
|
|
|
@ -1,43 +1,20 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web\Form\Element;
|
||||
|
||||
namespace Test\Icinga\Web\Form\Element;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
|
||||
require_once 'Zend/Form/Element/Text.php';
|
||||
require_once 'Zend/Form/Element/Xhtml.php';
|
||||
require_once realpath(__DIR__ . '/../../../../../../../library/Icinga/Test/BaseTestCase.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Application/Icinga.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Web/Form/Element/DateTimePicker.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Web/Form/Validator/DateTimeValidator.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Util/ConfigAwareFactory.php');
|
||||
require_once realpath(BaseTestCase::$libDir . '/Util/DateTimeFactory.php');
|
||||
|
||||
use \DateTimeZone;
|
||||
use Icinga\Form\Config\Authentication\BaseBackendForm;
|
||||
use \Icinga\Web\Form\Element\DateTimePicker;
|
||||
use \Icinga\Util\DateTimeFactory;
|
||||
|
||||
class DateTimeTest extends BaseTestCase
|
||||
class DateTimePickerTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
// Set default timezone else new DateTime calls will die with the Exception that it's
|
||||
// not safe to rely on the system's timezone
|
||||
date_default_timezone_set('UTC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that DateTimePicker::isValid() returns false if the input is not valid in terms of being a date/time string
|
||||
* or a timestamp
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testValidateInvalidInput()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
array(
|
||||
|
@ -73,15 +50,9 @@ class DateTimeTest extends BaseTestCase
|
|||
/**
|
||||
* Test that DateTimePicker::isValid() returns true if the input is valid in terms of being a date/time string
|
||||
* or a timestamp
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testValidateValidInput()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
array(
|
||||
|
@ -112,15 +83,9 @@ class DateTimeTest extends BaseTestCase
|
|||
|
||||
/**
|
||||
* Test that DateTimePicker::getValue() returns a timestamp after a successful call to isValid
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testGetValueReturnsUnixTimestampAfterSuccessfulIsValidCall()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('UTC')));
|
||||
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
array(
|
||||
|
@ -137,33 +102,4 @@ class DateTimeTest extends BaseTestCase
|
|||
'getValue did not return the correct Unix timestamp according to the given date/time string'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that DateTimePicker::getValue() returns a timestamp respecting
|
||||
* the given non-UTC time zone after a successful call to isValid
|
||||
*
|
||||
* Utilizes singleton DateTimeFactory
|
||||
*
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
public function testGetValueIsTimeZoneAware()
|
||||
{
|
||||
DateTimeFactory::setConfig(array('timezone' => new DateTimeZone('Europe/Berlin')));
|
||||
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
array(
|
||||
'patterns' => array(
|
||||
'd.m.Y H:i:s'
|
||||
)
|
||||
)
|
||||
);
|
||||
$dt->isValid('12.07.2013 08:03:43');
|
||||
|
||||
$this->assertEquals(
|
||||
1373609023,
|
||||
$dt->getValue(),
|
||||
'getValue did not return the correct Unix timestamp according to the given date/time string and time zone'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,43 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Web\Form\Validator;
|
||||
namespace Tests\Icinga\Web\Form\Validator;
|
||||
|
||||
require_once('Zend/Validate/Abstract.php');
|
||||
require_once(realpath('../../library/Icinga/Web/Form/Validator/DateFormatValidator.php'));
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Form\Validator\DateFormatValidator;
|
||||
|
||||
use \PHPUnit_Framework_TestCase;
|
||||
use \Icinga\Web\Form\Validator\DateFormatValidator;
|
||||
|
||||
class DateFormatValidatorTest extends PHPUnit_Framework_TestCase
|
||||
class DateFormatValidatorTest extends BaseTestCase
|
||||
{
|
||||
|
||||
public function testValidateCorrectInput()
|
||||
{
|
||||
$validator = new DateFormatValidator();
|
||||
|
|
|
@ -1,43 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Web\Form\Validator;
|
||||
namespace Tests\Icinga\Web\Form\Validator;
|
||||
|
||||
require_once('Zend/Validate/Abstract.php');
|
||||
require_once(realpath('../../library/Icinga/Web/Form/Validator/TimeFormatValidator.php'));
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Form\Validator\TimeFormatValidator;
|
||||
|
||||
use \PHPUnit_Framework_TestCase;
|
||||
use \Icinga\Web\Form\Validator\TimeFormatValidator;
|
||||
|
||||
class TimeFormatValidatorTest extends PHPUnit_Framework_TestCase
|
||||
class TimeFormatValidatorTest extends BaseTestCase
|
||||
{
|
||||
|
||||
public function testValidateCorrectInput()
|
||||
{
|
||||
$validator = new TimeFormatValidator();
|
||||
|
|
|
@ -1,44 +1,14 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
*
|
||||
* Icinga Web 2 - Head for multiple monitoring backends.
|
||||
* Copyright (C) 2013 Icinga Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* @copyright 2013 Icinga Development Team <info@icinga.org>
|
||||
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
|
||||
* @author Icinga Development Team <info@icinga.org>
|
||||
*
|
||||
*/
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Test\Icinga\Web\Form\Validator;
|
||||
namespace Tests\Icinga\Web\Form\Validator;
|
||||
|
||||
require_once('Zend/Validate/Abstract.php');
|
||||
require_once(realpath('../../library/Icinga/Web/Form/Validator/WritablePathValidator.php'));
|
||||
require_once(realpath('../../library/Icinga/Application/Config.php'));
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Form\Validator\WritablePathValidator;
|
||||
|
||||
use \PHPUnit_Framework_TestCase;
|
||||
use \Icinga\Web\Form\Validator\WritablePathValidator;
|
||||
|
||||
class WritablePathValidatorTest extends PHPUnit_Framework_TestCase
|
||||
class WritablePathValidatorTest extends BaseTestCase
|
||||
{
|
||||
|
||||
public function testValidateInputWithWritablePath()
|
||||
{
|
||||
$validator = new WritablePathValidator();
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web;
|
||||
|
||||
require_once('Zend/Form.php');
|
||||
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
|
||||
|
||||
require_once('../../library/Icinga/Web/Form.php');
|
||||
require_once('../../library/Icinga/Exception/ProgrammingError.php');
|
||||
require_once('../../library/Icinga/Web/Form/InvalidCSRFTokenException.php');
|
||||
|
||||
use Icinga\Web\Form;
|
||||
use \Zend_Test_PHPUnit_ControllerTestCase;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Dummy extension class as Icinga\Web\Form is an abstract one
|
||||
|
@ -19,14 +14,13 @@ class TestForm extends Form
|
|||
{
|
||||
public function create()
|
||||
{
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the Icinga\Web\Form class (Base class for all other forms)
|
||||
*/
|
||||
class FormTest extends Zend_Test_PHPUnit_ControllerTestCase
|
||||
class FormTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Tests whether the cancel label will be added to the form
|
||||
|
|
|
@ -1,51 +1,34 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web\Hook\Configuration;
|
||||
|
||||
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTabInterface.php';
|
||||
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTab.php';
|
||||
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilder.php';
|
||||
require_once '../../library/Icinga/Web/Hook.php';
|
||||
require_once '../../library/Icinga/Web/Widget/Widget.php';
|
||||
require_once '../../library/Icinga/Web/Widget/Tabs.php';
|
||||
require_once '../../library/Icinga/Web/Widget/Tab.php';
|
||||
require_once '../../library/Icinga/Exception/ProgrammingError.php';
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Hook\Configuration\ConfigurationTab;
|
||||
use Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Web\Url;
|
||||
use Icinga\Web\Widget\Tabs;
|
||||
use PHPUnit_Framework_TestResult;
|
||||
|
||||
class RequestMock
|
||||
class ConfigurationTabBuilderTest extends BaseTestCase
|
||||
{
|
||||
public function getBaseUrl()
|
||||
{
|
||||
return "/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ConfigurationTabBuilderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Hook::clean();
|
||||
Url::$overwrittenRequest = new RequestMock();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
Hook::clean();
|
||||
Url::$overwrittenRequest = null;
|
||||
}
|
||||
|
||||
public function testDefaultTabs()
|
||||
{
|
||||
$widget = new Tabs();
|
||||
$builder = new Hook\Configuration\ConfigurationTabBuilder($widget);
|
||||
$builder = new ConfigurationTabBuilder($widget);
|
||||
|
||||
$array = $builder->build();
|
||||
$tabs = $builder->getTabs();
|
||||
|
@ -56,15 +39,15 @@ class ConfigurationTabBuilderTest extends \PHPUnit_Framework_TestCase
|
|||
public function testTabCreation1()
|
||||
{
|
||||
$widget = new Tabs();
|
||||
$builder = new Hook\Configuration\ConfigurationTabBuilder($widget);
|
||||
$builder = new ConfigurationTabBuilder($widget);
|
||||
|
||||
$tab1 = new ConfigurationTab('test1', '/test1', 'TEST1');
|
||||
$tab2 = new ConfigurationTab('test2', '/test2', 'TEST2');
|
||||
$tab3 = new ConfigurationTab('test3', '/test3', 'TEST3');
|
||||
|
||||
Hook::registerObject(Hook\Configuration\ConfigurationTabBuilder::HOOK_NAMESPACE, 'test1', $tab1);
|
||||
Hook::registerObject(Hook\Configuration\ConfigurationTabBuilder::HOOK_NAMESPACE, 'test2', $tab2);
|
||||
Hook::registerObject(Hook\Configuration\ConfigurationTabBuilder::HOOK_NAMESPACE, 'test3', $tab3);
|
||||
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'test1', $tab1);
|
||||
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'test2', $tab2);
|
||||
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'test3', $tab3);
|
||||
|
||||
$builder->build();
|
||||
|
||||
|
@ -78,10 +61,10 @@ class ConfigurationTabBuilderTest extends \PHPUnit_Framework_TestCase
|
|||
public function testTabCreation2()
|
||||
{
|
||||
$widget = new Tabs();
|
||||
$builder = new Hook\Configuration\ConfigurationTabBuilder($widget);
|
||||
$builder = new ConfigurationTabBuilder($widget);
|
||||
|
||||
$tab = new \stdClass();
|
||||
Hook::registerObject(Hook\Configuration\ConfigurationTabBuilder::HOOK_NAMESPACE, 'misc', $tab);
|
||||
$tab = Mockery::mock('Tab');
|
||||
Hook::registerObject(ConfigurationTabBuilder::HOOK_NAMESPACE, 'misc', $tab);
|
||||
$builder->build();
|
||||
|
||||
$this->assertCount(5, $builder->getTabs());
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web\Hook\Configuration;
|
||||
|
||||
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTabInterface.php';
|
||||
require_once '../../library/Icinga/Web/Hook/Configuration/ConfigurationTab.php';
|
||||
require_once '../../library/Icinga/Exception/ProgrammingError.php';
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Hook\Configuration\ConfigurationTab;
|
||||
|
||||
class ConfigurationTabTest extends \PHPUnit_Framework_TestCase
|
||||
class ConfigurationTabTest extends BaseTestCase
|
||||
{
|
||||
public function testCreate1()
|
||||
{
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web;
|
||||
/**
|
||||
*
|
||||
* Test class for Hook
|
||||
* Created Fri, 22 Mar 2013 09:44:40 +0000
|
||||
*
|
||||
**/
|
||||
require_once("../../library/Icinga/Exception/ProgrammingError.php");
|
||||
require_once("../../library/Icinga/Web/Hook.php");
|
||||
|
||||
require_once("Zend/Log.php");
|
||||
require_once("../../library/Icinga/Application/Logger.php");
|
||||
|
||||
use Icinga\Web\Hook as Hook;
|
||||
use \Mockery;
|
||||
use Icinga\Web\Hook;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class Base
|
||||
{
|
||||
|
@ -35,51 +28,20 @@ class ErrorProneHookImplementation
|
|||
}
|
||||
}
|
||||
|
||||
class ObjectHookImplementation
|
||||
class HookTest extends BaseTestCase
|
||||
{
|
||||
private $test;
|
||||
|
||||
/**
|
||||
* @param mixed $test
|
||||
*/
|
||||
public function setTest($test)
|
||||
{
|
||||
$this->test = $test;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTest()
|
||||
{
|
||||
return $this->test;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getTest();
|
||||
}
|
||||
}
|
||||
|
||||
class HookTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
Hook::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::Has()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testHas()
|
||||
{
|
||||
$this->assertFalse(Hook::has("a"));
|
||||
|
@ -90,11 +52,6 @@ class HookTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertTrue(Hook::has("a","b"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::CreateInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testCreateInstance()
|
||||
{
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
|
@ -103,12 +60,6 @@ class HookTest extends \PHPUnit_Framework_TestCase
|
|||
Hook::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::CreateInstance()
|
||||
* Note: This method is static!
|
||||
*
|
||||
*
|
||||
**/
|
||||
public function testCreateInvalidInstance1()
|
||||
{
|
||||
$this->setExpectedException('\Icinga\Exception\ProgrammingError');
|
||||
|
@ -133,11 +84,6 @@ class HookTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertNull($test);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::All()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testAll()
|
||||
{
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
|
@ -148,14 +94,8 @@ class HookTest extends \PHPUnit_Framework_TestCase
|
|||
foreach(Hook::all("Base") as $instance) {
|
||||
$this->assertInstanceOf("Tests\\Icinga\\Web\\TestHookImplementation",$instance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for Hook::First()
|
||||
* Note: This method is static!
|
||||
*
|
||||
**/
|
||||
public function testFirst()
|
||||
{
|
||||
Hook::$BASE_NS = "Tests\\Icinga\\Web\\";
|
||||
|
@ -168,22 +108,20 @@ class HookTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
public function testRegisterObject()
|
||||
{
|
||||
$o1 = new ObjectHookImplementation();
|
||||
$o1->setTest('$123123');
|
||||
$o1 = Mockery::mock('Some\\Name\\Space\\ObjectHook');
|
||||
$o1->test = '$123123';
|
||||
$o2 = Mockery::mock('Some\\Name\\Space\\ObjectHook');
|
||||
$o2->test = '#456456';
|
||||
|
||||
Hook::registerObject('Test', 'o1', $o1);
|
||||
|
||||
$o2 = new ObjectHookImplementation();
|
||||
$o2->setTest('#456456');
|
||||
|
||||
Hook::registerObject('Test', 'o2', $o2);
|
||||
|
||||
$this->assertInstanceOf('Tests\\Icinga\\Web\\ObjectHookImplementation', Hook::createInstance('Test', 'o1'));
|
||||
$this->assertInstanceOf('Tests\\Icinga\\Web\\ObjectHookImplementation', Hook::createInstance('Test', 'o2'));
|
||||
$this->assertInstanceOf('Some\\Name\\Space\\ObjectHook', Hook::createInstance('Test', 'o1'));
|
||||
$this->assertInstanceOf('Some\\Name\\Space\\ObjectHook', Hook::createInstance('Test', 'o2'));
|
||||
|
||||
$string = "";
|
||||
foreach (Hook::all('Test') as $hook) {
|
||||
$string .= (string)$hook;
|
||||
$string .= $hook->test;
|
||||
}
|
||||
$this->assertEquals('$123123#456456', $string);
|
||||
}
|
||||
|
@ -197,7 +135,7 @@ class HookTest extends \PHPUnit_Framework_TestCase
|
|||
Hook::registerObject('Test', 'e1', 'STRING');
|
||||
}
|
||||
|
||||
public function testGetNullHooks()
|
||||
public function testGetZeroHooks()
|
||||
{
|
||||
$nh = Hook::all('DOES_NOT_EXIST');
|
||||
$this->assertInternalType('array', $nh);
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Web;
|
||||
|
||||
require_once "../../library/Icinga/Exception/ProgrammingError.php";
|
||||
require_once "../../library/Icinga/Web/Notification.php";
|
||||
require_once "../../library/Icinga/Application/Platform.php";
|
||||
require_once "../../library/Icinga/Application/Logger.php";
|
||||
|
||||
require_once "Zend/Session/Namespace.php";
|
||||
require_once "Zend/Config.php";
|
||||
require_once "Zend/Log.php";
|
||||
require_once "Zend/Session.php";
|
||||
require_once "Zend/Log/Writer/Abstract.php";
|
||||
require_once "Zend/Log/Writer/Stream.php";
|
||||
|
||||
use Icinga\Logger\Logger;
|
||||
use Icinga\Web\Notification;
|
||||
|
||||
class NotificationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Logger
|
||||
*/
|
||||
private $logger = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $loggerPath = null;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
\Zend_Session::$_unitTestEnabled = true;
|
||||
|
||||
$this->loggerPath = "/tmp/icinga2-web-notify-test";
|
||||
$this->dropLog();
|
||||
$logConfig = new \Zend_Config(array(
|
||||
"debug" => array(
|
||||
"enable" => 0,
|
||||
"type"=>"mock",
|
||||
"target"=>"target3"
|
||||
),
|
||||
"type" => "stream",
|
||||
"target" => $this->loggerPath
|
||||
));
|
||||
|
||||
$this->logger = new Logger($logConfig);
|
||||
|
||||
// $this->notification = Notification::getInstance();
|
||||
}
|
||||
|
||||
protected function dropLog()
|
||||
{
|
||||
if (file_exists($this->loggerPath)) {
|
||||
unlink($this->loggerPath);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAddMessage1()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$notify = Notification::getInstance();
|
||||
$notify->setCliFlag(true);
|
||||
$notify->error('OK1');
|
||||
$notify->warning('OK2');
|
||||
$notify->info('OK3');
|
||||
$this->logger->flushQueue();
|
||||
|
||||
$content = file_get_contents($this->loggerPath);
|
||||
|
||||
$this->assertContains('[error] OK1', $content);
|
||||
$this->assertContains('[warning] OK2', $content);
|
||||
$this->assertNotContains('[info] OK3', $content);
|
||||
|
||||
$this->dropLog();
|
||||
}
|
||||
|
||||
public function testAddMessage2()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$notify = Notification::getInstance();
|
||||
$notify->setCliFlag(false);
|
||||
|
||||
$notify->success('test123');
|
||||
$notify->error('test456');
|
||||
|
||||
$this->assertTrue($notify->hasMessages());
|
||||
|
||||
$messages = $notify->getMessages();
|
||||
|
||||
$this->assertInternalType('array', $messages);
|
||||
|
||||
$this->assertEquals('test123', $messages[0]->message);
|
||||
$this->assertEquals('success', $messages[0]->type);
|
||||
|
||||
$this->assertEquals('test456', $messages[1]->message);
|
||||
$this->assertEquals('error', $messages[1]->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Icinga\Exception\ProgrammingError
|
||||
* @expectedExceptionMessage "NOT_EXIST_123" is not a valid notification type
|
||||
*/
|
||||
public function testWrongType1()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$notify = Notification::getInstance();
|
||||
$notify->addMessage('test', 'NOT_EXIST_123');
|
||||
}
|
||||
|
||||
public function testSetterAndGetter1()
|
||||
{
|
||||
$this->markTestSkipped();
|
||||
$notify = Notification::getInstance();
|
||||
$notify->setCliFlag(true);
|
||||
$this->assertTrue($notify->getCliFlag());
|
||||
|
||||
$notify->setCliFlag(false);
|
||||
$this->assertFalse($notify->getCliFlag());
|
||||
}
|
||||
}
|
|
@ -1,28 +1,16 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web\Paginator\Adapter;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Zend_Config;
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Protocol\Statusdat\Reader;
|
||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
|
||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
||||
|
||||
require_once 'Zend/Paginator/Adapter/Interface.php';
|
||||
|
||||
require_once '../../library/Icinga/Web/Paginator/Adapter/QueryAdapter.php';
|
||||
require_once 'library/Icinga/Protocol/Statusdat/StatusdatTestLoader.php';
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
|
||||
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusdatQuery.php';
|
||||
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusQuery.php';
|
||||
require_once '../../modules/monitoring/library/Monitoring/Backend.php';
|
||||
|
||||
require_once '../../library/Icinga/Data/BaseQuery.php';
|
||||
require_once '../../library/Icinga/Data/ResourceFactory.php';
|
||||
|
||||
class QueryAdapterTest extends PHPUnit_Framework_TestCase
|
||||
class QueryAdapterTest extends BaseTestCase
|
||||
{
|
||||
private $cacheDir;
|
||||
|
||||
|
@ -30,16 +18,17 @@ class QueryAdapterTest extends PHPUnit_Framework_TestCase
|
|||
|
||||
private $resourceConfig;
|
||||
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->cacheDir = '/tmp'. Reader::STATUSDAT_DEFAULT_CACHE_PATH;
|
||||
|
||||
if (!file_exists($this->cacheDir)) {
|
||||
mkdir($this->cacheDir);
|
||||
}
|
||||
|
||||
$statusdatFile = dirname(__FILE__) . '/../../../../../res/status/icinga.status.dat';
|
||||
$cacheFile = dirname(__FILE__) . '/../../../../../res/status/icinga.objects.cache';
|
||||
$statusdatFile = BaseTestCase::$testDir . '/res/status/icinga.status.dat';
|
||||
$cacheFile = BaseTestCase::$testDir . '/res/status/icinga.objects.cache';
|
||||
|
||||
$this->backendConfig = new Zend_Config(
|
||||
array(
|
||||
|
|
|
@ -1,80 +1,22 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Web\Paginator\ScrollingStyle;
|
||||
|
||||
use Zend_Config;
|
||||
use Zend_Paginator_Adapter_Interface;
|
||||
use Icinga\Module\Monitoring\Backend\Statusdat;
|
||||
// @codingStandardsIgnoreStart
|
||||
require_once realpath(ICINGA_LIBDIR . '/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php');
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use \Zend_Paginator;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Protocol\Statusdat\Reader;
|
||||
use Icinga\Web\Paginator\Adapter\QueryAdapter;
|
||||
use Tests\Icinga\Protocol\Statusdat\StatusdatTestLoader;
|
||||
use Icinga\Module\Monitoring\Backend;
|
||||
|
||||
require_once 'Zend/Paginator/Adapter/Interface.php';
|
||||
require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
|
||||
require_once 'Zend/Paginator.php';
|
||||
require_once 'Zend/Config.php';
|
||||
require_once 'Zend/Cache.php';
|
||||
|
||||
require_once '../../library/Icinga/Web/Paginator/Adapter/QueryAdapter.php';
|
||||
require_once 'library/Icinga/Protocol/Statusdat/StatusdatTestLoader.php';
|
||||
|
||||
StatusdatTestLoader::requireLibrary();
|
||||
|
||||
require_once '../../modules/monitoring/library/Monitoring/Backend.php';
|
||||
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusdatQuery.php';
|
||||
require_once '../../modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusQuery.php';
|
||||
require_once '../../library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php';
|
||||
|
||||
class TestPaginatorAdapter implements Zend_Paginator_Adapter_Interface
|
||||
{
|
||||
private $items = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
for ($i=0; $i<1000; $i++) {
|
||||
$this->items[] = array(
|
||||
'a' => mt_rand(0, 100),
|
||||
'b' => mt_rand(0, 100)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an collection of items for a page.
|
||||
*
|
||||
* @param integer $offset Page offset
|
||||
* @param integer $itemCountPerPage Number of items per page
|
||||
* @return array
|
||||
*/
|
||||
public function getItems($offset, $itemCountPerPage)
|
||||
{
|
||||
$out = array_slice($this->items, $offset, $itemCountPerPage, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* (PHP 5 >= 5.1.0)<br/>
|
||||
* Count elements of an object
|
||||
* @link http://php.net/manual/en/countable.count.php
|
||||
* @return int The custom count as an integer.
|
||||
* </p>
|
||||
* <p>
|
||||
* The return value is cast to an integer.
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Test class for Slidingwithborder
|
||||
* Created Wed, 16 Jan 2013 15:15:16 +0000
|
||||
*
|
||||
**/
|
||||
class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
|
||||
class SlidingwithborderTest extends BaseTestCase
|
||||
{
|
||||
private $cacheDir;
|
||||
|
||||
|
@ -82,16 +24,17 @@ class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
private $resourceConfig;
|
||||
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->cacheDir = '/tmp'. Reader::STATUSDAT_DEFAULT_CACHE_PATH;
|
||||
|
||||
if (!file_exists($this->cacheDir)) {
|
||||
mkdir($this->cacheDir);
|
||||
}
|
||||
|
||||
$statusdatFile = dirname(__FILE__). '/../../../../../res/status/icinga.status.dat';
|
||||
$cacheFile = dirname(__FILE__). '/../../../../../res/status/icinga.objects.cache';
|
||||
$statusdatFile = BaseTestCase::$testDir . '/res/status/icinga.status.dat';
|
||||
$cacheFile = BaseTestCase::$testDir . '/res/status/icinga.objects.cache';
|
||||
|
||||
$this->backendConfig = new Zend_Config(
|
||||
array(
|
||||
|
@ -101,7 +44,7 @@ class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
|
|||
$this->resourceConfig = new Zend_Config(
|
||||
array(
|
||||
'status_file' => $statusdatFile,
|
||||
'object_file' => $cacheFile,
|
||||
'object_file' => $cacheFile,
|
||||
'type' => 'statusdat'
|
||||
)
|
||||
);
|
||||
|
@ -110,54 +53,44 @@ class SlidingwithborderTest extends \PHPUnit_Framework_TestCase
|
|||
public function testGetPages1()
|
||||
{
|
||||
$backend = new Backend($this->backendConfig, $this->resourceConfig);
|
||||
$query = $backend->select()->from('status');
|
||||
|
||||
$adapter = new QueryAdapter($query);
|
||||
$adapter = new QueryAdapter($backend->select()->from('status'));
|
||||
|
||||
$this->assertEquals(30, $adapter->count());
|
||||
|
||||
$scrolingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
||||
$paginator = new \Zend_Paginator($adapter);
|
||||
|
||||
$pages = $scrolingStyle->getPages($paginator);
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
$paginator = new Zend_Paginator($adapter);
|
||||
|
||||
$pages = $scrollingStyle->getPages($paginator);
|
||||
$this->assertInternalType('array', $pages);
|
||||
$this->assertCount(3, $pages);
|
||||
}
|
||||
|
||||
public function testGetPages2()
|
||||
{
|
||||
$scrolingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
||||
$adapter = new TestPaginatorAdapter();
|
||||
|
||||
$paginator = new \Zend_Paginator($adapter);
|
||||
|
||||
$pages = $scrolingStyle->getPages($paginator);
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
$paginator = new Zend_Paginator($this->getPaginatorAdapter());
|
||||
|
||||
$pages = $scrollingStyle->getPages($paginator);
|
||||
$this->assertInternalType('array', $pages);
|
||||
|
||||
$this->assertCount(13, $pages);
|
||||
$this->assertEquals('...', $pages[11]);
|
||||
}
|
||||
|
||||
public function testGetPages3()
|
||||
{
|
||||
$scrolingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
|
||||
$adapter = new TestPaginatorAdapter();
|
||||
|
||||
$paginator = new \Zend_Paginator($adapter);
|
||||
$scrollingStyle = new \Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder();
|
||||
$paginator = new Zend_Paginator($this->getPaginatorAdapter());
|
||||
$paginator->setCurrentPageNumber(9);
|
||||
|
||||
$pages = $scrolingStyle->getPages($paginator);
|
||||
|
||||
$pages = $scrollingStyle->getPages($paginator);
|
||||
$this->assertInternalType('array', $pages);
|
||||
|
||||
$this->assertCount(16, $pages);
|
||||
$this->assertEquals('...', $pages[3]);
|
||||
$this->assertEquals('...', $pages[14]);
|
||||
}
|
||||
|
||||
protected function getPaginatorAdapter()
|
||||
{
|
||||
return Mockery::mock('\Zend_Paginator_Adapter_Interface')->shouldReceive('count')->andReturn(1000)->getMock();
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue