upskill-event-manager/tests/unit/test-announcements-cpt.php
Ben 7c9ca65cf2
Some checks are pending
HVAC Plugin CI/CD Pipeline / Security Analysis (push) Waiting to run
HVAC Plugin CI/CD Pipeline / Code Quality & Standards (push) Waiting to run
HVAC Plugin CI/CD Pipeline / Unit Tests (push) Waiting to run
HVAC Plugin CI/CD Pipeline / Integration Tests (push) Waiting to run
HVAC Plugin CI/CD Pipeline / Deploy to Staging (push) Blocked by required conditions
HVAC Plugin CI/CD Pipeline / Deploy to Production (push) Blocked by required conditions
HVAC Plugin CI/CD Pipeline / Notification (push) Blocked by required conditions
Security Monitoring & Compliance / Dependency Vulnerability Scan (push) Waiting to run
Security Monitoring & Compliance / Secrets & Credential Scan (push) Waiting to run
Security Monitoring & Compliance / WordPress Security Analysis (push) Waiting to run
Security Monitoring & Compliance / Static Code Security Analysis (push) Waiting to run
Security Monitoring & Compliance / Security Compliance Validation (push) Waiting to run
Security Monitoring & Compliance / Security Summary Report (push) Blocked by required conditions
Security Monitoring & Compliance / Security Team Notification (push) Blocked by required conditions
feat: add comprehensive test framework and test files
- Add 90+ test files including E2E, unit, and integration tests
- Implement Page Object Model (POM) architecture
- Add Docker testing environment with comprehensive services
- Include modernized test framework with error recovery
- Add specialized test suites for master trainer and trainer workflows
- Update .gitignore to properly track test infrastructure

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-29 23:23:26 -03:00

190 lines
No EOL
6.6 KiB
PHP

