Remove outdated PHPUnit tests

Need new good tests.
This commit is contained in:
Dmitriy Simushev 2014-07-11 13:10:18 +00:00
parent f33c686aab
commit 7ce675da86
18 changed files with 0 additions and 3360 deletions

View File

View File

@ -1,208 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/database.php';
require_once dirname(__FILE__) . '/../config.php';
/**
* Test class for Database.
* Generated by PHPUnit on 2012-07-11 at 12:37:41.
*/
class DatabaseTest extends PHPUnit_Framework_TestCase {
/**
* @var Database
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {
$this->object = Database::getInstance();
}
public static function setUpBeforeClass() {
global $db_host, $db_name, $db_user, $db_pass, $tables_prefix,
$db_encoding, $force_charset_in_connection, $use_persistent_connection;
Database::initialize(
$db_host,
$db_user,
$db_pass,
$use_persistent_connection,
$db_name,
$tables_prefix,
$force_charset_in_connection,
$db_encoding
);
$dbh = new PDO(
"mysql:host={$db_host};dbname={$db_name}",
$db_user,
$db_pass
);
$dbh->exec(
"CREATE TABLE phpunit_test_only " .
"(id INT (10) UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (id))"
);
$dbh = NULL;
}
public static function tearDownAfterClass() {
global $db_host, $db_user, $db_pass, $db_name;
$dbh = new PDO(
"mysql:host={$db_host};dbname={$db_name}",
$db_user,
$db_pass
);
$dbh->exec("DROP TABLE phpunit_test_only");
$dbh = NULL;
Database::destroy();
}
public function testGetInstance() {
$anotherDatabaseInstance = Database::getInstance();
$this->assertSame($this->object, $anotherDatabaseInstance);
$anotherDatabaseInstance = NULL;
}
public function testErrorInfo() {
$this->object->throwExeptions(true);
$this->assertFalse($this->object->errorInfo());
try{
$this->object->query("SOME_FAKE_QUERY");
$this->fail('Exception must be thrown!');
} catch(Exception $e) {
$errorInfo = $this->object->errorInfo();
$this->assertEquals('42000', $errorInfo[0]);
$this->assertEquals(1064, $errorInfo[1]);
}
$this->object->query("SELECT 'test_value'");
$errorInfo = $this->object->errorInfo();
$this->assertEquals('00000', $errorInfo[0]);
}
public function testQuery() {
global $mysqlprefix;
// Test simple good query
$this->assertTrue($this->object->query("SELECT 'test_value'"));
// Test various fetch type
$result = $this->object->query(
"SELECT 'test_value_one' AS field_name",
NULL,
array('return_rows' => Database::RETURN_ONE_ROW)
);
$this->assertEquals('test_value_one', $result['field_name']);
$result = $this->object->query(
"SELECT 'test_value_two' AS field_name",
NULL,
array(
'return_rows' => Database::RETURN_ONE_ROW,
'fetch_type' => Database::FETCH_ASSOC
)
);
$this->assertEquals('test_value_two', $result['field_name']);
$result = $this->object->query(
"SELECT 'test_value_four' AS field_name",
NULL,
array(
'return_rows' => Database::RETURN_ONE_ROW,
'fetch_type' => Database::FETCH_NUM
)
);
$this->assertEquals('test_value_four', $result[0]);
$result = $this->object->query(
"SELECT 'test_value_four' AS field_name",
NULL,
array(
'return_rows' => Database::RETURN_ONE_ROW,
'fetch_type' => Database::FETCH_BOTH
)
);
$this->assertEquals('test_value_four', $result['field_name']);
$this->assertEquals('test_value_four', $result[0]);
// Test all rows return
$result = $this->object->query(
"SELECT 'test_value_five' AS field_name " .
"UNION SELECT 'test_value_six' AS field_name",
NULL,
array('return_rows' => Database::RETURN_ALL_ROWS)
);
$this->assertEquals('test_value_five', $result[0]['field_name']);
$this->assertEquals('test_value_six', $result[1]['field_name']);
// Test unnamed placeholders
$result = $this->object->query(
"SELECT ? AS field_name ",
array('test_value_seven'),
array('return_rows' => Database::RETURN_ONE_ROW)
);
$this->assertEquals('test_value_seven', $result['field_name']);
// Test named placeholders
$result = $this->object->query(
"SELECT :name AS field_name ",
array(':name' => 'test_value_eight'),
array('return_rows' => Database::RETURN_ONE_ROW)
);
$this->assertEquals('test_value_eight', $result['field_name']);
// Test prefixies
$result = $this->object->query(
"SELECT '{test}' AS field_name ",
NULL,
array('return_rows' => Database::RETURN_ONE_ROW)
);
$this->assertEquals($mysqlprefix.'test', $result['field_name']);
}
public function testInsertedId() {
$this->object->query("INSERT INTO phpunit_test_only (id) VALUES (NULL)");
$actual_id = $this->object->insertedId();
list($expected_id) = $this->object->query(
"SELECT MAX(id) FROM phpunit_test_only",
NULL,
array(
'return_rows' => Database::RETURN_ONE_ROW,
'fetch_type' => Database::FETCH_NUM
)
);
$this->assertTrue(is_numeric($actual_id));
$this->assertEquals($expected_id, $actual_id);
}
public function testAffectedRows() {
// Test on INSERT
$this->object->query(
"INSERT INTO phpunit_test_only (id) VALUES " .
"(100), (101), (102), (103), (104), (105)"
);
$this->assertEquals(6, $this->object->affectedRows());
// Test on UPDATE
$this->object->query(
"UPDATE phpunit_test_only SET id = id+100 WHERE id > 103"
);
$this->assertEquals(2, $this->object->affectedRows());
// Test on SELECT
$this->object->query(
"SELECT * FROM phpunit_test_only WHERE id >= 100 AND id <= 103"
);
$this->assertEquals(4, $this->object->affectedRows());
// Test on DELETE
$this->object->query(
"DELETE FROM phpunit_test_only WHERE id >= 100"
);
$this->assertEquals(6, $this->object->affectedRows());
}
}
?>

View File

@ -1,104 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/event_dispatcher.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/plugin.php';
require_once dirname(__FILE__) . '/../../plugins/phpunit_autotest_plugin_manager/phpunit_autotest_plugin_manager_plugin.php';
/**
* Test class for EventDispatcher.
* Generated by PHPUnit on 2012-07-17 at 16:09:00.
*/
class EventDispatcherTest extends PHPUnit_Framework_TestCase {
protected static $plugin = null;
public static function setUpBeforeClass() {
self::$plugin = new PhpunitAutotestPluginManagerPlugin();
}
public static function tearDownAfterClass() {
self::$plugin = null;
}
public function testGetInstance() {
$dispatcher = EventDispatcher::getInstance();
$another_dispatcher = EventDispatcher::getInstance();
$this->assertSame($dispatcher, $another_dispatcher);
unset($another_dispatcher);
return $dispatcher;
}
/**
* @depends testGetInstance
*/
public function testAttachListener($dispatcher) {
// Try to Attach wrong method as listener to event
// Following code wait for trigger user error, which converts by PHPUnit to an
// Exception
try{
$dispatcher->attachListener(
'some_test_event',
self::$plugin,
'wrongEventListener'
);
$this->fail("Error expected!");
} catch(Exception $e) {}
// Try to attach listener to event
$this->assertTrue(
$dispatcher->attachListener(
'some_test_event',
self::$plugin,
'testEventListener'
)
);
// Try to attach listener to event
$this->assertTrue(
$dispatcher->attachListener(
'some_another_test_event',
self::$plugin,
'testEventListener'
)
);
return $dispatcher;
}
/**
* @depends testAttachListener
*/
public function testDetachListener($dispatcher) {
// Try to detach listner that was not attached to registerd event
$this->assertFalse(
$dispatcher->detachListener(
'some_test_event',
self::$plugin,
'wrongEventListener'
)
);
// Try to detach listener that was attached to registered
$this->assertTrue(
$dispatcher->detachListener(
'some_test_event',
self::$plugin,
'testEventListener'
)
);
return $dispatcher;
}
/**
* @depends testDetachListener
*/
public function testTriggerEvent($dispatcher) {
// Try to trigger registered event
$test_array = array();
$dispatcher->triggerEvent('some_another_test_event', $test_array);
$this->assertEquals('some_test_value', $test_array['test']);
}
}
?>

View File

@ -1,167 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api_execution_context.php';
/**
* Test class for MibewAPIExecutionContext.
* Generated by PHPUnit on 2012-07-27 at 15:47:53.
*/
class MibewAPIExecutionContextTest extends PHPUnit_Framework_TestCase {
public function testStoreFunctionResults() {
$context = new MibewAPIExecutionContext();
// Create 'function' array. See Mibew API for details.
$function = array(
'function' => 'test_function',
'arguments' => array(
'return' => array('microtime' => 'time'),
'references' => array()
)
);
// Wrong function's results
$wrong_results = array();
// Try to catch MibewAPIException with
// MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT code
try {
$context->storeFunctionResults($function, $wrong_results);
$this->fail("Exception must be thrown");
} catch(MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT,
$e->getCode()
);
}
// Correct function's results
$results = array(
'microtime' => 'some_microtime_value'
);
$context->storeFunctionResults($function, $results);
return $context;
}
/**
* @depends testStoreFunctionResults
*/
public function testGetResults(MibewAPIExecutionContext $context) {
$results = $context->getResults();
$this->assertEquals(
array('time' => 'some_microtime_value'),
$results
);
//return $context;
}
/**
* @depends testStoreFunctionResults
*/
public function testGetArgumentsList(MibewAPIExecutionContext $context) {
// Function with wrong references arguments. See Mibew API for details of 'function'
// array
$wrong_function = array(
'function' => 'test',
'arguments' => array(
'return' => array(),
'references' => array(
// Wrong function number. Execution does not have to many
// functons results
'x' => 12
),
'x' => 'microtime'
)
);
// Try to catch MibewAPIException with
// MibewAPIException::WRONG_FUNCTION_NUM_IN_REFERENCE code
try {
$context->getArgumentsList($wrong_function);
$this->fail("Exception must be thrown");
} catch(MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::WRONG_FUNCTION_NUM_IN_REFERENCE,
$e->getCode()
);
}
// Another wrong function.
$wrong_function = array(
'function' => 'test',
'arguments' => array(
'return' => array(),
'references' => array(
// Wrong argument 'x'. This function does not have this
// argument
'x' => 1
)
)
);
// Try to catch MibewAPIException with
// MibewAPIException::EMPTY_VARIABLE_IN_REFERENCE code
try {
$context->getArgumentsList($wrong_function);
$this->fail("Exception must be thrown");
} catch(MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_VARIABLE_IN_REFERENCE,
$e->getCode()
);
}
// Another wrong function.
$wrong_function = array(
'function' => 'test',
'arguments' => array(
'return' => array(),
'references' => array(
'x' => 1
),
// Wrong reference name.
'x' => 'wrong_result'
)
);
// Try to catch MibewAPIException with
// MibewAPIException::VARIABLE_IS_UNDEFINED_IN_REFERENCE code
try {
$context->getArgumentsList($wrong_function);
$this->fail("Exception must be thrown");
} catch(MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::VARIABLE_IS_UNDEFINED_IN_REFERENCE,
$e->getCode()
);
}
// Correct function.
$correct_function = array(
'function' => 'test',
'arguments' => array(
'return' => array(),
'references' => array(
'x' => 1
),
'x' => 'microtime'
)
);
$arguments = $context->getArgumentsList($correct_function);
$this->assertEquals(
array(
'x' => 'some_microtime_value',
'return' => array(),
'references' => array(
'x' => 1
)
),
$arguments
);
}
}
?>

