<?php
/**
 * Tests for the bundled Markdown documentation renderer.
 *
 * @package GravityOps\Core
 */

namespace GOSP\GravityOps\Core\Tests\Unit;

use GOSP\GravityOps\Core\SuiteCore\Admin\DocsRenderer;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use ReflectionMethod;

/**
 * Tests documentation article link behavior.
 */
final class DocsRendererTest extends TestCase {

	/**
	 * External links open separately without changing local article navigation.
	 *
	 * @return void
	 */
	public function test_external_links_open_in_new_tab(): void {
		$reflection = new ReflectionClass( DocsRenderer::class );
		$renderer   = $reflection->newInstanceWithoutConstructor();
		$method     = new ReflectionMethod( DocsRenderer::class, 'add_heading_ids_and_toc' );
		$method->setAccessible( true );

		$result = $method->invoke(
			$renderer,
			'<p><a href="https://example.com/docs">External</a> <a href="#local">Local</a> <a href="../other.md">Relative</a></p>'
		);

		$this->assertStringContainsString( 'href="https://example.com/docs" target="_blank" rel="noopener noreferrer"', $result['html'] );
		$this->assertStringContainsString( '<a href="#local">Local</a>', $result['html'] );
		$this->assertStringContainsString( '<a href="../other.md">Relative</a>', $result['html'] );
	}
}