<?php
/**
* Unit Tests for HVAC Announcements Custom Post Type
*
* @package HVAC_Community_Events
* @subpackage Tests
*/
class Test_HVAC_Announcements_CPT extends WP_UnitTestCase {
/**
* Setup before class
*/
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
// Register post type and taxonomies
$cpt = HVAC_Announcements_CPT::get_instance();
$cpt->register_post_type();
$cpt->register_taxonomies();
}
/**
* Test post type is registered
*/
public function test_post_type_registered() {
$post_type = HVAC_Announcements_CPT::get_post_type();
$this->assertTrue( post_type_exists( $post_type ) );
}
/**
* Test post type name constant
*/
public function test_post_type_constant() {
$this->assertEquals( 'hvac_announcement', HVAC_Announcements_CPT::POST_TYPE );
$this->assertEquals( HVAC_Announcements_CPT::POST_TYPE, HVAC_Announcements_CPT::get_post_type() );
}
/**
* Test category taxonomy is registered
*/
public function test_category_taxonomy_registered() {
$taxonomy = HVAC_Announcements_CPT::get_category_taxonomy();
$this->assertTrue( taxonomy_exists( $taxonomy ) );
}
/**
* Test tag taxonomy is registered
*/
public function test_tag_taxonomy_registered() {
$taxonomy = HVAC_Announcements_CPT::get_tag_taxonomy();
$this->assertTrue( taxonomy_exists( $taxonomy ) );
}
/**
* Test taxonomy constants
*/
public function test_taxonomy_constants() {
$this->assertEquals( 'hvac_announcement_cat', HVAC_Announcements_CPT::TAXONOMY_CATEGORY );
$this->assertEquals( 'hvac_announcement_tag', HVAC_Announcements_CPT::TAXONOMY_TAG );
}
/**
* Test post type supports
*/
public function test_post_type_supports() {
$post_type = HVAC_Announcements_CPT::get_post_type();
$this->assertTrue( post_type_supports( $post_type, 'title' ) );
$this->assertTrue( post_type_supports( $post_type, 'editor' ) );
$this->assertTrue( post_type_supports( $post_type, 'author' ) );
$this->assertTrue( post_type_supports( $post_type, 'thumbnail' ) );
$this->assertTrue( post_type_supports( $post_type, 'excerpt' ) );
$this->assertTrue( post_type_supports( $post_type, 'custom-fields' ) );
}
/**
* Test creating an announcement post
*/
public function test_create_announcement() {
$post_id = wp_insert_post( array(
'post_type' => HVAC_Announcements_CPT::get_post_type(),
'post_title' => 'Test Announcement',
'post_content' => 'This is a test announcement.',
'post_status' => 'publish',
) );
$this->assertNotEquals( 0, $post_id );
$this->assertFalse( is_wp_error( $post_id ) );
$post = get_post( $post_id );
$this->assertEquals( HVAC_Announcements_CPT::get_post_type(), $post->post_type );
$this->assertEquals( 'Test Announcement', $post->post_title );
// Clean up
wp_delete_post( $post_id, true );
}
/**
* Test assigning categories to announcement
*/
public function test_assign_categories() {
// Create announcement
$post_id = wp_insert_post( array(
'post_type' => HVAC_Announcements_CPT::get_post_type(),
'post_title' => 'Test Announcement',
'post_status' => 'publish',
) );
// Create category
$term = wp_insert_term( 'Test Category', HVAC_Announcements_CPT::get_category_taxonomy() );
$this->assertFalse( is_wp_error( $term ) );
// Assign category
$result = wp_set_post_terms( $post_id, array( $term['term_id'] ), HVAC_Announcements_CPT::get_category_taxonomy() );
$this->assertFalse( is_wp_error( $result ) );
// Verify assignment
$categories = wp_get_post_terms( $post_id, HVAC_Announcements_CPT::get_category_taxonomy() );
$this->assertCount( 1, $categories );
$this->assertEquals( 'Test Category', $categories[0]->name );
// Clean up
wp_delete_post( $post_id, true );
wp_delete_term( $term['term_id'], HVAC_Announcements_CPT::get_category_taxonomy() );
}
/**
* Test assigning tags to announcement
*/
public function test_assign_tags() {
// Create announcement
$post_id = wp_insert_post( array(
'post_type' => HVAC_Announcements_CPT::get_post_type(),
'post_title' => 'Test Announcement',
'post_status' => 'publish',
) );
// Assign tags
$result = wp_set_post_terms( $post_id, array( 'tag1', 'tag2', 'tag3' ), HVAC_Announcements_CPT::get_tag_taxonomy() );
$this->assertFalse( is_wp_error( $result ) );
// Verify assignment
$tags = wp_get_post_terms( $post_id, HVAC_Announcements_CPT::get_tag_taxonomy() );
$this->assertCount( 3, $tags );
$tag_names = wp_list_pluck( $tags, 'name' );
$this->assertContains( 'tag1', $tag_names );
$this->assertContains( 'tag2', $tag_names );
$this->assertContains( 'tag3', $tag_names );
// Clean up
wp_delete_post( $post_id, true );
foreach ( $tags as $tag ) {
wp_delete_term( $tag->term_id, HVAC_Announcements_CPT::get_tag_taxonomy() );
}
}
/**
* Test post type is not publicly queryable
*/
public function test_post_type_not_public() {
$post_type_obj = get_post_type_object( HVAC_Announcements_CPT::get_post_type() );
$this->assertFalse( $post_type_obj->public );
$this->assertFalse( $post_type_obj->publicly_queryable );
$this->assertFalse( $post_type_obj->has_archive );
}
/**
* Test post type capabilities
*/
public function test_post_type_capabilities() {
$post_type_obj = get_post_type_object( HVAC_Announcements_CPT::get_post_type() );
$this->assertEquals( 'hvac_announcement', $post_type_obj->capability_type[0] );
$this->assertEquals( 'hvac_announcements', $post_type_obj->capability_type[1] );
$this->assertTrue( $post_type_obj->map_meta_cap );
}
/**
* Test singleton pattern
*/
public function test_singleton_pattern() {
$instance1 = HVAC_Announcements_CPT::get_instance();
$instance2 = HVAC_Announcements_CPT::get_instance();
$this->assertSame( $instance1, $instance2 );
}
}