View File

@ -1,61 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api_interaction.php';
require_once dirname(__FILE__) . '/mibew_api_test_interaction.php';
/**
* Test class for MibewAPIInteraction.
*/
class MibewAPIInteractionTest extends PHPUnit_Framework_TestCase {
/**
* An instance of the MibewAPITestInteraction
* @var MibewAPITestInteraction
*/
protected $object = null;
protected function setUp() {
$this->object = new MibewAPITestInteraction();
}
protected function tearDown() {
unset($this->object);
}
public function testGetObligatoryArguments() {
// Test obligatory arguments for all functions
$this->assertEquals(
$this->object->getObligatoryArguments('some_default_function'),
array('return', 'references')
);
// Test obligatory argumens for specific function
$this->assertEquals(
$this->object->getObligatoryArguments('foo'),
array('return', 'references', 'bar')
);
}
public function testGetObligatoryArgumentsDefaults() {
// Test default values for obligatory arguments for all functions
$this->assertEquals(
$this->object->getObligatoryArgumentsDefaults('some_default_function'),
array(
'return' => array(),
'references' => array()
)
);
// Test default values for obligatory argumens for specific function
$this->assertEquals(
$this->object->getObligatoryArgumentsDefaults('foo'),
array(
'return' => array(),
'references' => array(),
'bar' => 127
)
);
}
}
?>

