diff --git a/admin/pages/connections/odoo_connection.php b/admin/pages/connections/odoo_connection.php index 1af2b48..291a2a4 100644 --- a/admin/pages/connections/odoo_connection.php +++ b/admin/pages/connections/odoo_connection.php @@ -79,11 +79,19 @@ protected function handle_route($action) private function test_connection($id) { - show_message(json_encode(odoo_conn_test_odoo_connection( - ["id" => $id] - ))); + $test_result = odoo_conn_test_odoo_connection( + ["id" => $id] + ); + $this->display_test_connection_result($test_result); } + protected function display_test_connection_result($test_result) + { + // $test_result variable is used in the test_connection_result.php file. + wp_enqueue_style("test-connection-result", plugins_url("test_connection_result.css", __FILE__)); + require_once "test_connection_result.php"; + } + protected function display_input_form() { require_once "odoo_connection_input_form.php"; diff --git a/admin/pages/connections/test_connection_result.css b/admin/pages/connections/test_connection_result.css new file mode 100644 index 0000000..ecc84c9 --- /dev/null +++ b/admin/pages/connections/test_connection_result.css @@ -0,0 +1,15 @@ + +.odoo-conn-message-notification-box { + background-color: #fff; + box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04); + border: 1px solid #c3c4c7; + padding: 8px 10px; +} + +.test-result-ok { + background: #ddffdd; +} + +.test-result-failure { + background: #ffdddd; +} diff --git a/admin/pages/connections/test_connection_result.php b/admin/pages/connections/test_connection_result.php new file mode 100644 index 0000000..a3a99a7 --- /dev/null +++ b/admin/pages/connections/test_connection_result.php @@ -0,0 +1,22 @@ + +
+

Test Result:

+ + + +
+ Error Message: + +
+ +
+ Error Code: + +
+ +
+ \ No newline at end of file diff --git a/odoo_conn.php b/odoo_conn.php index 162f52f..d6afb41 100644 --- a/odoo_conn.php +++ b/odoo_conn.php @@ -8,7 +8,7 @@ * Requires PHP: 8.1 * Text Domain: cf7-odoo-connector * Requires Plugins: contact-form-7 - * Version: 0.1.6 + * Version: 0.1.7 */ // Exit if accessed directly. diff --git a/tests/end_to_end_tests/tests/selenium_tests/Error_Test.php b/tests/end_to_end_tests/tests/selenium_tests/Error_Test.php index 47e8bfd..2bc9de3 100644 --- a/tests/end_to_end_tests/tests/selenium_tests/Error_Test.php +++ b/tests/end_to_end_tests/tests/selenium_tests/Error_Test.php @@ -44,13 +44,27 @@ public function test_broken_connection_alert() $test_button->click(); sleep(2); - $expected_error_message = "{\"success\":false,\"error_string\":\"Username or API Key is incorrect\",\"error_code\":0}"; - $elements = $this->wait_for_elements( + $this->wait_for_elements( WebDriverBy::xpath( - "//p[contains(text(), '$expected_error_message')]" + "//h1[contains(text(), 'Test Result: Failure')]" ) ); - $this->assertCount(1, $elements); + $this->driver->findElement( + WebDriverBy::xpath("//b[contains(text(), 'Error Message: ')]") + ); + $this->driver->findElement( + WebDriverBy::xpath("//span[contains(text(), 'Username or API Key is incorrect')]") + ); + $this->driver->findElement( + WebDriverBy::xpath("//b[contains(text(), 'Error Code: ')]") + ); + $this->driver->findElement( + WebDriverBy::xpath("//span[contains(text(), '0')]") + ); + + // to make the test not appear to be 'risky' as it hasn't made any assertions. + // findElement will raise an exception if the test fails. + $this->assertTrue(true); } public function test_broken_send_data() diff --git a/tests/php/admin/pages/connections/OdooConnOdooConnectionRouter_request_Test.php b/tests/php/admin/pages/connections/OdooConnOdooConnectionRouter_request_Test.php index ee637ad..246c24c 100644 --- a/tests/php/admin/pages/connections/OdooConnOdooConnectionRouter_request_Test.php +++ b/tests/php/admin/pages/connections/OdooConnOdooConnectionRouter_request_Test.php @@ -76,6 +76,25 @@ function test_request_edit() $this->odoo_conn_page_router->request(); } + function test_request_test_connection() + { + $GLOBALS['_REQUEST'] = ['page_action' => 'test_connection', 'id' => 3]; + $this->odoo_conn_page_router->shouldReceive('display_test_connection_result')->with( + ['success' => true] + )->once(); + $this->odoo_conn_page_router->shouldReceive('display_table')->once(); + Functions\expect('current_user_can')->once()->with( + 'administrator' + )->andReturn(true); + Functions\expect( + 'odoo_conn\admin\database_connection\odoo_conn_test_odoo_connection' + )->with( + ['id' => 3] + )->andReturn(['success' => true]); + + $this->odoo_conn_page_router->request(); + } + function test_request_other() { $GLOBALS['_REQUEST'] = ['id' => 3, 'page_action' => 'other'];