This commit is contained in:
alorig
2025-11-22 08:07:56 +05:00
parent 84c18848b0
commit 3580acf61e
42 changed files with 13124 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
<?php
/**
* Unit test for API key revoke handler
*
* @package Igny8Bridge
*/
class Test_Revoke_Api_Key extends WP_UnitTestCase {
public function test_revoke_api_key_clears_options() {
// Simulate stored API key and tokens
update_option('igny8_api_key', 'test-key-123');
update_option('igny8_access_token', 'test-key-123');
update_option('igny8_refresh_token', 'refresh-123');
update_option('igny8_token_refreshed_at', time());
// Call revoke
Igny8Admin::revoke_api_key();
// Assert removed
$this->assertFalse(get_option('igny8_api_key'));
$this->assertFalse(get_option('igny8_access_token'));
$this->assertFalse(get_option('igny8_refresh_token'));
$this->assertFalse(get_option('igny8_token_refreshed_at'));
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* Basic unit test for site-metadata endpoint
*
* @package Igny8Bridge
*/
class Test_Site_Metadata_Endpoint extends WP_UnitTestCase {
public function test_site_metadata_endpoint_returns_success() {
// Ensure connection enabled
update_option('igny8_connection_enabled', 1);
// Create a fake API key so permission checks pass via Igny8API
update_option('igny8_api_key', 'test-api-key-123');
update_option('igny8_access_token', 'test-api-key-123');
// Build request
$request = new WP_REST_Request('GET', '/igny8/v1/site-metadata/');
$request->set_header('Authorization', 'Bearer test-api-key-123');
$server = rest_get_server();
$response = $server->dispatch($request);
$this->assertEquals(200, $response->get_status());
$data = $response->get_data();
$this->assertNotEmpty($data);
$this->assertArrayHasKey('success', $data);
$this->assertTrue($data['success']);
$this->assertArrayHasKey('data', $data);
$this->assertArrayHasKey('post_types', $data['data']);
$this->assertArrayHasKey('taxonomies', $data['data']);
}
}