Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ jobs:
repository: TangibleInc/database-module
path: database-module

- name: Checkout fields
uses: actions/checkout@v6
with:
repository: TangibleInc/fields
path: fields

- name: Setup WordPress test config
run: |
cp wordpress-develop/wp-tests-config-sample.php wordpress-develop/wp-tests-config.php
Expand All @@ -80,4 +86,5 @@ jobs:
env:
WORDPRESS_DEVELOP_DIR: ${{ github.workspace }}/wordpress-develop
DATABASE_MODULE_DIR: ${{ github.workspace }}/database-module
TANGIBLE_FIELDS_DIR: ${{ github.workspace }}/fields
run: ./vendor/bin/phpunit
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Default WordPress develop location
WORDPRESS_DEVELOP_DIR ?= $(HOME)/workspace/wordpress-develop
DATABASE_MODULE_DIR ?= $(shell dirname $(CURDIR))/database-module
TANGIBLE_FIELDS_DIR ?= $(shell dirname $(CURDIR))/fields

help:
@echo "Available targets:"
Expand All @@ -22,9 +23,10 @@ test:
test-all: setup-integrations
WORDPRESS_DEVELOP_DIR=$(WORDPRESS_DEVELOP_DIR) \
DATABASE_MODULE_DIR=$(DATABASE_MODULE_DIR) \
TANGIBLE_FIELDS_DIR=$(TANGIBLE_FIELDS_DIR) \
./vendor/bin/phpunit

setup-integrations: setup-database-module
setup-integrations: setup-database-module setup-tangible-fields

setup-database-module:
@if [ ! -d "$(DATABASE_MODULE_DIR)" ]; then \
Expand All @@ -34,6 +36,14 @@ setup-database-module:
echo "database-module already exists at $(DATABASE_MODULE_DIR)"; \
fi

setup-tangible-fields:
@if [ ! -d "$(TANGIBLE_FIELDS_DIR)" ]; then \
echo "Cloning tangible-fields to $(TANGIBLE_FIELDS_DIR)..."; \
git clone https://github.com/tangibleinc/fields.git $(TANGIBLE_FIELDS_DIR); \
else \
echo "tangible-fields already exists at $(TANGIBLE_FIELDS_DIR)"; \
fi

setup-wp:
@if [ ! -d "$(WORDPRESS_DEVELOP_DIR)" ]; then \
echo "Cloning wordpress-develop to $(WORDPRESS_DEVELOP_DIR)..."; \
Expand Down
16 changes: 12 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"name": "tangible/object",
"description": "A WordPress tool suite for building data-driven interfaces with a clean extensible architecture.",
"repositories": [],
"repositories": [
{
"type": "vcs",
"url": "https://github.com/TangibleInc/framework"
}
],
"require-dev": {
"phpunit/phpunit": "^9.6.31",
"yoast/phpunit-polyfills": "^2.0.5"
"yoast/phpunit-polyfills": "^2.0.5",
"tangible/framework": "dev-main"
},
"require": {},
"autoload": {
Expand All @@ -20,9 +26,11 @@
"scripts": {
"test": "phpunit",
"setup:integrations": [
"@setup:database-module"
"@setup:database-module",
"@setup:tangible-fields"
],
"setup:database-module": "[ -d ../database-module ] || git clone https://github.com/tangibleinc/database-module.git ../database-module"
"setup:database-module": "[ -d ../database-module ] || git clone https://github.com/tangibleinc/database-module.git ../database-module",
"setup:tangible-fields": "[ -d ../fields ] || git clone https://github.com/tangibleinc/fields.git ../fields"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
34 changes: 31 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
$_DATABASE_MODULE_DIR = __DIR__ . '/../../database-module';
}

/**
* Optional: Load the Tangible Fields library for TangibleFieldsRenderer tests.
* Set TANGIBLE_FIELDS_DIR environment variable to override the default path.
*/
if ( ! $_TANGIBLE_FIELDS_DIR = getenv( 'TANGIBLE_FIELDS_DIR' ) ) {
$_TANGIBLE_FIELDS_DIR = __DIR__ . '/../../fields';
}

// Load WP test functions first (provides tests_add_filter)
require_once $_WORDPRESS_TESTS_DIR . '/includes/functions.php';

Expand All @@ -40,5 +48,17 @@
});
}

