Aliyya_Putri_Setiyomadani/form-testing/tests/GetFormPHPTest.php
2024-12-31 11:09:29 +07:00

46 lines
1.5 KiB
PHP

<?php
require_once __DIR__ . '/helper/TestResultsManager.php';
use PHPUnit\Framework\TestCase;
class GetFormPHPTest extends TestCase
{
private $testResultsManager;
protected function setUp(): void
{
$this->testResultsManager = new TestResultsManager();
}
public function testGetFormHandlingResult()
{
try {
$testCase = get_class($this) . '.' . __FUNCTION__;
$_GET['yourName'] = 'AliyyaPS';
$_GET['yourAddress'] = 'Sidoarjo';
ob_start();
include_once './apps/getFormHandling.php';
$output = ob_get_clean();
$dom = new DOMDocument();
$dom->loadHTML($output);
$titleElemen = $dom->getElementsByTagName('title')->item(0);
$this->assertEquals('Get Form Handling', $titleElemen->nodeValue, 'The text content of the title element on the page should be "Get Form Handling"');
$h3Elemen = $dom->getElementsByTagName('h3')->item(0);
$this->assertEquals('Welcome!!', $h3Elemen->nodeValue, 'Text content of the h3 element should be "Welcome!!"');
$pElemen = $dom->getElementsByTagName('p')->item(0);
$this->assertStringContainsString('AliyyaPS from', $pElemen->nodeValue);
$this->assertStringContainsString('Sidoarjo', $pElemen->nodeValue);
$this->testResultsManager->showTestResult($testCase);
} catch (\Throwable $e) {
$this->testResultsManager->showTestResult($testCase, $e);
throw $e;
}
}
}