View File

@ -1,607 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api_interaction.php';
require_once dirname(__FILE__) . '/mibew_api_test_interaction.php';
/**
* Test class for MibewAPI.
* Generated by PHPUnit on 2012-07-27 at 15:47:47.
*/
class MibewAPITest extends PHPUnit_Framework_TestCase {
public function testGetAPI() {
$mibew_api = MibewAPI::getAPI('MibewAPITestInteraction');
$this->assertEquals($mibew_api, MibewAPI::getAPI('MibewAPITestInteraction'));
}
/**
* @depends testGetAPI
*/
public function testCheckFunction() {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
// Wrong function. Function name is absent
$wrong_function = array();
// Try to catch MibewAPIException with
// MibewAPIException::VARIABLE_IS_UNDEFINED_IN_RESULT code
try {
$api->checkFunction($wrong_function);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_FUNCTION_NAME,
$e->getCode()
);
}
// Another wrong function. It have reserved name and second argument in
// MibewAPI::checkFunction() will be true.
$wrong_function = array(
'function' => 'result'
);
// Try to catch MibewAPIException with MibewAPIException::FUNCTION_NAME_RESERVED
// code
try {
$api->checkFunction($wrong_function, true);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::FUNCTION_NAME_RESERVED,
$e->getCode()
);
}
// Another wrong function. It have reserved name, but second argument in
// MibewAPI::checkFunction() will be false as default. Also it have no 'arguments'
// element.
$wrong_function = array(
'function' => 'result'
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_ARGUMENTS code
try {
$api->checkFunction($wrong_function);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_ARGUMENTS,
$e->getCode()
);
}
// Another wrong function. 'arguments' element is an empty array.
$wrong_function = array(
'function' => 'wrong_function',
'arguments' => array()
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_ARGUMENTS code
try {
$api->checkFunction($wrong_function);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_ARGUMENTS,
$e->getCode()
);
}
// Another wrong function. 'arguments' element is not array.
$wrong_function = array(
'function' => 'wrong_function',
'arguments' => 'not an array'
);
// Try to catch MibewAPIException with MibewAPIException::WRONG_ARGUMENTS_TYPE code
try {
$api->checkFunction($wrong_function);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::WRONG_ARGUMENTS_TYPE,
$e->getCode()
);
}
// Another wrong function. The obligatary arguments missed.
$wrong_function = array(
'function' => 'wrong_function',
'arguments' => array(
'x' => 11
)
);
// Try to catch MibewAPIException with
// MibewAPIException::OBLIGATORY_ARGUMENTS_MISSED code
try {
$api->checkFunction($wrong_function);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::OBLIGATORY_ARGUMENTS_MISSED,
$e->getCode()
);
}
// Another wrong function. Some of the obligatary arguments missed.
$wrong_function = array(
'function' => 'wrong_function',
'arguments' => array(
'x' => 11,
'return' => array()
)
);
// Try to catch MibewAPIException with
// MibewAPIException::OBLIGATORY_ARGUMENTS_MISSED code
try {
$api->checkFunction($wrong_function);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::OBLIGATORY_ARGUMENTS_MISSED,
$e->getCode()
);
}
// Correct function
$correct_function = array(
'function' => 'correct_function',
'arguments' => array(
'return' => array('name' => 'alias'),
'references' => array('x' => 1),
'x' => 'argument_from_first_function',
'argument_key' => 'argument_value'
)
);
$api->checkFunction($correct_function);
return $correct_function;
}
/**
* @depends testCheckFunction
*/
public function testCheckRequest($correct_function) {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
// Wrong request. Its 'token' element is absent.
$wrong_request = array();
// Try to catch MibewAPIException with MibewAPIException::EMPTY_TOKEN code
try {
$api->checkRequest($wrong_request);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_TOKEN,
$e->getCode()
);
}
// Wrong request. Its 'token' element is empty.
$wrong_request = array('token' => '');
// Try to catch MibewAPIException with MibewAPIException::EMPTY_TOKEN code
try {
$api->checkRequest($wrong_request);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_TOKEN,
$e->getCode()
);
}
// Wrong request. Its 'function' element is absent.
$wrong_request = array(
'token' => 'some_test_token'
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_FUNCTIONS code
try {
$api->checkRequest($wrong_request);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_FUNCTIONS,
$e->getCode()
);
}
// Wrong request. Its 'function' element is empty.
$wrong_request = array(
'token' => 'some_test_token',
'functions' => array()
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_FUNCTIONS code
try {
$api->checkRequest($wrong_request);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_FUNCTIONS,
$e->getCode()
);
}
// Correct request
$correct_request = array(
'token' => 'some_test_token',
'functions' => array($correct_function, $correct_function)
);
$api->checkRequest($correct_request);
return $correct_request;
}
/**
* @depends testCheckRequest
*/
public function testCheckPackage($correct_request) {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
$trusted_signatures = array('some_trusted_signature');
// Wrong package. Signature element is absent.
$wrong_package = array();
// Try to catch MibewAPIException with MibewAPIException::EMPTY_SIGNATURE code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_SIGNATURE,
$e->getCode()
);
}
// Wrong package. Signature is wrong.
$wrong_package = array('signature' => 'wrong_signature');
// Try to catch MibewAPIException with MibewAPIException::UNTRUSTED_SIGNATURE code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::UNTRUSTED_SIGNATURE,
$e->getCode()
);
}
// Wrong package. Protocol is absent.
$wrong_package = array(
'signature' => 'some_trusted_signature'
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_PROTOCOL code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_PROTOCOL,
$e->getCode()
);
}
// Wrong package. Protocol is empty.
$wrong_package = array(
'signature' => 'some_trusted_signature',
'proto' => ''
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_PROTOCOL code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_PROTOCOL,
$e->getCode()
);
}
// Wrong package. Protocol is wrong.
$wrong_package = array(
'signature' => 'some_trusted_signature',
'proto' => 'wrong_protocol'
);
// Try to catch MibewAPIException with MibewAPIException::WRONG_PROTOCOL_VERSION
// code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::WRONG_PROTOCOL_VERSION,
$e->getCode()
);
}
// Wrong package. 'async' flag is absent.
$wrong_package = array(
'signature' => 'some_trusted_signature',
'proto' => MibewAPI::PROTOCOL_VERSION
);
// Try to catch MibewAPIException with MibewAPIException::ASYNC_FLAG_MISSED code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::ASYNC_FLAG_MISSED,
$e->getCode()
);
}
// Wrong package. 'async' flag is wrong.
$wrong_package = array(
'signature' => 'some_trusted_signature',
'proto' => MibewAPI::PROTOCOL_VERSION,
'async' => 'wrong_async_flag'
);
// Try to catch MibewAPIException with MibewAPIException::WRONG_ASYNC_FLAG_VALUE
// code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::WRONG_ASYNC_FLAG_VALUE,
$e->getCode()
);
}
// Wrong package. Requests is absent.
$wrong_package = array(
'signature' => 'some_trusted_signature',
'proto' => MibewAPI::PROTOCOL_VERSION,
'async' => false
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_REQUESTS code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_REQUESTS,
$e->getCode()
);
}
// Wrong package. Requests is empty.
$wrong_package = array(
'signature' => 'some_trusted_signature',
'proto' => MibewAPI::PROTOCOL_VERSION,
'async' => false,
'requests' => array()
);
// Try to catch MibewAPIException with MibewAPIException::EMPTY_REQUESTS code
try {
$api->checkPackage($wrong_package, $trusted_signatures);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::EMPTY_REQUESTS,
$e->getCode()
);
}
// Correct package.
$correct_package = array(
'signature' => 'some_trusted_signature',
'proto' => MibewAPI::PROTOCOL_VERSION,
'async' => false,
'requests' => array($correct_request, $correct_request)
);
$api->checkPackage($correct_package, $trusted_signatures);
return $correct_package;
}
/**
* @depends testCheckPackage
*/
public function testEncodePackage($correct_package) {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
// Get package values
$requests = $correct_package['requests'];
$signature = $correct_package['signature'];
$async = $correct_package['async'];
// Encode package
$encoded_package = $api->encodePackage($requests, $signature, $async);
$this->assertEquals(
urlencode(json_encode($correct_package)),
$encoded_package
);
return array(
'package' => $correct_package,
'encoded_package' => $encoded_package
);
}
/**
* @depends testEncodePackage
*/
public function testDecodePackage($vars) {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
// Try to catch MibewAPIException with MibewAPIException::NOT_VALID_JSON code
try {
$api->decodePackage(
substr(
$vars['encoded_package'],
// Break package
ceil(strlen($vars['encoded_package']) / 2)
),
array('some_trusted_signature')
);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::NOT_VALID_JSON,
$e->getCode()
);
}
$this->assertEquals(
$vars['package'],
$api->decodePackage(
$vars['encoded_package'],
array('some_trusted_signature')
)
);
}
/**
* @depends testGetAPI
*/
public function testGetResultFunction() {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
// Wrong functions list. More than one result function.
$functions_list = array(
array(
'function' => 'result',
'num' => 1
),
array(
'function' => 'result',
'num' => 2
)
);
// Try to catch MibewAPIException with
// MibewAPIException::RESULT_FUNCTION_ALREADY_EXISTS code
try {
$api->getResultFunction($functions_list, null);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::RESULT_FUNCTION_ALREADY_EXISTS,
$e->getCode()
);
}
// Wrong functions list. Result function not exists, but getResultFunction's second
// argument is true
$functions_list = array();
// Try to catch MibewAPIException with
// MibewAPIException::NO_RESULT_FUNCTION code
try {
$api->getResultFunction($functions_list, true);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::NO_RESULT_FUNCTION,
$e->getCode()
);
}
// Wrong functions list. Result function exists, but getResultFunction's second
// argument is false
$functions_list = array(
array(
'function' => 'result',
'num' => 1
)
);
// Try to catch MibewAPIException with
// MibewAPIException::RESULT_FUNCTION_EXISTS code
try {
$api->getResultFunction($functions_list, false);
$this->fail("Exception must be thrown");
} catch (MibewAPIException $e) {
$this->assertEquals(
MibewAPIException::RESULT_FUNCTION_EXISTS,
$e->getCode()
);
}
// Correct functions list. Result function not exists and getResultFunction's second
// argument is false
$functions_list = array();
$this->assertEquals(null, $api->getResultFunction($functions_list, false));
// Correct functions list. Result function exists and getResultFunction's second
// argument is true
$functions_list = array(
array(
'function' => 'result',
'num' => 1
)
);
$this->assertEquals(
$functions_list[0],
$api->getResultFunction($functions_list, true)
);
// Correct functions list. Result function not exists and getResultFunction's second
// argument is null
$functions_list = array();
$this->assertEquals(null, $api->getResultFunction($functions_list, null));
// Correct functions list. Result function exists and getResultFunction's second
// argument is null
$functions_list = array(
array(
'function' => 'result',
'num' => 1
)
);
$this->assertEquals(
$functions_list[0],
$api->getResultFunction($functions_list, null)
);
}
/**
* @depends testGetAPI
*/
public function testBuildResult() {
$api = MibewAPI::getAPI('MibewAPITestInteraction');
$token = 'some_test_token';
$package = array(
'token' => $token,
'functions' => array(
array(
'function' => 'result',
'arguments' => array(
'references' => array(),
'return' => array(),
'test_argument' => 'test_value'
)
)
)
);
$this->assertEquals(
$package,
$api->buildResult($token, array('test_argument' => 'test_value'))
);
}
}
?>

