- Added GitHub spec-kit for development workflow - Standardized file signatures to Descomplicar® format - Updated development configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
184 lines
4.5 KiB
PHP
184 lines
4.5 KiB
PHP
/**
|
|
* Descomplicar® Crescimento Digital
|
|
* https://descomplicar.pt
|
|
*/
|
|
|
|
<?php
|
|
/**
|
|
* Test utilities for Care Booking Block plugin
|
|
*
|
|
* @package CareBookingBlock
|
|
*/
|
|
|
|
/**
|
|
* Base test case for Care Booking Block plugin
|
|
*/
|
|
class Care_Booking_Test_Case extends WP_UnitTestCase
|
|
{
|
|
/**
|
|
* Plugin instance
|
|
*
|
|
* @var CareBookingBlock
|
|
*/
|
|
protected $plugin;
|
|
|
|
/**
|
|
* Test user ID
|
|
*
|
|
* @var int
|
|
*/
|
|
protected $admin_user_id;
|
|
|
|
/**
|
|
* Set up test case
|
|
*/
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Get plugin instance
|
|
$this->plugin = CareBookingBlock::get_instance();
|
|
|
|
// Create admin user for capability tests
|
|
$this->admin_user_id = $this->factory->user->create([
|
|
'role' => 'administrator'
|
|
]);
|
|
|
|
// Clean test database
|
|
$this->clean_test_data();
|
|
|
|
// Create test data
|
|
$this->create_test_data();
|
|
}
|
|
|
|
/**
|
|
* Tear down test case
|
|
*/
|
|
public function tearDown(): void
|
|
{
|
|
$this->clean_test_data();
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* Clean test data from database
|
|
*/
|
|
protected function clean_test_data()
|
|
{
|
|
global $wpdb;
|
|
|
|
// Clean restrictions table
|
|
$table_name = $wpdb->prefix . 'care_booking_restrictions';
|
|
$wpdb->query("DELETE FROM $table_name WHERE target_id >= 999");
|
|
|
|
// Clear test caches
|
|
delete_transient('care_booking_doctors_blocked');
|
|
delete_transient('care_booking_restrictions_hash');
|
|
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_care_booking_services_blocked_99%'");
|
|
}
|
|
|
|
/**
|
|
* Create test data
|
|
*/
|
|
protected function create_test_data()
|
|
{
|
|
// This method can be overridden by child classes
|
|
// to create specific test data
|
|
}
|
|
|
|
/**
|
|
* Create test doctor restriction
|
|
*
|
|
* @param int $doctor_id Doctor ID
|
|
* @param bool $is_blocked Whether doctor is blocked
|
|
* @return int|false Restriction ID or false on failure
|
|
*/
|
|
protected function create_test_doctor_restriction($doctor_id, $is_blocked = true)
|
|
{
|
|
global $wpdb;
|
|
|
|
$table_name = $wpdb->prefix . 'care_booking_restrictions';
|
|
|
|
$result = $wpdb->insert(
|
|
$table_name,
|
|
[
|
|
'restriction_type' => 'doctor',
|
|
'target_id' => $doctor_id,
|
|
'doctor_id' => null,
|
|
'is_blocked' => $is_blocked
|
|
],
|
|
['%s', '%d', '%d', '%d']
|
|
);
|
|
|
|
return $result ? $wpdb->insert_id : false;
|
|
}
|
|
|
|
/**
|
|
* Create test service restriction
|
|
*
|
|
* @param int $service_id Service ID
|
|
* @param int $doctor_id Doctor ID
|
|
* @param bool $is_blocked Whether service is blocked
|
|
* @return int|false Restriction ID or false on failure
|
|
*/
|
|
protected function create_test_service_restriction($service_id, $doctor_id, $is_blocked = true)
|
|
{
|
|
global $wpdb;
|
|
|
|
$table_name = $wpdb->prefix . 'care_booking_restrictions';
|
|
|
|
$result = $wpdb->insert(
|
|
$table_name,
|
|
[
|
|
'restriction_type' => 'service',
|
|
'target_id' => $service_id,
|
|
'doctor_id' => $doctor_id,
|
|
'is_blocked' => $is_blocked
|
|
],
|
|
['%s', '%d', '%d', '%d']
|
|
);
|
|
|
|
return $result ? $wpdb->insert_id : false;
|
|
}
|
|
|
|
/**
|
|
* Assert AJAX response structure
|
|
*
|
|
* @param array $response AJAX response
|
|
* @param bool $should_succeed Whether response should indicate success
|
|
*/
|
|
protected function assert_ajax_response($response, $should_succeed = true)
|
|
{
|
|
$this->assertIsArray($response);
|
|
$this->assertArrayHasKey('success', $response);
|
|
$this->assertArrayHasKey('data', $response);
|
|
|
|
if ($should_succeed) {
|
|
$this->assertTrue($response['success']);
|
|
} else {
|
|
$this->assertFalse($response['success']);
|
|
$this->assertArrayHasKey('message', $response['data']);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Mock WordPress nonce for testing
|
|
*
|
|
* @param string $action Nonce action
|
|
* @return string
|
|
*/
|
|
protected function mock_wp_nonce($action = 'care_booking_nonce')
|
|
{
|
|
return wp_create_nonce($action);
|
|
}
|
|
|
|
/**
|
|
* Set current user and mock capabilities
|
|
*
|
|
* @param int $user_id User ID
|
|
*/
|
|
protected function set_current_user($user_id)
|
|
{
|
|
wp_set_current_user($user_id);
|
|
}
|
|
} |