first commit
This commit is contained in:
parent
985a5c928c
commit
f40a84879c
551 changed files with 72374 additions and 24 deletions
104
dvwa/external/phpids/0.6/tests/IDS/CachingTest.php
vendored
Normal file
104
dvwa/external/phpids/0.6/tests/IDS/CachingTest.php
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2007 PHPIDS group (http://php-ids.org)
|
||||
*
|
||||
* 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; version 2 of the license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package PHPIDS tests
|
||||
* @version SVN: $Id:CachingTest.php 515 2007-09-15 13:43:40Z christ1an $
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib');
|
||||
require_once 'IDS/Init.php';
|
||||
require_once 'IDS/Caching/Factory.php';
|
||||
|
||||
class IDS_CachingTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function setUp() {
|
||||
$this->path = dirname(__FILE__) . '/../../lib/IDS/Config/Config.ini';
|
||||
$this->init = IDS_Init::init($this->path);
|
||||
}
|
||||
|
||||
function testCachingNone() {
|
||||
$this->init->config['Caching']['caching'] = 'none';
|
||||
$this->assertFalse(IDS_Caching::factory($this->init, 'storage'));
|
||||
}
|
||||
|
||||
function testCachingFile() {
|
||||
$this->init->config['Caching']['caching'] = 'file';
|
||||
$this->init->config['Caching']['expiration_time'] = 0;
|
||||
$this->assertTrue(IDS_Caching::factory($this->init, 'storage') instanceof IDS_Caching_File);
|
||||
}
|
||||
|
||||
function testCachingFileSetCache() {
|
||||
$this->init->config['Caching']['caching'] = 'file';
|
||||
$this->init->config['Caching']['expiration_time'] = 0;
|
||||
$cache = IDS_Caching::factory($this->init, 'storage');
|
||||
$cache = $cache->setCache(array(1,2,3,4));
|
||||
$this->assertTrue($cache instanceof IDS_Caching_File);
|
||||
}
|
||||
|
||||
function testCachingFileGetCache() {
|
||||
$this->init->config['Caching']['caching'] = 'file';
|
||||
$this->init->config['Caching']['path'] = dirname(__FILE__) . '/../../lib/IDS/tmp/default_filter.cache';
|
||||
$this->init->config['Caching']['expiration_time'] = 0;
|
||||
$cache = IDS_Caching::factory($this->init, 'storage');
|
||||
$cache = $cache->setCache(array(1,2,3,4));
|
||||
$this->assertEquals($cache->getCache(), array(1,2,3,4));
|
||||
}
|
||||
|
||||
function testCachingSession() {
|
||||
$this->init->config['Caching']['caching'] = 'session';
|
||||
$this->assertTrue(IDS_Caching::factory($this->init, 'storage') instanceof IDS_Caching_Session);
|
||||
}
|
||||
|
||||
function testCachingSessionSetCache() {
|
||||
$this->init->config['Caching']['caching'] = 'session';
|
||||
|
||||
$cache = IDS_Caching::factory($this->init, 'storage');
|
||||
$cache = $cache->setCache(array(1,2,3,4));
|
||||
$this->assertTrue($cache instanceof IDS_Caching_Session);
|
||||
}
|
||||
|
||||
function testCachingSessionGetCache() {
|
||||
$this->init->config['Caching']['caching'] = 'session';
|
||||
|
||||
$cache = IDS_Caching::factory($this->init, 'storage');
|
||||
$cache = $cache->setCache(array(1,2,3,4));
|
||||
$this->assertEquals($cache->getCache(), array(1,2,3,4));
|
||||
}
|
||||
|
||||
function testCachingSessionGetCacheDestroyed() {
|
||||
$this->init->config['Caching']['caching'] = 'session';
|
||||
|
||||
$cache = IDS_Caching::factory($this->init, 'storage');
|
||||
$cache = $cache->setCache(array(1,2,3,4));
|
||||
$_SESSION['PHPIDS']['storage'] = null;
|
||||
$this->assertFalse($cache->getCache());
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
@unlink(dirname(__FILE__) . '/../../lib/IDS/tmp/default_filter.cache');
|
||||
@unlink(dirname(__FILE__) . '/../../lib/IDS/tmp/memcache.timestamp');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
||||
85
dvwa/external/phpids/0.6/tests/IDS/EventTest.php
vendored
Normal file
85
dvwa/external/phpids/0.6/tests/IDS/EventTest.php
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2007 PHPIDS group (http://php-ids.org)
|
||||
*
|
||||
* 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; version 2 of the license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package PHPIDS tests
|
||||
* @version SVN: $Id:EventTest.php 515 2007-09-15 13:43:40Z christ1an $
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib');
|
||||
require_once 'IDS/Event.php';
|
||||
require_once 'IDS/Filter.php';
|
||||
|
||||
class IDS_EventTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->event = new IDS_Event("handled_key", "my val",
|
||||
array(
|
||||
new IDS_Filter(1, '^test$', 'my description', array('tag1', 'tag2'), 10),
|
||||
new IDS_Filter(1, '^test2$', 'my other desc', array('tag2', 'tag3'), 4)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testName()
|
||||
{
|
||||
$this->assertEquals('handled_key', $this->event->getName());
|
||||
$this->assertEquals("my val", $this->event->getValue());
|
||||
}
|
||||
|
||||
public function testValueAggregation()
|
||||
{
|
||||
$this->assertEquals(14, $this->event->getImpact());
|
||||
$this->assertEquals(array('tag1', 'tag2', 'tag3'), $this->event->getTags());
|
||||
}
|
||||
|
||||
public function testIterator()
|
||||
{
|
||||
$regexps = array('^test$', '^test2$');
|
||||
foreach ($this->event as $key => $filter)
|
||||
$this->assertEquals($regexps[$key], $filter->getRule());
|
||||
foreach ($this->event->getFilters() as $key => $filter)
|
||||
$this->assertEquals($regexps[$key], $filter->getRule());
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$this->assertEquals(2, count($this->event));
|
||||
}
|
||||
|
||||
public function testCopy()
|
||||
{
|
||||
$filters = $this->event->getFilters();
|
||||
$filter[] = "foo";
|
||||
$this->assertEquals(2, count($this->event));
|
||||
}
|
||||
|
||||
public function testIteratorAggregate()
|
||||
{
|
||||
$this->assertType('IteratorAggregate', $this->event);
|
||||
$this->assertType('IteratorAggregate', $this->event->getIterator());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
||||
112
dvwa/external/phpids/0.6/tests/IDS/ExceptionTest.php
vendored
Normal file
112
dvwa/external/phpids/0.6/tests/IDS/ExceptionTest.php
vendored
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2007 PHPIDS group (http://php-ids.org)
|
||||
*
|
||||
* 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; version 2 of the license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package PHPIDS tests
|
||||
* @version SVN: $Id:ExceptionTest.php 517 2007-09-15 15:04:13Z mario $
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib');
|
||||
require_once 'IDS/Init.php';
|
||||
require_once 'IDS/Caching/Factory.php';
|
||||
require_once 'IDS/Report.php';
|
||||
require_once 'IDS/Event.php';
|
||||
require_once 'IDS/Filter.php';
|
||||
require_once 'IDS/Monitor.php';
|
||||
require_once 'IDS/Filter/Storage.php';
|
||||
|
||||
class IDS_ExceptionTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp() {
|
||||
$this->report = new IDS_Report(array(
|
||||
new IDS_Event("key_a", 'val_b',
|
||||
array(
|
||||
new IDS_Filter(1, '^test_a1$', 'desc_a1', array('tag_a1', 'tag_a2'), 1),
|
||||
new IDS_Filter(1, '^test_a2$', 'desc_a2', array('tag_a2', 'tag_a3'), 2)
|
||||
)
|
||||
),
|
||||
new IDS_Event('key_b', 'val_b',
|
||||
array(
|
||||
new IDS_Filter(1, '^test_b1$', 'desc_b1', array('tag_b1', 'tag_b2'), 3),
|
||||
new IDS_FIlter(1, '^test_b2$', 'desc_b2', array('tag_b2', 'tag_b3'), 4),
|
||||
)
|
||||
)
|
||||
));
|
||||
|
||||
$this->path = dirname(__FILE__) . '/../../lib/IDS/Config/Config.ini';
|
||||
$this->init = IDS_Init::init($this->path);
|
||||
}
|
||||
|
||||
public function testEventConstructorExceptions1() {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
new IDS_Event(array(1,2), 'val_b',
|
||||
array(
|
||||
new IDS_Filter(1, '^test_a1$', 'desc_a1', array('tag_a1', 'tag_a2'), 1),
|
||||
new IDS_Filter(1, '^test_a2$', 'desc_a2', array('tag_a2', 'tag_a3'), 2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEventConstructorExceptions2() {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
new IDS_Event("key_a", array(1,2),
|
||||
array(
|
||||
new IDS_Filter(1, '^test_a1$', 'desc_a1', array('tag_a1', 'tag_a2'), 1),
|
||||
new IDS_Filter(1, '^test_a2$', 'desc_a2', array('tag_a2', 'tag_a3'), 2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEventConstructorExceptions3() {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
new IDS_Event("key_a", 'val_b', array(1,2));
|
||||
}
|
||||
|
||||
public function testGetEventException() {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->assertEquals($this->report->getEvent(array(1,2,3)), $this->getExpectedException());
|
||||
}
|
||||
|
||||
public function testHasEventException() {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
$this->assertEquals($this->report->hasEvent(array(1,2,3)), $this->getExpectedException());
|
||||
}
|
||||
|
||||
public function testInitConfigWrongPathException() {
|
||||
$this->setExpectedException('Exception');
|
||||
$this->assertEquals(IDS_Init::init('IDS/Config/Config.ini.wrong'), $this->getExpectedException());
|
||||
}
|
||||
|
||||
public function testWrongXmlFilterPathException() {
|
||||
$this->setExpectedException('Exception');
|
||||
$this->init->config['General']['filter_type'] = 'xml';
|
||||
$this->init->config['General']['filter_path'] = 'IDS/wrong_path';
|
||||
$this->assertEquals(new IDS_Monitor(array('test', 'bla'), $this->init), $this->getExpectedException());
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->init->config['General']['filter_type'] = 'xml';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
||||
97
dvwa/external/phpids/0.6/tests/IDS/FilterTest.php
vendored
Normal file
97
dvwa/external/phpids/0.6/tests/IDS/FilterTest.php
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2007 PHPIDS group (http://php-ids.org)
|
||||
*
|
||||
* 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; version 2 of the license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package PHPIDS tests
|
||||
* @version SVN: $Id:FilterTest.php 515 2007-09-15 13:43:40Z christ1an $
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib');
|
||||
require_once 'IDS/Init.php';
|
||||
|
||||
class IDS_FilterTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp() {
|
||||
$this->path = dirname(__FILE__) . '/../../lib/IDS/Config/Config.ini';
|
||||
$this->init = IDS_Init::init($this->path);
|
||||
}
|
||||
|
||||
public function testObjectConstruction()
|
||||
{
|
||||
$filter = new IDS_Filter(1, '^test$', 'My description', array('foo', 'bar'), 12);
|
||||
|
||||
$this->assertTrue($filter->match('test'));
|
||||
$this->assertEquals("My description", $filter->getDescription(), "Should return description");
|
||||
$this->assertEquals(array("foo", "bar"), $filter->getTags(), "Should return array/list of tags");
|
||||
$this->assertEquals('^test$', $filter->getRule());
|
||||
$this->assertEquals(12, $filter->getImpact());
|
||||
}
|
||||
|
||||
public function testModificator()
|
||||
{
|
||||
$filter = new IDS_Filter(1, '^te.st$', 'My description', array('tag1', 'tag2'), 1);
|
||||
|
||||
// Default must be
|
||||
// ... case-insensitive
|
||||
$this->assertTrue($filter->match('TE1ST'));
|
||||
// ... dot all (\n is matched by .)
|
||||
$this->assertTrue($filter->match("TE\nST"));
|
||||
// .. "$" is end only #has changed since modifiers are ims
|
||||
$this->assertTrue($filter->match("TE1ST\n"));
|
||||
|
||||
}
|
||||
|
||||
public function testExceptions()
|
||||
{
|
||||
$filter = new IDS_Filter(1, '^test$', 'My description', array('foo', 'bar'), 10);
|
||||
|
||||
try {
|
||||
$filter->match(1);
|
||||
$this->fail("Expected Exception");
|
||||
} catch (Exception $e) {}
|
||||
|
||||
|
||||
try {
|
||||
$filter = new IDS_Filter(1, '^test$', 'my desc', array('foo'), 'test');
|
||||
$this->fail("Expected Exception");
|
||||
} catch (Exception $e) {}
|
||||
|
||||
try {
|
||||
$filter = new IDS_Filter(1, 1, 'my desc', array("foo"), 'bla');
|
||||
$this->fail("Excpected Exception");
|
||||
} catch (Exception $e) {}
|
||||
|
||||
}
|
||||
|
||||
public function testFilterSetFilterSet() {
|
||||
|
||||
$this->init->config['General']['filter_type'] = 'xml';
|
||||
$this->init->config['General']['filter_path'] = dirname(__FILE__) . '/../../lib/IDS/default_filter.xml';
|
||||
$this->storage = new IDS_Filter_Storage($this->init);
|
||||
$filter = array();
|
||||
$filter[] = new IDS_Filter(1, 'test', 'test2', array(), 1);
|
||||
$this->assertTrue($this->storage->setFilterSet($filter) instanceof IDS_Filter_Storage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
||||
90
dvwa/external/phpids/0.6/tests/IDS/InitTest.php
vendored
Normal file
90
dvwa/external/phpids/0.6/tests/IDS/InitTest.php
vendored
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2007 PHPIDS group (http://php-ids.org)
|
||||
*
|
||||
* 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; version 2 of the license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package PHPIDS tests
|
||||
* @version SVN: $Id:InitTest.php 517 2007-09-15 15:04:13Z mario $
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib');
|
||||
require_once 'IDS/Init.php';
|
||||
|
||||
class IDS_InitTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function setUp() {
|
||||
$this->path = dirname(__FILE__) . '/../../lib/IDS/Config/Config.ini';
|
||||
$this->init = IDS_Init::init($this->path);
|
||||
}
|
||||
|
||||
function testInit() {
|
||||
$this->assertTrue($this->init instanceof IDS_Init);
|
||||
}
|
||||
|
||||
function testInitConfig() {
|
||||
$keys = array('General', 'Logging', 'Caching');
|
||||
$this->assertEquals($keys, array_keys($this->init->config));
|
||||
}
|
||||
|
||||
function testInitClone() {
|
||||
$config2 = clone $this->init;
|
||||
$this->assertEquals($config2, $this->init);
|
||||
}
|
||||
|
||||
function testInitGetConfigPath() {
|
||||
$this->assertEquals($this->init->getConfigPath(), $this->path);
|
||||
}
|
||||
|
||||
function testInitSetConfigOverwrite() {
|
||||
$this->init->setConfig(array('General' => array('filter_type' => 'json')), true);
|
||||
$this->assertEquals($this->init->config['General']['filter_type'], 'json');
|
||||
|
||||
$this->init->setConfig(
|
||||
array('General' => array('exceptions' => array('foo'))),
|
||||
true
|
||||
);
|
||||
$this->assertSame(
|
||||
array('foo', '__utmc'),
|
||||
$this->init->config['General']['exceptions']
|
||||
);
|
||||
}
|
||||
|
||||
function testInitSetConfigNoOverwrite() {
|
||||
$this->init->setConfig(array('General' => array('filter_type' => 'xml')), true);
|
||||
$this->init->setConfig(array('General' => array('filter_type' => 'json')));
|
||||
$this->assertEquals($this->init->config['General']['filter_type'], 'xml');
|
||||
}
|
||||
|
||||
function testInitGetConfig() {
|
||||
$data = $this->init->getConfig();
|
||||
$this->assertEquals($this->init->config, $data);
|
||||
}
|
||||
|
||||
function testInstanciatingInitObjectWithoutPassingConfigFile()
|
||||
{
|
||||
$init = IDS_Init::init();
|
||||
$this->assertType('IDS_Init', $init);
|
||||
$this->assertSame($init, IDS_Init::init());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
||||
1389
dvwa/external/phpids/0.6/tests/IDS/MonitorTest.php
vendored
Normal file
1389
dvwa/external/phpids/0.6/tests/IDS/MonitorTest.php
vendored
Normal file
File diff suppressed because it is too large
Load diff
123
dvwa/external/phpids/0.6/tests/IDS/ReportTest.php
vendored
Normal file
123
dvwa/external/phpids/0.6/tests/IDS/ReportTest.php
vendored
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPIDS
|
||||
* Requirements: PHP5, SimpleXML
|
||||
*
|
||||
* Copyright (c) 2007 PHPIDS group (http://php-ids.org)
|
||||
*
|
||||
* 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; version 2 of the license.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @package PHPIDS tests
|
||||
* @version SVN: $Id:ReportTest.php 515 2007-09-15 13:43:40Z christ1an $
|
||||
*/
|
||||
|
||||
require_once 'PHPUnit/Framework/TestCase.php';
|
||||
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../lib');
|
||||
require_once 'IDS/Report.php';
|
||||
require_once 'IDS/Event.php';
|
||||
|
||||
class IDS_ReportTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->report = new IDS_Report(array(
|
||||
new IDS_Event("key_a", 'val_b',
|
||||
array(
|
||||
new IDS_Filter(1, '^test_a1$', 'desc_a1', array('tag_a1', 'tag_a2'), 1),
|
||||
new IDS_Filter(1, '^test_a2$', 'desc_a2', array('tag_a2', 'tag_a3'), 2)
|
||||
)
|
||||
),
|
||||
new IDS_Event('key_b', 'val_b',
|
||||
array(
|
||||
new IDS_Filter(1, '^test_b1$', 'desc_b1', array('tag_b1', 'tag_b2'), 3),
|
||||
new IDS_FIlter(1, '^test_b2$', 'desc_b2', array('tag_b2', 'tag_b3'), 4),
|
||||
)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testEmpty()
|
||||
{
|
||||
$this->assertFalse($this->report->isEmpty());
|
||||
$report = new IDS_Report;
|
||||
$this->assertTrue($report->isEmpty());
|
||||
}
|
||||
|
||||
public function testCountable()
|
||||
{
|
||||
$this->assertEquals(2, count($this->report));
|
||||
}
|
||||
|
||||
public function testGetterByName()
|
||||
{
|
||||
$this->assertEquals("key_a", $this->report->getEvent("key_a")->getName());
|
||||
$this->assertEquals("key_b", $this->report->getEvent("key_b")->getName());
|
||||
}
|
||||
|
||||
public function testGetTags()
|
||||
{
|
||||
$this->assertEquals(array('tag_a1', 'tag_a2', 'tag_a3', 'tag_b1', 'tag_b2', 'tag_b3'), $this->report->getTags());
|
||||
}
|
||||
|
||||
public function testImpactSum()
|
||||
{
|
||||
$this->assertEquals(10, $this->report->getImpact());
|
||||
}
|
||||
|
||||
public function testHasEvent()
|
||||
{
|
||||
$this->assertTrue($this->report->hasEvent('key_a'));
|
||||
}
|
||||
|
||||
public function testAddingAnotherEventAfterCalculation()
|
||||
{
|
||||
$this->testImpactSum();
|
||||
$this->testGetTags();
|
||||
$this->report->addEvent(new IDS_Event('key_c', 'val_c', array(new IDS_Filter(1, 'test_c1', 'desc_c1', array('tag_c1'), 10))));
|
||||
$this->assertEquals(20, $this->report->getImpact());
|
||||
$this->assertEquals(array('tag_a1', 'tag_a2', 'tag_a3', 'tag_b1', 'tag_b2', 'tag_b3', 'tag_c1'), $this->report->getTags());
|
||||
}
|
||||
|
||||
public function testIteratorAggregate()
|
||||
{
|
||||
$this->assertType('IteratorAggregate', $this->report);
|
||||
$this->assertType('IteratorAggregate', $this->report->getIterator());
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$this->assertEquals(preg_match('/Total impact: 10/', $this->report->__toString()),1);
|
||||
}
|
||||
|
||||
public function testToStringEmpty()
|
||||
{
|
||||
$this->report = new IDS_Report();
|
||||
$this->assertEquals('', $this->report->__toString());
|
||||
}
|
||||
|
||||
public function testGetEvent() {
|
||||
$this->report->addEvent(new IDS_Event('key_c', 'val_c', array(new IDS_Filter(1, 'test_c1', 'desc_c1', array('tag_c1'), 10))));
|
||||
$this->assertTrue($this->report->getEvent('key_c') instanceof IDS_Event);
|
||||
}
|
||||
|
||||
public function testGetEventWrong() {
|
||||
$this->assertFalse($this->report->getEvent('not_available'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 expandtab
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue