Skip to content

Commit

Permalink
Merge pull request #41 from Jack-Dane/#35_fix_create_record_button_ui
Browse files Browse the repository at this point in the history
#35 fix create record button UI
  • Loading branch information
Jack-Dane authored Jun 23, 2024
2 parents 2e6ede8 + f0ab9b2 commit 71b2a13
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 61 deletions.
2 changes: 1 addition & 1 deletion admin/pages/connections/odoo_connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function create_new_record()
$post_odoo_connection->request($_REQUEST);
}

protected function create_table_display()
protected function get_table_display()
{
return new OdooConnOdooConnectionListTableEditable(
$this->get_backend, $this->delete_backend
Expand Down
2 changes: 1 addition & 1 deletion admin/pages/errors/odoo_errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
parent::__construct();
}

protected function create_table_display()
protected function get_table_display()
{
return new OdooConnOdooErrorsListTableEditable(
$this->get_backend, $this->delete_backend
Expand Down
2 changes: 1 addition & 1 deletion admin/pages/form_mappings/odoo_form_mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct($menu_slug)
parent::__construct($menu_slug);
}

protected function create_table_display()
protected function get_table_display()
{
return new OdooConnOdooFormMappingListTableEditable(
$this->get_backend, $this->delete_backend
Expand Down
2 changes: 1 addition & 1 deletion admin/pages/forms/odoo_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function create_new_record()
$post_odoo_connection->request($_REQUEST);
}

protected function create_table_display()
protected function get_table_display()
{
return new OdooConnOdooFormListTableEditable(
$this->get_backend, $this->delete_backend
Expand Down
30 changes: 22 additions & 8 deletions admin/pages/page_router.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ abstract class OdooConnPageRouter

public function __construct()
{
$this->table_display = $this->create_table_display();
$this->table_display = $this->get_table_display();
}

private function valid_capability() {
Expand Down Expand Up @@ -47,16 +47,26 @@ protected function handle_route($action)

protected function display_table()
{
echo "<div class='wrap'>";
$this->start_wrap();
$this->table_display->check_bulk_action();

echo "<form method='post'>";
$this->table_display->prepare_items();
$this->table_display->display();
echo "</form></div>";
echo "</form>";

$this->end_wrap();
}

protected abstract function create_table_display();
protected function start_wrap() {
echo "<div class='wrap'>";
}

protected function end_wrap() {
echo "</div>";
}

protected abstract function get_table_display();

protected abstract function delete($id);

Expand Down Expand Up @@ -113,7 +123,6 @@ private function verify_nonce() {
protected function display_table()
{
$request_method = $_SERVER["REQUEST_METHOD"];
$menu_page_slug = menu_page_url($this->menu_slug, false);

if ($request_method == "POST") {
$this->verify_nonce();
Expand All @@ -125,12 +134,17 @@ protected function display_table()
}
}

$connection_url = esc_url(add_query_arg("page_action", "new", $menu_page_slug));
echo "<a href='$connection_url' id='create-data' class='create-database-record button-primary'>Create a new record</a>";

parent::display_table();
}

protected function start_wrap() {
parent::start_wrap();

$menu_page_slug = menu_page_url($this->menu_slug, false);
$create_record_url = esc_url(add_query_arg("page_action", "new", $menu_page_slug));
echo "<a href='$create_record_url' id='create-data' class='create-database-record button-primary'>Create a new record</a>";
}

protected abstract function create_new_record();

protected abstract function update_record();
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.1'
services:

wordpress:
image: wordpress:beta-6.5-php8.3-apache
image: wordpress:apache
restart: always
ports:
- 8080:80
Expand Down
15 changes: 11 additions & 4 deletions runE2ETests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ docker exec $dockerPHPContainerId /bin/sh -c 'cd /opt/odoo_conn; vendor/bin/phpu
docker exec $dockerPHPContainerId /bin/sh -c 'cd /opt/odoo_conn; vendor/bin/phpunit tests/end_to_end_tests/tests/selenium_tests/Delete_Test.php'

# cleanup the containers
docker compose -f tests/end_to_end_tests/odoo-compose.yaml rm -f --volumes --stop
docker compose -f tests/end_to_end_tests/wordpress-compose.yaml rm -f --volumes --stop
echo "Stopping and removing Odoo compose containers"
docker compose -f tests/end_to_end_tests/odoo-compose.yaml down --volumes
docker compose -f tests/end_to_end_tests/odoo-compose.yaml rm

docker container rm -f $dockerPHPContainerId
docker container rm -f $dockerSeleniumContainerId
echo "Stopping and removing WordPress containers"
docker compose -f tests/end_to_end_tests/wordpress-compose.yaml down --volumes
docker compose -f tests/end_to_end_tests/wordpress-compose.yaml rm

echo "Removing PHP container and image"
docker container rm -f $dockerPHPContainerId
docker image rm $dockerPHPImageId

echo "Removing Selenium container"
docker container rm -f $dockerSeleniumContainerId
21 changes: 21 additions & 0 deletions tests/end_to_end_tests/tests/endpoint_tests/CF7_Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace end_to_end_tests\tests\endpoint_tests;

require_once __DIR__ . '/EndpointTestBase.php';


class CF7_Test extends EndpointTestBase
{

protected function endpoint()
{
return 'http://localhost:8000/?rest_route=/odoo_conn/v1/get-contact-7-forms';
}

public function test()
{
$this->make_request();
}

}
36 changes: 36 additions & 0 deletions tests/end_to_end_tests/tests/endpoint_tests/EndpointTestBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace end_to_end_tests\tests\endpoint_tests;

use PHPUnit\Framework\TestCase;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;


abstract class EndpointTestBase extends Testcase {

public function setUp(): void
{
$this->client = new Client();
}

protected abstract function endpoint();

protected function make_request()
{
$failure = false;
try {
$this->client->request(
'GET', $this->endpoint()
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
}

}


?>
34 changes: 12 additions & 22 deletions tests/end_to_end_tests/tests/endpoint_tests/OdooConnection_Test.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
<?php

use \PHPUnit\Framework\TestCase;
use \GuzzleHttp\Client;
use \GuzzleHttp\Exception\ClientException;
namespace end_to_end_tests\tests\endpoint_tests;

class OdooConnection_Test extends TestCase
{
require_once __DIR__ . '/EndpointTestBase.php';

public function setUp(): void
{
$this->client = new Client();
}
class OdooConnection_Test extends EndpointTestBase
{

public function test_get_odoo_connections()
{
$failure = false;
try {
$response = $this->client->request(
"GET", "http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-connections"
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
}
protected function endpoint()
{
return 'http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-connections';
}

public function test()
{
$this->make_request();
}
}

?>
33 changes: 12 additions & 21 deletions tests/end_to_end_tests/tests/endpoint_tests/OdooForm_Test.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
<?php

use \PHPUnit\Framework\TestCase;
use \GuzzleHttp\Client;
use \GuzzleHttp\Exception\ClientException;
namespace end_to_end_tests\tests\endpoint_tests;

class OdooForm_Test extends TestCase
require_once __DIR__ . '/EndpointTestBase.php';

class OdooForm_Test extends EndpointTestBase
{

public function setUp(): void
{
$this->client = new Client();
}
protected function endpoint()
{
return 'http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-forms';
}

public function test_get_odoo_forms()
{
$failure = false;
try {
$response = $this->client->request(
"GET", "http://localhost:8000/?rest_route=/odoo_conn/v1/get-odoo-forms"
);
} catch (ClientException $e) {
$failure = true;
$this->assertEquals(401, $e->getResponse()->getStatusCode());
}
$this->assertTrue($failure);
}
public function test()
{
$this->make_request();
}

}

Expand Down
2 changes: 1 addition & 1 deletion tests/end_to_end_tests/wordpress-dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WordPress with composer
FROM wordpress:beta-6.5-php8.3-apache
FROM wordpress:latest

COPY --from=composer /usr/bin/composer /usr/bin/composer

Expand Down

0 comments on commit 71b2a13

Please sign in to comment.