<?php
/**
 * Characterization tests for the hello-world ppok/system/ping ability.
 *
 * @package Ppok\AIToolkit\Tests
 * @license GPL-2.0-or-later
 */

namespace Ppok\AIToolkit\Tests;

use Ppok\AIToolkit\Abilities\System_Ping;

class Test_System_Ping extends \WP_UnitTestCase {

	public function test_slug_constant(): void {
		$this->assertSame( 'ppok/ping', System_Ping::SLUG );
	}

	public function test_descriptor_has_required_keys(): void {
		$d = System_Ping::descriptor();

		foreach ( array( 'label', 'description', 'input_schema', 'output_schema', 'permission_callback', 'execute_callback', 'meta' ) as $key ) {
			$this->assertArrayHasKey( $key, $d, "Descriptor missing required key: {$key}" );
		}
	}

	public function test_descriptor_marks_read_only_and_mcp_public(): void {
		$d = System_Ping::descriptor();
		$this->assertFalse( $d['meta']['ppok']['write'], 'Ping must be read-only.' );
		$this->assertTrue( $d['meta']['mcp']['public'], 'Ping must be exposed to MCP.' );
	}

	public function test_execute_returns_site_name_and_version(): void {
		$result = System_Ping::execute_callback();

		$this->assertArrayHasKey( 'site_name', $result );
		$this->assertArrayHasKey( 'plugin_version', $result );
		$this->assertIsString( $result['site_name'] );
		$this->assertSame( PPOK_AI_TOOLKIT_VERSION, $result['plugin_version'] );
	}

	public function test_permission_callback_requires_read_cap(): void {
		// A logged-out visitor should not pass.
		wp_set_current_user( 0 );
		$this->assertFalse( System_Ping::permission_callback() );

		// A subscriber (has 'read' cap) should pass.
		$subscriber = self::factory()->user->create( array( 'role' => 'subscriber' ) );
		wp_set_current_user( $subscriber );
		$this->assertTrue( System_Ping::permission_callback() );
	}
}