// Load tangible-fields if available (requires tangible-framework)
if ( file_exists( $_TANGIBLE_FIELDS_DIR . '/index.php' ) ) {
tests_add_filter( 'muplugins_loaded', function() use ( $_TANGIBLE_FIELDS_DIR ) {
// Load tangible-framework first (required by tangible-fields)
$framework_path = __DIR__ . '/../vendor/tangible/framework/index.php';
if ( file_exists( $framework_path ) ) {
require_once $framework_path;
}
require_once $_TANGIBLE_FIELDS_DIR . '/index.php';
});
}

// Now load the rest of WordPress
require $_WORDPRESS_TESTS_DIR . '/includes/bootstrap.php';
84 changes: 84 additions & 0 deletions tests/phpunit/data-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,90 @@ public function test_tangible_fields_renderer_throws_without_framework(): void {
$renderer->render_editor( $layout, [] );
}

/**
* ==========================================================================
* TangibleFieldsRenderer Integration Tests (require Tangible Fields framework)
* ==========================================================================
*/

public function test_tangible_fields_framework_is_available(): void {
if ( ! function_exists( 'tangible_fields' ) ) {
$this->markTestSkipped( 'Tangible Fields framework is not loaded.' );
}

$fields = tangible_fields();
$this->assertNotNull( $fields, 'tangible_fields() should return a Fields instance' );
$this->assertIsObject( $fields );
}

public function test_tangible_fields_renderer_renders_list_view(): void {
if ( ! function_exists( 'tangible_fields' ) ) {
$this->markTestSkipped( 'Tangible Fields framework is not loaded.' );
}

$dataset = new DataSet();
$dataset->add_string( 'name' );
$dataset->add_integer( 'count' );

$renderer = new \Tangible\Renderer\TangibleFieldsRenderer();
$html = $renderer->render_list( $dataset, [
[ 'name' => 'Item 1', 'count' => 5 ],
[ 'name' => 'Item 2', 'count' => 10 ],
[ 'name' => 'Item 3', 'count' => 15 ],
] );

$this->assertStringContainsString( 'wp-list-table', $html );
$this->assertStringContainsString( 'Item 1', $html );
$this->assertStringContainsString( 'Item 2', $html );
$this->assertStringContainsString( 'Item 3', $html );
}

public function test_tangible_fields_renderer_list_view_handles_boolean(): void {
if ( ! function_exists( 'tangible_fields' ) ) {
$this->markTestSkipped( 'Tangible Fields framework is not loaded.' );
}

$dataset = new DataSet();
$dataset->add_string( 'name' );
$dataset->add_boolean( 'active' );

$renderer = new \Tangible\Renderer\TangibleFieldsRenderer();
$html = $renderer->render_list( $dataset, [
[ 'name' => 'Item 1', 'active' => true ],
[ 'name' => 'Item 2', 'active' => false ],
] );

$this->assertStringContainsString( 'Yes', $html );
$this->assertStringContainsString( 'No', $html );
}

public function test_tangible_fields_renderer_list_view_handles_repeater(): void {
if ( ! function_exists( 'tangible_fields' ) ) {
$this->markTestSkipped( 'Tangible Fields framework is not loaded.' );
}

$dataset = new DataSet();
$dataset->add_string( 'name' );
$dataset->add_string( 'items' );

$renderer = new \Tangible\Renderer\TangibleFieldsRenderer();
$renderer->set_field_configs( [
'items' => [
'type' => 'repeater',
'sub_fields' => [
[ 'name' => 'title', 'type' => 'string' ],
],
],
] );

$html = $renderer->render_list( $dataset, [
[ 'name' => 'Test', 'items' => json_encode( [ [ 'title' => 'A' ], [ 'title' => 'B' ] ] ) ],
] );

// Repeater fields should show item count in list view.
$this->assertStringContainsString( '2 item(s)', $html );
}

/**
* ==========================================================================
* DataView with TangibleFieldsRenderer Tests
Expand Down