From 7ce675da86a469101781e0d5eb3c2591507c4a44 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 11 Jul 2014 13:10:18 +0000 Subject: [PATCH] Remove outdated PHPUnit tests Need new good tests. --- src/tests/server_side/.keep | 0 .../webim/libs/classes/DatabaseTest.php | 208 --- .../libs/classes/EventDispatcherTest.php | 104 -- .../classes/MibewAPIExecutionContextTest.php | 167 --- .../libs/classes/MibewAPIInteractionTest.php | 61 - .../webim/libs/classes/MibewAPITest.php | 607 -------- .../webim/libs/classes/PluginManagerTest.php | 87 -- .../libs/classes/RequestProcessorTest.php | 462 ------ .../webim/libs/classes/SettingsTest.php | 80 -- .../webim/libs/classes/ThreadTest.php | 1273 ----------------- .../classes/mibew_api_test_interaction.php | 24 - .../webim/libs/classes/test_processor.php | 115 -- .../libs/classes/thread_processor_mock.php | 13 - .../server_side/webim/libs/default_config.php | 28 - .../webim/libs/request_processor_test.php | 8 - ...phpunit_autotest_plugin_manager_plugin.php | 29 - ...otest_plugin_manager_dependence_plugin.php | 26 - .../request_processor_test_plugin.php | 68 - 18 files changed, 3360 deletions(-) create mode 100644 src/tests/server_side/.keep delete mode 100644 src/tests/server_side/webim/libs/classes/DatabaseTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/EventDispatcherTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/MibewAPIExecutionContextTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/MibewAPIInteractionTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/MibewAPITest.php delete mode 100644 src/tests/server_side/webim/libs/classes/PluginManagerTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/RequestProcessorTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/SettingsTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/ThreadTest.php delete mode 100644 src/tests/server_side/webim/libs/classes/mibew_api_test_interaction.php delete mode 100644 src/tests/server_side/webim/libs/classes/test_processor.php delete mode 100644 src/tests/server_side/webim/libs/classes/thread_processor_mock.php delete mode 100644 src/tests/server_side/webim/libs/default_config.php delete mode 100644 src/tests/server_side/webim/libs/request_processor_test.php delete mode 100644 src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager/phpunit_autotest_plugin_manager_plugin.php delete mode 100644 src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager_dependence/phpunit_autotest_plugin_manager_dependence_plugin.php delete mode 100644 src/tests/server_side/webim/plugins/request_processor_test/request_processor_test_plugin.php diff --git a/src/tests/server_side/.keep b/src/tests/server_side/.keep new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/server_side/webim/libs/classes/DatabaseTest.php b/src/tests/server_side/webim/libs/classes/DatabaseTest.php deleted file mode 100644 index 36965868..00000000 --- a/src/tests/server_side/webim/libs/classes/DatabaseTest.php +++ /dev/null @@ -1,208 +0,0 @@ -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()); - } - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/EventDispatcherTest.php b/src/tests/server_side/webim/libs/classes/EventDispatcherTest.php deleted file mode 100644 index a7050be6..00000000 --- a/src/tests/server_side/webim/libs/classes/EventDispatcherTest.php +++ /dev/null @@ -1,104 +0,0 @@ -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']); - } - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/MibewAPIExecutionContextTest.php b/src/tests/server_side/webim/libs/classes/MibewAPIExecutionContextTest.php deleted file mode 100644 index cb6a54c5..00000000 --- a/src/tests/server_side/webim/libs/classes/MibewAPIExecutionContextTest.php +++ /dev/null @@ -1,167 +0,0 @@ - '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 - ); - } - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/MibewAPIInteractionTest.php b/src/tests/server_side/webim/libs/classes/MibewAPIInteractionTest.php deleted file mode 100644 index 573a40d6..00000000 --- a/src/tests/server_side/webim/libs/classes/MibewAPIInteractionTest.php +++ /dev/null @@ -1,61 +0,0 @@ -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 - ) - ); - } -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/MibewAPITest.php b/src/tests/server_side/webim/libs/classes/MibewAPITest.php deleted file mode 100644 index c8f6429c..00000000 --- a/src/tests/server_side/webim/libs/classes/MibewAPITest.php +++ /dev/null @@ -1,607 +0,0 @@ -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')) - ); - } -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/PluginManagerTest.php b/src/tests/server_side/webim/libs/classes/PluginManagerTest.php deleted file mode 100644 index a1c2ff44..00000000 --- a/src/tests/server_side/webim/libs/classes/PluginManagerTest.php +++ /dev/null @@ -1,87 +0,0 @@ - '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()); - } -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/RequestProcessorTest.php b/src/tests/server_side/webim/libs/classes/RequestProcessorTest.php deleted file mode 100644 index 4257d0c3..00000000 --- a/src/tests/server_side/webim/libs/classes/RequestProcessorTest.php +++ /dev/null @@ -1,462 +0,0 @@ - '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(); - } - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/SettingsTest.php b/src/tests/server_side/webim/libs/classes/SettingsTest.php deleted file mode 100644 index e005f060..00000000 --- a/src/tests/server_side/webim/libs/classes/SettingsTest.php +++ /dev/null @@ -1,80 +0,0 @@ -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); - } - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/ThreadTest.php b/src/tests/server_side/webim/libs/classes/ThreadTest.php deleted file mode 100644 index e4080a90..00000000 --- a/src/tests/server_side/webim/libs/classes/ThreadTest.php +++ /dev/null @@ -1,1273 +0,0 @@ -query( - "SELECT COUNT(*) FROM {chatmessage} " . - "WHERE ikind = :kind AND tmessage = :message AND messageid > :last_msg_id", - array( - ':kind' => $kind, - ':message' => $message, - ':last_msg_id' => $last_msg_id - ), - array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM) - ); - return $count; - } - - /** - * Get total message count from database - * - * @param int $last_msg_id Message id to start search from - * @return int Messages count - */ - protected function _helper_getTotalMessagesCount($last_msg_id) { - $db = Database::getInstance(); - list($count) = $db->query( - "SELECT COUNT(*) FROM {chatmessage} WHERE messageid > :last_msg_id", - array(':last_msg_id' => $last_msg_id), - array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM) - ); - return $count; - } - - /** - * Returns last message id - * - * @return int Id of the last message - */ - protected function _helper_getLastMessageId() { - $db = Database::getInstance(); - list($last_msg_id) = $db->query( - "SELECT MAX(messageid) FROM {chatmessage}", - NULL, - array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM) - ); - if (! $last_msg_id) { - $last_msg_id = 0; - } - return $last_msg_id; - } - - /** - * Get threads count with specified thread id - * - * @param int $thread_id Id of the thread - * @return int Count of threads - */ - protected function _helper_getThreadCount($thread_id) { - $db = Database::getInstance(); - list($count) = $db->query( - "SELECT COUNT(*) FROM {chatthread} WHERE threadid = :id", - array(':id' => $thread_id), - array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM) - ); - return $count; - } - - /** - * Get thread info from database - * - * @param int $thread_id Id of the thread - * @return array Thread info - */ - protected function _helper_getThreadInfo($thread_id) { - $db = Database::getInstance(); - return $db->query( - "SELECT * FROM {chatthread} WHERE threadid = :id", - array(':id' => $thread_id), - array('return_rows' => Database::RETURN_ONE_ROW) - ); - } - - public static function setUpBeforeClass() { - // Initialize database object - 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(); - // Clear tables - $db->query("TRUNCATE {chatthread}"); - $db->query("TRUNCATE {chatmessage}"); - self::$thread_lifetime = Settings::get('thread_lifetime'); - Settings::set('thread_lifetime', 600); - } - - public static function tearDownAfterClass() { - $db = Database::getInstance(); - // Clear tables - $db->query("TRUNCATE {chatthread}"); - $db->query("TRUNCATE {chatmessage}"); - Settings::set('thread_lifetime', self::$thread_lifetime); - // Destroy Database object - Database::destroy(); - } - - public function testCreate() { - // Create thread - $thread = Thread::create(); - - // Check thread - $this->assertNotEmpty($thread); - $this->assertNotEmpty($thread->id); - $this->assertNotEmpty($thread->lastToken); - - // Check if thread in database - $this->assertEquals(1, $this->_helper_getThreadCount($thread->id)); - - $threadid = $thread->id; - unset($thread); - return $threadid; - } - - /** - * @depends testCreate - */ - public function testLoad($threadid) { - // Load thread - $thread = Thread::load($threadid); - - // Check thread - $this->assertNotEmpty($thread); - $this->assertEquals($threadid, $thread->id); - - return $thread; - } - - /** - * @depends testLoad - */ - public function testDelete(Thread $thread) { - $threadid = $thread->id; - - // Check if thread in database - $this->assertEquals(1, $this->_helper_getThreadCount($threadid)); - - // Delete thread - $thread->delete(); - unset($thread); - - // Check thread in database - $this->assertEquals(0, $this->_helper_getThreadCount($threadid)); - } - - public function testCreateFromDbInfo() { - // Check incomplete fields list - $fields_list = array( - 'threadid' => 1 - ); - $thread = Thread::createFromDbInfo($fields_list); - $this->assertFalse($thread); - - // Check complete fields list - $fields_list = array( - 'threadid' => 10, - - 'lrevision' => 189, - 'istate' => Thread::STATE_QUEUE, - 'invitationstate' => Thread::INVITATION_NOT_INVITED, - 'ltoken' => 19908, - - 'nextagent' => 0, - 'groupid' => 0, - - 'shownmessageid' => 0, - 'messageCount' => 0, - - 'dtmcreated' => time() - 100, - 'dtmmodified' => time() - 90, - 'dtmchatstarted' => 0, - 'dtmclosed' => time(), - - 'agentId' => 0, - 'agentName' => '', - 'agentTyping' => 0, - 'lastpingagent' => 0, - - 'locale' => 'en', - - 'userid' => 1112, - 'userName' => 'Guest', - 'userTyping' => 0, - 'lastpinguser' => time() - 10, - - 'remote' => '127.0.0.1', - 'referer' => 'http://google.com', - 'userAgent' => 'Mozilla FireFox' - ); - $thread = Thread::createFromDbInfo($fields_list); - $this->assertInstanceOf('Thread', $thread); - - unset($thread); - } - - public function test__isset() { - // Create new thread - $thread = Thread::create(); - - // Property exists and not empty - $this->assertNotEmpty($thread->id); - - // assertTrue use instead of assertEmpty because of PHPUnit don't work correctly with __isset magic method - - // Property exists in internal Thread::$propertyMap property but not set - $this->assertTrue(empty($thread->lastRevision)); - $this->assertFalse(isset($thread->lastRevision)); - - // Property does not exists - $this->assertTrue(empty($thread->someFakeProp)); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function test__set() { - // Create thread - $thread = Thread::create(); - - // Try to set value for unexistent property - // Following code wait for trigger user notice, which converts by PHPUnit to an - // Exception - try { - $thread->someFakeField = 'some_test_value'; - $this->fail("Exception must be thrown"); - } catch(Exception $e) {} - - // Try to set exist property - $thread->lastToken = 129; - - return $thread; - } - - /** - * @depends test__set - */ - public function test__get(Thread $thread) { - // Check property value from test_set() method - $this->assertEquals(129, $thread->lastToken); - - // Try to get value of unexistent property - // Following code wait for trigger user notice, which converts by PHPUnit to an - // Exception - try { - $some_value = $thread->someFakeField; - $this->fail("Exception must be thrown"); - } catch(Exception $e) {} - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testSave() { - // Create new thread - $thread = Thread::create(); - - // Update thread values - $thread->state = $state = Thread::STATE_CHATTING; - $thread->lastToken = $last_token = 11; - - $thread->nextAgent = $next_agent = 12; - $thread->groupId = $group_id = 13; - - $thread->shownMessageId = $shown_message_id = 14; - $thread->messageCount = $message_count = 15; - - $thread->created = $created = time() - 200; - $thread->chatStarted = $chat_started = time() - 180; - - $thread->agentId = $agent_id = 16; - $thread->agentName = $agent_name = '17'; - $thread->agentTyping = $agent_typing = 0; - $thread->lastPingAgent = $last_ping_agent = time() - 170; - - $thread->locale = $locale = '18'; - - $thread->userId = $user_id = 19; - $thread->userName = $user_name = '20'; - $thread->userTyping = $user_tiping = 1; - $thread->lastPingUser = $last_user_ping = time() - 160; - - $thread->remote = $remote = '21'; - $thread->referer = $referer = '22'; - $thread->userAgent = $user_agent = '23'; - - - // Save thread - $thread->save(); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - - // Check values - $this->assertEquals($thread_info['istate'], $state); - $this->assertEquals($thread_info['ltoken'], $last_token); - - $this->assertEquals($thread_info['nextagent'], $next_agent); - $this->assertEquals($thread_info['groupid'], $group_id); - - $this->assertEquals($thread_info['shownmessageid'], $shown_message_id); - $this->assertEquals($thread_info['messageCount'], $message_count); - - $this->assertEquals($thread_info['dtmcreated'], $created); - $this->assertEquals($thread_info['dtmchatstarted'], $chat_started); - - $this->assertEquals($thread_info['agentId'], $agent_id); - $this->assertEquals($thread_info['agentName'], $agent_name); - $this->assertEquals($thread_info['agentTyping'], $agent_typing); - $this->assertEquals($thread_info['lastpingagent'], $last_ping_agent); - - $this->assertEquals($thread_info['locale'], $locale); - - $this->assertEquals($thread_info['userid'], $user_id); - $this->assertEquals($thread_info['userName'], $user_name); - $this->assertEquals($thread_info['userTyping'], $user_tiping); - $this->assertEquals($thread_info['lastpinguser'], $last_user_ping); - - $this->assertEquals($thread_info['remote'], $remote); - $this->assertEquals($thread_info['referer'], $referer); - $this->assertEquals($thread_info['userAgent'], $user_agent); - - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testReopen() { - global $home_locale; - - $db = Database::getInstance(); - - // Create new thread - $thread = Thread::create(); - $thread->state = Thread::STATE_CHATTING; - $thread->locale = $home_locale; - $thread->lastPingAgent = time() - Settings::get('thread_lifetime') * 2; - $thread->lastPingUser = time() - Settings::get('thread_lifetime') * 2; - $thread->save(); - - - // Last ping was more than life_time ago - $this->assertFalse(Thread::reopen($thread->id)); - - - // Try reopen closed thread - $thread->state = Thread::STATE_CLOSED; - $thread->lastPingAgent = time(); - $thread->lastPingUser = time(); - $thread->save(); - $this->assertFalse(Thread::reopen($thread->id)); - - - // Try to reopen left thread - $thread->state = Thread::STATE_LEFT; - $thread->save(); - $this->assertFalse(Thread::reopen($thread->id)); - - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // Try to reopen thread with Thread::STATE_WAITING state - $thread->nextAgent = 2; - $thread->state = Thread::STATE_WAITING; - $thread->save(); - - $another_thread = Thread::reopen($thread->id); - $this->assertNotEmpty($another_thread); - - // Load another thread info - $thread_info = $this->_helper_getThreadInfo($another_thread->id); - // Check next agent field - $this->assertEquals(0, $another_thread->nextAgent); - $this->assertEquals(0, $thread_info['nextagent']); - - // Check sent messages - $message_count = $this->_helper_getTotalMessagesCount($last_msg_id); - $this->assertEquals(1, $message_count); - - // Check message text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring_("chat.status.user.reopenedthread", $another_thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - unset($another_thread); - - - // Reload thread because values in database was changed - // in Thread::reopen method called above, but values in $thread object - // are still the same - $thread = Thread::load($thread->id); - - // Try to reopen thread with Thread::STATE_QUEUE state - $thread->nextAgent = 2; - $thread->state = Thread::STATE_QUEUE; - $thread->save(); - - $another_thread = Thread::reopen($thread->id); - $this->assertNotEmpty($another_thread); - - // Load another thread info - $thread_info = $this->_helper_getThreadInfo($another_thread->id); - // Check next agent field - $this->assertEquals(2, $another_thread->nextAgent); - $this->assertEquals(2, $thread_info['nextagent']); - - unset($another_thread); - - // Check equlity of treads returned by reopen method and returned by load method - $thread_id = $thread->id; - unset($thread); - $thread = Thread::load($thread_id); - $another_thread = Thread::reopen($thread_id); - $this->assertEquals($thread, $another_thread); - unset($another_thread); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testCloseOldThreads() { - $timeout = Settings::get('thread_lifetime'); - - // Create new thread - $thread = Thread::create(); - - - // Try to close thread with state = Thread::STATE_CHATTING and time no timeout - // Update values - $thread->state = Thread::STATE_CHATTING; - $thread->lastPingAgent = time(); - $thread->lastPingUser = time(); - // Save thread - $thread->save(); - // And close all threads - Thread::closeOldThreads(); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertNotEquals($thread_info['istate'], Thread::STATE_CLOSED); - - - // Try to close thread with timeout for user and no timeout for agent - // Update values - $thread->state = Thread::STATE_CHATTING; - $thread->lastPingAgent = time(); - $thread->lastPingUser = time() - $timeout * 2; - // Save thread - $thread->save(); - // And close all threads - Thread::closeOldThreads(); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertNotEquals($thread_info['istate'], Thread::STATE_CLOSED); - - - // Try to close thread with timeout for agent and no timeout for user - // Update values - $thread->state = Thread::STATE_CHATTING; - $thread->lastPingAgent = time() - $timeout * 2; - $thread->lastPingUser = time(); - // Save thread - $thread->save(); - // And close all threads - Thread::closeOldThreads(); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertNotEquals($thread_info['istate'], Thread::STATE_CLOSED); - - - // Try to close thread with timeout for agent and timeout for user - // Update values - $thread->state = Thread::STATE_CHATTING; - $thread->lastPingAgent = time() - $timeout * 2; - $thread->lastPingUser = time() - $timeout * 2; - // Save thread - $thread->save(); - // And close all threads - Thread::closeOldThreads(); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals($thread_info['istate'], Thread::STATE_CLOSED); - - - // Try to close thread with timeout for user and not started for agent(was no agent ping yet) - // Update values - $thread->state = Thread::STATE_CHATTING; - $thread->lastPingAgent = 0; - $thread->lastPingUser = time() - $timeout * 2; - // Save thread - $thread->save(); - // And close all threads - Thread::closeOldThreads(); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals($thread_info['istate'], Thread::STATE_CLOSED); - - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testPostMessage() { - $db = Database::getInstance(); - - // Create new thread - $thread = Thread::create(); - - // Set values - $message = array( - 'threadid' => $thread->id, - 'ikind' => Thread::KIND_INFO, - 'agentId' => 12, - 'tmessage' => 'New message text', - 'dtmcreated' => time(), - 'tname' => 'Sender name', - 'plugin' => '', - 'data' => array() - ); - - $message['messageid'] = $thread->postMessage( - $message['ikind'], - $message['tmessage'], - array( - 'name' => $message['tname'], - 'operator_id' => $message['agentId'], - 'created' => $message['dtmcreated'] - ) - ); - // Load message info from database - $msg_info = $db->query( - "SELECT * FROM {chatmessage} WHERE messageid = ?", - array($message['messageid']), - array('return_rows' => Database::RETURN_ONE_ROW) - ); - $msg_info['data'] = unserialize($msg_info['data']); - - // Check values - $this->assertEquals($message, $msg_info); - - // Delete thread - $thread->delete(); - unset($thread); - - return $message['messageid']; - } - - /** - * @depends testPostMessage - */ - public function testGetMessages($msg_id) { - // Create new thread - $thread = Thread::create(); - - // Create messages - // The first - $first_message = array( - 'kind' => Thread::KIND_USER, - 'message' => 'The first message', - 'created' => time(), - 'name' => 'System message only for agent', - 'plugin' => 'f_test_plg', - 'data' => array('msg_num' => 1) - ); - // The second - $second_message = array( - 'kind' => Thread::KIND_AGENT, - 'message' => 'The second message', - 'created' => time(), - 'name' => 'User', - 'plugin' => 'f_test_plg', - 'data' => array('msg_num' => 1) - ); - // The third - $third_message = array( - 'kind' => Thread::KIND_FOR_AGENT, - 'message' => 'The third message', - 'created' => time(), - 'name' => 'Agent', - 'plugin' => 'f_test_plg', - 'data' => array('msg_num' => 1) - ); - - // Send messages - // The first - $first_message['id'] = $thread->postMessage( - $first_message['kind'], - $first_message['message'], - array( - 'name' => $first_message['name'], - 'operator_id' => 12, - 'created' => $first_message['created'], - 'plugin' => $second_message['plugin'], - 'data' => $second_message['data'] - ) - ); - // The second - $second_message['id'] = $thread->postMessage( - $second_message['kind'], - $second_message['message'], - array( - 'name' => $second_message['name'], - 'operator_id' => 14, - 'created' => $second_message['created'], - 'plugin' => $second_message['plugin'], - 'data' => $second_message['data'] - ) - ); - // The third - $third_message['id'] = $thread->postMessage( - $third_message['kind'], - $third_message['message'], - array( - 'name' => $third_message['name'], - 'operator_id' => 16, - 'created' => $third_message['created'], - 'plugin' => $second_message['plugin'], - 'data' => $second_message['data'] - ) - ); - - // Check messages for agent with ids starts from $msg_id - $last_id = $msg_id; - $this->assertEquals( - array($first_message, $second_message, $third_message), - $thread->getMessages(false, $last_id) - ); - // Check last message id - $this->assertEquals($third_message['id'], $last_id); - - // Check messages for user with ids starts from $msg_id - $last_id = $msg_id; - $this->assertEquals( - array($first_message, $second_message), - $thread->getMessages(true, $last_id) - ); - // Check last message id - $this->assertEquals($second_message['id'], $last_id); - - // Check messages for agent with ids starts from first message's id - $last_id = $first_message['id']; - $this->assertEquals( - array($second_message, $third_message), - $thread->getMessages(false, $last_id) - ); - // Check last message id - $this->assertEquals($third_message['id'], $last_id); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testRenameUser() { - // Create new thread - $thread = Thread::create(); - // Set user initial name - $thread->userName = 'User name'; - $thread->locale = 'en'; - $thread->save(); - - // Rename user - $new_user_name = 'New user name'; - $thread->renameUser($new_user_name); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check user name - $this->assertEquals($new_user_name, $thread_info['userName']); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testCheckForReassign() { - global $home_locale; - - // Create new thread - $thread = Thread::create(); - $thread->state = Thread::STATE_CHATTING; - $thread->locale = $home_locale; - $thread->agentName = "First name"; - $thread->agentId = 1; - $thread->nextAgent = 0; - $thread->save(); - - // Create operator - $operator = array( - 'operatorid' => 2, - 'vclocalename' => 'Second local name', - 'vccommonname' => 'Second common name', - 'vcavatar' => 'avatar' - ); - - // Chat in progress. No reassign expected - $thread->checkForReassign($operator); - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(1, $thread_info['agentId']); - - - // User waiting for another agent - $thread->nextAgent = 5; - $thread->state = Thread::STATE_WAITING; - $thread->save(); - $thread->checkForReassign($operator); - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - $this->assertEquals(Thread::STATE_WAITING, $thread_info['istate']); - $this->assertEquals(Thread::STATE_WAITING, $thread->state); - - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - // User waiting for another agent, but last agent checks for reassign - $thread->nextAgent = 5; - $thread->agentId = 2; - $thread->state = Thread::STATE_WAITING; - $thread->save(); - $thread->checkForReassign($operator); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check state - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - - // Check sent message - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - - // Check messages text: - // Thread::KIND_EVENTS message - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_("chat.status.operator.returned", array($operator['vclocalename']), $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - // Update last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // User waiting for this agent. - // It differs from previous test only in sent message text - $thread->nextAgent = 2; - $thread->agentId = 1; - $thread->agentName = 'First agent'; - $thread->state = Thread::STATE_WAITING; - $thread->save(); - $thread->checkForReassign($operator); - - // Check message text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_( - "chat.status.operator.changed", - array($operator['vclocalename'], 'First agent'), - $thread->locale - ), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testClose() { - global $home_locale; - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - // Create new thread - $thread = Thread::create(); - $thread->state = Thread::STATE_CHATTING; - $thread->userName = 'User'; - $thread->agentName = 'Agent'; - $thread->locale = $home_locale; - $thread->save(); - - - // Check close thread by user - $thread->close(true); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check state - $this->assertEquals(Thread::STATE_CLOSED, $thread_info['istate']); - $this->assertEquals(Thread::STATE_CLOSED, $thread->state); - - // Check messages count - $this->assertEquals(0, $thread_info['messageCount']); - - // Check sent messages - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - - // Check message text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_("chat.status.user.left", array($thread->userName), $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // Check close thread by agent. - // It differs from previous test only in message text - $thread->state = Thread::STATE_CHATTING; - $thread->save(); - - $thread->close(false); - - // Check message text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_("chat.status.operator.left", array($thread->agentName), $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - // Check close thread with user's and agent's messages - $thread->state = Thread::STATE_CHATTING; - $thread->messageCount = 0; - $thread->save(); - - // Send messages - $thread->postMessage(Thread::KIND_USER, "Test message"); - $thread->postMessage(Thread::KIND_USER, "Next test message"); - $thread->postMessage(Thread::KIND_AGENT, "Test message"); - $thread->postMessage(Thread::KIND_EVENTS, "Test message"); - - $thread->close(true); - - // Load thread info from database - $thread_info = $this->_helper_getThreadInfo($thread->id); - - // Check messages count - $this->assertEquals(2, $thread_info['messageCount']); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testPing() { - global $home_locale; - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - // Create new thread - $thread = Thread::create(); - $thread->state = Thread::STATE_LOADING; - $thread->lastPingAgent = 0; - $thread->lastPingUser = 0; - $thread->locale = $home_locale; - $thread->save(); - - - // Check first user ping - $thread->ping(true, false); - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals(Thread::STATE_QUEUE, $thread->state); - $this->assertEquals(Thread::STATE_QUEUE, $thread_info['istate']); - - - // Check not first ping user without any connection problems at the other side - // Update thread info - $thread->lastPingAgent = time(); - $thread->lastPingUser = 0; - $thread->state = Thread::STATE_CHATTING; - $thread->save(); - // Ping the thread - $thread->ping(true, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check no message sent - $this->assertEquals($last_msg_id, $this->_helper_getLastMessageId()); - // Check last ping time updated for user - $this->assertLessThan($thread->lastPingUser, 0); - $this->assertLessThan($thread_info['lastpinguser'], 0); - // Check thread state not changed - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - - - // Check ping agent without any connection problems at the other side - // Update thread info - $thread->lastPingAgent = 0; - $thread->save(); - // Ping the thread - $thread->ping(false, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check no message sent - $this->assertEquals($last_msg_id, $this->_helper_getLastMessageId()); - // Check last ping time updated for user - $this->assertLessThan($thread->lastPingAgent, 0); - $this->assertLessThan($thread_info['lastpingagent'], 0); - // Check thread state not changed - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - - - // Check ping user with connection problem at the other side and thread state equals to - // Thread::STATE_WAITING - // Update thread info - $thread->lastPingAgent = time() - Thread::CONNECTION_TIMEOUT * 2; - $thread->state = Thread::STATE_WAITING; - $thread->save(); - // Ping the thread - $thread->ping(true, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check no message sent - $this->assertEquals($last_msg_id, $this->_helper_getLastMessageId()); - // Check last ping agent - $this->assertEquals(0, $thread->lastPingAgent); - $this->assertEquals(0, $thread_info['lastpingagent']); - - - // Check ping user with connection problem at the other side and thread state equals to Thread::STATE_CHATTING. - // In this case message must be sent and state must be changed - // Update thread info - $thread->lastPingAgent = time() - Thread::CONNECTION_TIMEOUT * 2; - $thread->state = Thread::STATE_CHATTING; - $thread->nextAgent = 1; - $thread->save(); - // Ping the thread - $thread->ping(true, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check message sent - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - // Check messsage text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_CONN, - getstring_("chat.status.operator.dead", $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - // Check last ping agent - $this->assertEquals(0, $thread->lastPingAgent); - $this->assertEquals(0, $thread_info['lastpingagent']); - // Check thread state - $this->assertEquals(Thread::STATE_WAITING, $thread->state); - $this->assertEquals(Thread::STATE_WAITING, $thread_info['istate']); - // Check next agent - $this->assertEquals(0, $thread->nextAgent); - $this->assertEquals(0, $thread_info['nextagent']); - - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // Check ping agent with connection problem at the other side - // Update thread info - $thread->lastPingUser = time() - Thread::CONNECTION_TIMEOUT * 2; - $thread->save(); - // Ping the thread - $thread->ping(false, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check message sent - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - // Check messsage text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_FOR_AGENT, - getstring_("chat.status.user.dead", $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - // Check last ping user - $this->assertEquals(0, $thread->lastPingUser); - $this->assertEquals(0, $thread_info['lastpinguser']); - - - // Check user typing - // Update thread info - $thread->userTyping = '0'; - $thread->save(); - // Ping the thread - $thread->ping(true, true); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check - $this->assertEquals('1', $thread->userTyping); - $this->assertEquals('1', $thread_info['userTyping']); - - // Check user not typing - // Update thread info - $thread->userTyping = '1'; - $thread->save(); - // Ping the thread - $thread->ping(true, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check - $this->assertEquals('0', $thread->userTyping); - $this->assertEquals('0', $thread_info['userTyping']); - - - // Check agent typing - // Update thread info - $thread->agentTyping = '0'; - $thread->save(); - // Ping the thread - $thread->ping(false, true); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check - $this->assertEquals('1', $thread->agentTyping); - $this->assertEquals('1', $thread_info['agentTyping']); - - // Check agent not typing - // Update thread info - $thread->agentTyping = '1'; - $thread->save(); - // Ping the thread - $thread->ping(false, false); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check - $this->assertEquals('0', $thread->agentTyping); - $this->assertEquals('0', $thread_info['agentTyping']); - - // Delete thread - $thread->delete(); - unset($thread); - } - - public function testTake() { - global $home_locale; - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - // Create operator - $operator = array( - 'operatorid' => 2, - 'vclocalename' => 'Local name', - 'vccommonname' => 'Common name', - 'vcavatar' => 'avatar' - ); - - // Create new thread - $thread = Thread::create(); - $thread->state = Thread::STATE_CLOSED; - $thread->locale = $home_locale; - $thread->agentName = 'Agent'; - $thread->userName = 'User'; - $thread->agentId = 2; - $thread->save(); - - - // Try to take closed thread - $this->assertFalse($thread->take($operator)); - - - // Try to take left thread - $thread->state = Thread::STATE_LEFT; - $thread->save(); - $this->assertFalse($thread->take($operator)); - - - // Try to take thread by current operator during chat - $thread->state = Thread::STATE_CHATTING; - $thread->save(); - $this->assertTrue($thread->take($operator)); - // No message must be sent - $this->assertEquals(0, $this->_helper_getTotalMessagesCount($last_msg_id)); - - - // Try to take thread during chat - $thread->state = Thread::STATE_CHATTING; - $thread->agentId = 1; - $thread->nextAgent = 10; - $thread->save(); - $this->assertTrue($thread->take($operator)); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - // Check agent id - $this->assertEquals(2, $thread->agentId); - $this->assertEquals(2, $thread_info['agentId']); - // Check agent name - $this->assertEquals($operator['vclocalename'], $thread->agentName); - $this->assertEquals($operator['vclocalename'], $thread_info['agentName']); - // Check next agent id - $this->assertEquals(0, $thread->nextAgent); - $this->assertEquals(0, $thread_info['nextagent']); - // Check chat started time - $this->assertFalse(empty($thread->chatStarted)); - $this->assertFalse(empty($thread_info['dtmchatstarted'])); - // One messages must be sent - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - // Check messages text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_( - "chat.status.operator.changed", - array($operator['vclocalename'], 'Agent'), - $thread->locale - ), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // Try to take thread with state Thread::STATE_WAITING by current operator - $thread->state = Thread::STATE_WAITING; - $thread->save(); - $this->assertTrue($thread->take($operator)); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - // Check agent id - $this->assertEquals(2, $thread->agentId); - $this->assertEquals(2, $thread_info['agentId']); - // One message must be sent - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - // Check messages text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_("chat.status.operator.returned", array($operator['vclocalename']), $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // Try to take thread with state Thread::STATE_WAITING - $thread->state = Thread::STATE_WAITING; - $thread->agentId = 1; - $thread->agentName = 'Agent'; - $thread->save(); - $this->assertTrue($thread->take($operator)); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - // One message must be sent - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - // Check messages text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - getstring2_( - "chat.status.operator.changed", - array($operator['vclocalename'], 'Agent'), - $thread->locale - ), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - - // Get last message id - $last_msg_id = $this->_helper_getLastMessageId(); - - - // Try to take thread with state Thread::STATE_QUEUE - $thread->state = Thread::STATE_QUEUE; - $thread->save(); - $this->assertTrue($thread->take($operator)); - // Get thread info - $thread_info = $this->_helper_getThreadInfo($thread->id); - // Check thread state - $this->assertEquals(Thread::STATE_CHATTING, $thread->state); - $this->assertEquals(Thread::STATE_CHATTING, $thread_info['istate']); - // One message must be sent - $this->assertEquals(1, $this->_helper_getTotalMessagesCount($last_msg_id)); - // Check messages text - $message_count = $this->_helper_getMessagesCount( - Thread::KIND_EVENTS, - $message = getstring2_("chat.status.operator.joined", array($operator['vclocalename']), $thread->locale), - $last_msg_id - ); - $this->assertEquals(1, $message_count); - - // Delete thread - $thread->delete(); - unset($thread); - } - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/mibew_api_test_interaction.php b/src/tests/server_side/webim/libs/classes/mibew_api_test_interaction.php deleted file mode 100644 index f1aba947..00000000 --- a/src/tests/server_side/webim/libs/classes/mibew_api_test_interaction.php +++ /dev/null @@ -1,24 +0,0 @@ - array( - 'return' => array(), - 'references' => array() - ), - 'foo' => array( - 'bar' => 127 - ) - ); - - public $reservedFunctionNames = array( - 'result' - ); - -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/test_processor.php b/src/tests/server_side/webim/libs/classes/test_processor.php deleted file mode 100644 index f20398d7..00000000 --- a/src/tests/server_side/webim/libs/classes/test_processor.php +++ /dev/null @@ -1,115 +0,0 @@ - '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; - } - } -} - -?> diff --git a/src/tests/server_side/webim/libs/classes/thread_processor_mock.php b/src/tests/server_side/webim/libs/classes/thread_processor_mock.php deleted file mode 100644 index 18e029fc..00000000 --- a/src/tests/server_side/webim/libs/classes/thread_processor_mock.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/src/tests/server_side/webim/libs/default_config.php b/src/tests/server_side/webim/libs/default_config.php deleted file mode 100644 index 2290ce7e..00000000 --- a/src/tests/server_side/webim/libs/default_config.php +++ /dev/null @@ -1,28 +0,0 @@ - \ No newline at end of file diff --git a/src/tests/server_side/webim/libs/request_processor_test.php b/src/tests/server_side/webim/libs/request_processor_test.php deleted file mode 100644 index 06feeef0..00000000 --- a/src/tests/server_side/webim/libs/request_processor_test.php +++ /dev/null @@ -1,8 +0,0 @@ -triggerEvent('testRequestProcessorCallback', $arguments); -} - -?> \ No newline at end of file diff --git a/src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager/phpunit_autotest_plugin_manager_plugin.php b/src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager/phpunit_autotest_plugin_manager_plugin.php deleted file mode 100644 index 363e499b..00000000 --- a/src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager/phpunit_autotest_plugin_manager_plugin.php +++ /dev/null @@ -1,29 +0,0 @@ -listenersRegistered = true; - $GLOBALS['phpunit_autotest_plugin_manager'] = true; - } - - public function testEventListener(&$vars) { - $vars['test'] = 'some_test_value'; - } - - public function __construct(){ - $this->initialized = true; - } - -} - -?> \ No newline at end of file diff --git a/src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager_dependence/phpunit_autotest_plugin_manager_dependence_plugin.php b/src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager_dependence/phpunit_autotest_plugin_manager_dependence_plugin.php deleted file mode 100644 index 28e8adc2..00000000 --- a/src/tests/server_side/webim/plugins/phpunit_autotest_plugin_manager_dependence/phpunit_autotest_plugin_manager_dependence_plugin.php +++ /dev/null @@ -1,26 +0,0 @@ -initialized = true; - } - -} - -?> \ No newline at end of file diff --git a/src/tests/server_side/webim/plugins/request_processor_test/request_processor_test_plugin.php b/src/tests/server_side/webim/plugins/request_processor_test/request_processor_test_plugin.php deleted file mode 100644 index 42a1aaeb..00000000 --- a/src/tests/server_side/webim/plugins/request_processor_test/request_processor_test_plugin.php +++ /dev/null @@ -1,68 +0,0 @@ -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; - } -} - -?> \ No newline at end of file