Files
chrnx-dev-wp/tests/php/ProjectBlocksTest.php
T
2026-08-15 14:19:58 -05:00

132 lines
3.9 KiB
PHP

<?php
/**
* Tests for the project blocks.
*
* @package CHRNX
*/
/**
* Verify project block rendering.
*/
class ProjectBlocksTest extends WP_UnitTestCase {
/**
* Register blocks and taxonomies before each test.
*/
public function set_up() {
parent::set_up();
do_action( 'init' );
}
/**
* Ensure the list renders one card per project with its status.
*/
public function test_project_list_renders_a_card_per_project() {
$term_id = self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'name' => 'Green Tea',
'slug' => 'green-tea-test',
)
);
update_term_meta( $term_id, 'chrnx_project_status', 'Beta' );
$markup = do_blocks( '<!-- wp:chrnx/project-list /-->' );
$this->assertStringContainsString( 'chrnx-project-card', $markup );
$this->assertStringContainsString( 'Green Tea', $markup );
$this->assertStringContainsString( 'Beta', $markup );
}
/**
* Ensure stored project links render with their platform icons.
*/
public function test_project_list_renders_stored_links() {
$term_id = self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'name' => 'Matcha CLI',
'slug' => 'matcha-cli-test',
)
);
update_term_meta( $term_id, 'chrnx_project_repo', 'https://example.com/repo' );
update_term_meta( $term_id, 'chrnx_project_package', 'https://example.com/package' );
$markup = do_blocks( '<!-- wp:chrnx/project-list /-->' );
$this->assertStringContainsString( 'chrnx-platform-links', $markup );
$this->assertStringContainsString( 'https://example.com/repo', $markup );
$this->assertStringContainsString( 'https://example.com/package', $markup );
}
/**
* Ensure a project without a cover still renders art.
*/
public function test_project_without_cover_uses_placeholder_art() {
self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'slug' => 'coverless-test',
)
);
$markup = do_blocks( '<!-- wp:chrnx/project-list /-->' );
$this->assertStringContainsString( 'chrnx-project-card__fallback', $markup );
}
/**
* Ensure the detail block renders the queried project header.
*/
public function test_project_detail_renders_the_queried_term() {
$term_id = self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'name' => 'Ailed',
'slug' => 'ailed-test',
'description' => 'A chess engine that feels.',
)
);
update_term_meta( $term_id, 'chrnx_project_repo', 'https://github.com/example/ailed' );
update_term_meta( $term_id, 'chrnx_project_status', 'Activo' );
$this->go_to( get_term_link( $term_id ) );
$markup = do_blocks( '<!-- wp:chrnx/project-detail /-->' );
$this->assertStringContainsString( 'A chess engine that feels.', $markup );
$this->assertStringContainsString( 'https://github.com/example/ailed', $markup );
$this->assertStringContainsString( 'Activo', $markup );
}
/**
* Ensure the detail block renders nothing outside a project archive.
*/
public function test_project_detail_is_silent_off_its_archive() {
$this->go_to( home_url( '/' ) );
$this->assertSame( '', trim( do_blocks( '<!-- wp:chrnx/project-detail /-->' ) ) );
}
/**
* Ensure a project archive filters the journal to that project.
*/
public function test_project_archive_filters_the_journal() {
$term_id = self::factory()->term->create(
array(
'taxonomy' => 'chrnx_project',
'slug' => 'filter-test',
)
);
$mine = self::factory()->post->create( array( 'post_title' => 'Belongs to the project' ) );
self::factory()->post->create( array( 'post_title' => 'Unrelated post' ) );
wp_set_object_terms( $mine, array( $term_id ), 'chrnx_project' );
$this->go_to( get_term_link( $term_id ) );
$markup = do_blocks( '<!-- wp:chrnx/journal-stream /-->' );
$this->assertStringContainsString( 'Belongs to the project', $markup );
$this->assertStringNotContainsString( 'Unrelated post', $markup );
}
}