View File

@ -1,87 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/plugin_manager.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/plugin.php';
/**
* Test class for PluginManager.
* Generated by PHPUnit on 2012-07-17 at 16:09:18.
*/
class PluginManagerTest extends PHPUnit_Framework_TestCase {
public function testLoadPlugins() {
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../plugins/'));
// Try to load plugin that does not exists
// Following code wait for trigger user error, which converts by PHPUnit to an
// Exception
try {
PluginManager::loadPlugins(
array(
array(
'name' => 'missed_plugin'
)
)
);
$this->fail("Exception must be thrown");
} catch(PHPUnit_Framework_Error_Warning $e) {}
// Try to load plugin with an absent plugin in dependences list
// Following code wait for trigger user warning, which converts by PHPUnit to an
// Exception
try {
PluginManager::loadPlugins(
array(
array(
'name' => 'phpunit_autotest_plugin_manager_dependence'
)
)
);
$this->fail("Exception must be thrown");
} catch(PHPUnit_Framework_Error_Warning $e) {}
// Try to load correct plugin
PluginManager::loadPlugins(
array(
array(
'name' => 'phpunit_autotest_plugin_manager'
)
)
);
// Check if plugin initialized correctry
if(empty($GLOBALS['phpunit_autotest_plugin_manager'])) {
$this->fail('Plugin not loaded and initialize correctly');
}
}
/**
* @depends testLoadPlugins
*/
public function testGetPlugin() {
// Try to get plugin with wrong name
// Following code wait for trigger user warning, which converts by PHPUnit to an
// Exception
try {
PluginManager::getPlugin('wrong_plugin_name');
$this->fail("Exception must be thrown");
} catch(Exception $e) {}
// Try to get loaded plugin
PluginManager::getPlugin('phpunit_autotest_plugin_manager');
}
/**
* @depends testGetPlugin
*/
public function testGetAllPlugins() {
// Get loaded plugin
$plugin = PluginManager::getPlugin('phpunit_autotest_plugin_manager');
// Build plugins list to comparison
$plugins_list = array('phpunit_autotest_plugin_manager' => $plugin);
// Check loaded plugins list
$this->assertEquals($plugins_list, PluginManager::getAllPlugins());
}
}
?>

View File

@ -1,462 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/event_dispatcher.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/plugin.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/plugin_manager.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/request_processor.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api_interaction.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/mibew_api_execution_context.php';
require_once dirname(__FILE__) . '/../request_processor_test.php';
require_once dirname(__FILE__) . '/mibew_api_test_interaction.php';
require_once dirname(__FILE__) . '/test_processor.php';
/**
* Test class for RequestProcessor.
* Generated by PHPUnit on 2012-09-21 at 19:05:21.
*/
class RequestProcessorTest extends PHPUnit_Framework_TestCase {
/**
* @var RequestProcessor
*/
protected static $object;
/**
* @var MibewAPI
*/
protected static $mibewAPI;
/**
* @var Request_processor_testPlugin
*/
protected static $plugin;
public static function setUpBeforeClass() {
// Load Mibew API
self::$mibewAPI = MibewAPI::getAPI('MibewAPITestInteraction');
// Initialize TestProcessor object
self::$object = new TestProcessor(array(
'signature' => 'valid_signature',
'trusted_signatures' => array('trusted_signature')
));
// Initialize events listener plugin
set_include_path(get_include_path() . PATH_SEPARATOR . realpath(dirname(__FILE__) . '/../../plugins/'));
PluginManager::loadPlugins(
array(
array('name' => 'request_processor_test')
)
);
self::$plugin = PluginManager::getPlugin('request_processor_test');
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp() {}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown() {}
public function test__construct() {
// Try to get error with undefined signature
try {
new TestProcessor(
array(
'trusted_signatures' => array('')
)
);
$this->fail('Error must be thrown');
} catch(PHPUnit_Framework_Error $e) {}
// Try to get error with undefined trusted signatures
try {
new TestProcessor(
array('signature' => '')
);
$this->fail('Error must be thrown');
} catch(PHPUnit_Framework_Error $e) {}
// Try to create object
$processor = new TestProcessor(
array(
'signature' => '',
'trusted_signatures' => array(''),
'event_prefix' => '_testProcessor'
)
);
unset($processor);
}
public function testReceiveRequest() {
// Test signature check
// Create request
$package = self::$mibewAPI->encodePackage(
array(
array(
'token' => 'test',
'functions' => array(
array(
'function' => 'test',
'arguments' => array(
'return' => array(),
'references' => array()
)
)
)
)
),
'wrong signature',
false
);
// Process request and check result
$this->assertFalse(self::$object->receiveRequest($package));
// Check plugin call list
$this->assertEquals(array('testRequestError'), self::$plugin->callList);
self::$plugin->callList = array();
// Check error code
$this->assertEquals(MibewAPIException::UNTRUSTED_SIGNATURE, self::$plugin->errorCode);
// Check TestProcessor call list
$this->assertEquals(array(), self::$object->callList);
// Test synchronous request
// Create request
$package = self::$mibewAPI->encodePackage(
array(
array(
'token' => 'sync_call_test',
'functions' => array(
array(
'function' => 'call_func',
'arguments' => array(
'return' => array('processorCall' => 'processorCall', 'pluginCall' => 'pluginCall'),
'references' => array()
)
)
)
)
),
'trusted_signature',
false
);
// Process request and check result
$this->assertTrue(self::$object->receiveRequest($package));
// Check plugin call list
$this->assertEquals(array('testRequestReceived', 'testFunctionCall'), self::$plugin->callList);
self::$plugin->callList = array();
// Check TestProcessor call list
$this->assertEquals(
array(
'processRequest',
'processFunction',
'processorCall',
'sendSyncResponses'
),
self::$object->callList
);
self::$object->callList = array();
// Check response
$this->assertEquals(
array(
array(
'token' => 'sync_call_test',
'functions' => array(
array(
'function' => 'result',
'arguments' => array(
'processorCall' => true,
'pluginCall' => true,
'return' => array(),
'references' => array()
)
)
)
)
),
self::$object->responses
);
self::$object->responses = array();
// Test first asynchronous request (no callbacks and no result function)
// Create request
$package = self::$mibewAPI->encodePackage(
array(
array(
'token' => 'async_call_test',
'functions' => array(
array(
'function' => 'call_func',
'arguments' => array(
'return' => array('processorCall' => 'processorCall', 'pluginCall' => 'pluginCall'),
'references' => array()
)
)
)
)
),
'trusted_signature',
true
);
// Process request and check result
$this->assertTrue(self::$object->receiveRequest($package));
// Check plugin call list
$this->assertEquals(array('testRequestReceived', 'testFunctionCall'), self::$plugin->callList);
self::$plugin->callList = array();
// Check TestProcessor call list
$this->assertEquals(
array(
'loadCallback',
'processRequest',
'processFunction',
'processorCall',
'sendAsyncResponses'
),
self::$object->callList
);
self::$object->callList = array();
// Check response
$this->assertEquals(
array(
array(
'token' => 'async_call_test',
'functions' => array(
array(
'function' => 'result',
'arguments' => array(
'processorCall' => true,
'pluginCall' => true,
'return' => array(),
'references' => array()
)
)
)
)
),
self::$object->responses
);
self::$object->responses = array();
// Test asynchronous request with result function and no callback
// Create request
$package = self::$mibewAPI->encodePackage(
array(
array(
'token' => 'result_only_test',
'functions' => array(
array(
'function' => 'result',
'arguments' => array(
'test_argument' => 'test_value',
'return' => array(),
'references' => array()
)
)
)
)
),
'trusted_signature',
true
);
// Process request and check result
$this->assertTrue(self::$object->receiveRequest($package));
// Check plugin call list
$this->assertEquals(array('testRequestReceived'), self::$plugin->callList);
self::$plugin->callList = array();
// Check TestProcessor call list
$this->assertEquals(array('loadCallback'), self::$object->callList);
self::$object->callList = array();
// Check response
$this->assertEmpty(self::$object->responses);
// Test asynchronous request with callback and no result function
// Create request
$package = self::$mibewAPI->encodePackage(
array(
array(
'token' => 'callback_only_test',
'functions' => array(
array(
'function' => 'not_result',
'arguments' => array(
'test_argument' => 'test_value',
'return' => array(),
'references' => array()
)
)
)
)
),
'trusted_signature',
true
);
// Process request and check result
$this->assertFalse(self::$object->receiveRequest($package));
// Check plugin call list
$this->assertEquals(array('testRequestReceived', 'testRequestError'), self::$plugin->callList);
self::$plugin->callList = array();
// Check error code
$this->assertEquals(MibewAPIException::NO_RESULT_FUNCTION, self::$plugin->errorCode);
// Check TestProcessor call list
$this->assertEquals(array('loadCallback', 'processRequest'), self::$object->callList);
self::$object->callList = array();
// Check response
$this->assertEmpty(self::$object->responses);
// Test asynchronous request with callback and result function
// Create request
$package = self::$mibewAPI->encodePackage(
array(
array(
'token' => 'callback_and_result_test',
'functions' => array(
array(
'function' => 'result',
'arguments' => array(
'first' => true,
'return' => array(),
'references' => array()
)
)
)
)
),
'trusted_signature',
true
);
// Process request and check result
$this->assertTrue(self::$object->receiveRequest($package));
// Check plugin call list
$this->assertEquals(array('testRequestReceived', 'testRequestProcessorCallback'), self::$plugin->callList);
self::$plugin->callList = array();
// Check callback arguments
$this->assertEquals(
array(
'first' => true,
'second' => true, // Set in TestProcessor::loadCallback method
'return' => array(),
'references' => array()
),
self::$plugin->callbackArguments
);
self::$plugin->callbackArguments = array();
// Check TestProcessor call list
$this->assertEquals(array('loadCallback', 'processRequest'), self::$object->callList);
self::$object->callList = array();
// Check response
$this->assertEmpty(self::$object->responses);
}
public function testCall() {
// Check call to not a function
// Call function
$this->assertFalse(self::$object->call('', true));
// Check plugin call list
$this->assertEquals(array('testCallError'), self::$plugin->callList);
self::$plugin->callList = array();
// Check error code
$this->assertEquals(RequestProcessorException::WRONG_ARGUMENTS, self::$plugin->errorCode);
// Check TestProcessor call list
$this->assertEmpty(self::$object->callList);
// Check call to wrong function array. Only empty function's arguments checked. Other errors tested with
// MibewAPI class.
// Specify function
$function = array(
'function' => 'not a function'
);
// Call function
$this->assertFalse(self::$object->call(array($function), true));
// Check plugin call list
$this->assertEquals(array('testCallError'), self::$plugin->callList);
self::$plugin->callList = array();
// Check error code
$this->assertEquals(MibewAPIException::EMPTY_ARGUMENTS, self::$plugin->errorCode);
// Check TestProcessor call list
$this->assertEmpty(self::$object->callList);
// Check asynchronous request
// Specify function
$function = array(
'function' => 'test_func',
'arguments' => array(
'return' => array(),
'references' => array()
)
);
// Call function
$this->assertTrue(
self::$object->call(
array($function),
true,
array('function' => 'callback', 'arguments' => array())
)
);
// Check plugin call list
$this->assertEquals(array(), self::$plugin->callList);
self::$plugin->callList = array();
// Check TestProcessor call list
$this->assertEquals(array('saveCallback', 'sendAsyncRequest'), self::$object->callList);
self::$object->callList = array();
// Check synchronous request with function that have result in response package
// Specify function
$function = array(
'function' => 'return_result',
'arguments' => array(
'return' => array(),
'references' => array()
)
);
// Call function
$this->assertNotEquals(false, self::$object->call(array($function), false));
// Check plugin call list
$this->assertEquals(array('testResponseReceived'), self::$plugin->callList);
self::$plugin->callList = array();
// Check TestProcessor call list
$this->assertEquals(
array('sendSyncRequest', 'processRequest'),
self::$object->callList
);
self::$object->callList = array();
// Check synchronous request with function that have no result in response package
// Specify function
$function = array(
'function' => 'some_test_func',
'arguments' => array(
'return' => array(),
'references' => array()
)
);
// Call function
$this->assertFalse(self::$object->call(array($function), false));
// Check plugin call list
$this->assertEquals(array('testResponseReceived', 'testCallError'), self::$plugin->callList);
self::$plugin->callList = array();
// Check error code
$this->assertEquals(MibewAPIException::NO_RESULT_FUNCTION, self::$plugin->errorCode);
// Check TestProcessor call list
$this->assertEquals(
array('sendSyncRequest', 'processRequest'),
self::$object->callList
);
self::$object->callList = array();
}
}
?>

View File

@ -1,80 +0,0 @@
<?php
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/settings.php';
require_once dirname(__FILE__) . '/../../../../../mibew/libs/classes/database.php';
require_once dirname(__FILE__) . '/../config.php';
/**
* Test class for Settings.
* Generated by PHPUnit on 2012-07-16 at 15:07:10.
*/
class SettingsTest extends PHPUnit_Framework_TestCase {
public static function setUpBeforeClass() {
global $db_host, $db_name, $db_user, $db_pass, $tables_prefix,
$db_encoding, $force_charset_in_connection, $use_persistent_connection;
Database::initialize(
$db_host,
$db_user,
$db_pass,
$use_persistent_connection,
$db_name,
$tables_prefix,
$force_charset_in_connection,
$db_encoding
);
$db = Database::getInstance();
$db->query(
"INSERT INTO {chatconfig} (vckey, vcvalue) " .
"VALUES (?, ?)",
array('some_test_key', 'some_test_value')
);
}
public static function tearDownAfterClass() {
$db = Database::getInstance();
$db->query(
"DELETE FROM {chatconfig} WHERE vckey = ? OR vckey = ?",
array('some_test_key', 'some_another_test_key')
);
Database::destroy();
}
public function testGet() {
$this->assertEquals('some_test_value', Settings::get('some_test_key'));
}
public function testSet() {
Settings::set('some_test_key', 'some_another_value');
$this->assertEquals('some_another_value', Settings::get('some_test_key'));
Settings::set('some_test_key', 'some_test_value');
}
public function testUpdate() {
$db = Database::getInstance();
Settings::set('some_test_key', 'some_value_for_update');
Settings::set('some_another_test_key', 'some_another_value_for_update');
Settings::update();
list($count) = $db->query(
"SELECT COUNT(*) FROM {chatconfig} WHERE vckey = ? AND vcvalue = ?",
array('some_test_key', 'some_value_for_update'),
array(
'return_rows' => Database::RETURN_ONE_ROW,
'fetch_type' => Database::FETCH_NUM
)
);
$this->assertEquals(1, $count);
list($count) = $db->query(
"SELECT COUNT(*) FROM {chatconfig} WHERE vckey = ? AND vcvalue = ?",
array('some_another_test_key', 'some_another_value_for_update'),
array(
'return_rows' => Database::RETURN_ONE_ROW,
'fetch_type' => Database::FETCH_NUM
)
);
$this->assertEquals(1, $count);
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
<?php
/**
* Test interaction type for the Mibew API
*/
class MibewAPITestInteraction extends MibewAPIInteraction {
protected $obligatoryArguments = array(
'*' => array(
'return' => array(),
'references' => array()
),
'foo' => array(
'bar' => 127
)
);
public $reservedFunctionNames = array(
'result'
);
}
?>

View File

@ -1,115 +0,0 @@
<?php
class TestProcessor extends RequestProcessor {
public $callList = array();
public $responses = array();
public function __construct($config = array()) {
$config += array(
'event_prefix' => 'test'
);
parent::__construct($config);
}
protected function getMibewAPIInstance() {
return MibewAPI::getAPI('MibewAPITestInteraction');
}
protected function processRequest($request, $result_function = null) {
array_push($this->callList, 'processRequest');
return parent::processRequest($request, $result_function);
}
protected function processFunction($function, MibewAPIExecutionContext &$context) {
array_push($this->callList, 'processFunction');
return parent::processFunction($function, $context);
}
/**
* @todo Think about callbacks saving
*/
protected function saveCallback($token, $callback) {
array_push($this->callList, 'saveCallback');
}
protected function loadCallback($token) {
array_push($this->callList, 'loadCallback');
if ($token == 'callback_only_test') {
return array('function' => 'time', 'arguments' => array());
} elseif($token == 'callback_and_result_test') {
return array('function' => 'request_processor_callback', 'arguments' => array('second' => true));
}
return null;
}
protected function sendSyncRequest($request) {
array_push($this->callList, 'sendSyncRequest');
$return_result = false;
foreach ($request['functions'] as $function) {
if ($function['function'] == 'return_result') {
$return_result = true;
break;
}
}
if ($return_result) {
return array(
'requests' => array(
array(
'token' => $request['token'],
'functions' => array(
array(
'function' => 'result',
'arguments' => array(
'some_argument' => 'some_value',
'return' => array(),
'references' => array()
)
)
)
)
)
);
}
return array(
'requests' => array(
array(
'token' => $request['token'],
'functions' => array(
array(
'function' => 'not_a_result',
'arguments' => array(
'some_argument' => 'some_value',
'return' => array(),
'references' => array()
)
)
)
)
)
);
}
protected function sendAsyncRequest($request) {
array_push($this->callList, 'sendAsyncRequest');
}
protected function sendSyncResponses($responses) {
array_push($this->callList, 'sendSyncResponses');
$this->responses = $responses;
}
protected function sendAsyncResponses($responses) {
array_push($this->callList, 'sendAsyncResponses');
}
protected function processorCall(&$func) {
array_push($this->callList, 'processorCall');
if ($func['function'] == 'call_func') {
$func['results']['processorCall'] = true;
}
}
}
?>

View File

@ -1,13 +0,0 @@
<?php
class ThreadProcessor {
public static function getInstance() {
return new self();
}
public function call($functions = null, $callback = null) {
return true;
}
}
?>

View File

@ -1,28 +0,0 @@
<?php
/**
* Database parameters
*
* WARNING: Do not use the same values as in the mibew config file!
* Tests may truncate databses they use and all data will be lost!
*
* Use at least default $tables prefix
*/
$db_host = "";
$db_user = "";
$db_pass = "";
$db_name = "";
$tables_prefix = "";
$db_encoding = "utf8";
$force_charset_in_connection = true;
$use_persistent_connection = false;
/*
* Locales
*/
$home_locale = "en"; /* native name will be used in this locale */
$default_locale = "en"; /* if user does not provide known lang */
?>

View File

@ -1,8 +0,0 @@
<?php
function request_processor_callback($arguments) {
$dispatcher = EventDispatcher::getInstance();
$dispatcher->triggerEvent('testRequestProcessorCallback', $arguments);
}
?>

View File

@ -1,29 +0,0 @@
<?php
/**
* Test plugin for PHPUnit tests
*/
Class PhpunitAutotestPluginManagerPlugin extends Plugin{
public $listenersRegistered = false;
public function getWeight() {
return 10;
}
public function registerListeners() {
$this->listenersRegistered = true;
$GLOBALS['phpunit_autotest_plugin_manager'] = true;
}
public function testEventListener(&$vars) {
$vars['test'] = 'some_test_value';
}
public function __construct(){
$this->initialized = true;
}
}
?>

View File

@ -1,26 +0,0 @@
<?php
/**
* Test plugin for PHPUnit tests
*/
Class PhpunitAutotestPluginManagerDependencePlugin extends Plugin{
public $listenersRegistered = false;
public function getWeight() {
return 10;
}
public function registerListeners() {}
public static function getDependences() {
return array('some_missed_dependence');
}
public function __construct(){
$this->initialized = true;
}
}
?>

View File

@ -1,68 +0,0 @@
<?php
/**
* Test plugin for PHPUnit tests
*/
Class RequestProcessorTestPlugin extends Plugin{
public $callList = array();
public $errorCode = 0;
public $callbackArguments = array();
public function __construct() {
$this->initialized = true;
}
public function getWeight() {
return 10;
}
public function registerListeners() {
$processor_events = array(
'testRequestReceived',
'testRequestError',
'testResponseReceived',
'testCallError',
'testFunctionCall',
'testRequestProcessorCallback'
);
$dispatcher = EventDispatcher::getInstance();
foreach ($processor_events as $event) {
$dispatcher->attachListener($event, $this, $event);
}
}
public function testRequestReceived(&$arguments) {
array_push($this->callList, 'testRequestReceived');
}
public function testRequestError(&$arguments) {
array_push($this->callList, 'testRequestError');
$this->errorCode = $arguments['exception']->getCode();
}
public function testResponseReceived(&$arguments) {
array_push($this->callList, 'testResponseReceived');
}
public function testCallError(&$arguments) {
array_push($this->callList, 'testCallError');
$this->errorCode = $arguments['exception']->getCode();
}
public function testFunctionCall(&$arguments) {
array_push($this->callList, 'testFunctionCall');
if ($arguments['function'] == 'call_func') {
$arguments['results']['pluginCall'] = true;
}
}
public function testRequestProcessorCallback(&$arguments) {
array_push($this->callList, 'testRequestProcessorCallback');
$this->callbackArguments = $arguments;
}
}
?>