<commit_before><?php
namespace T3v\T3vCore\Tests\Functional;

use TYPO3\CMS\Core\Utility\GeneralUtility;

use Nimut\TestingFramework\Http\Response;
use Nimut\TestingFramework\TestCase\FunctionalTestCase;

use PHPUnit\Util\PHP\DefaultPhpProcess;

/**
 * Rendering Test Class
 *
 * @package T3v\T3vCore\Tests\Functional
 */
class RenderingTest extends FunctionalTestCase {
  /**
   * The core extensions to load.
   *
   * @var array
   */
  protected $coreExtensionsToLoad = ['fluid'];

  /**
   * The test extensions to load.
   *
   * @var array
   */
  protected $testExtensionsToLoad = ['typo3conf/ext/t3v_core'];

  /**
   * Test if template is rendered.
   *
   * @test
   */
  public function templateIsRendered() {
    $expectedDom = new \DomDocument();
    $expectedDom->preserveWhiteSpace = false;
    $expectedDom->loadHTML('<h1>T3v Core</h1>');

    $actualDom = new \DomDocument();
    $actualDom->preserveWhiteSpace = false;
    $actualDom->loadHTML($this->fetchFrontendResponse(['id' => '1'])->getContent());

    $this->assertXmlStringEqualsXmlString($expectedDom->saveHTML(), $actualDom->saveHTML());
  }

  /**
   * Setup before running tests.
   *
   * @return void
   */
  protected function setUp() {
    parent::setUp();

    $this->importDataSet(__DIR__ . '/Fixtures/Database/Pages.xml');

    $this->setUpFrontendRootPage(1, ['EXT:t3v_core/Tests/Functional/Fixtures/Frontend/Basic.ts']);
  }

  /**
   * Helper function to fetch the Front-end response.
   *
   * @param array $requestArguments The request arguments
   * @param boolean $failOnFailure Fail on failure, defaults to `true`
   * @return \Nimut\TestingFramework\Http\Response The Front-end response
   */
  protected function fetchFrontendResponse(array $requestArguments, $failOnFailure = true) {
    $failOnFailure = (boolean) $failOnFailure;

    if (!empty($requestArguments['url'])) {
      $requestUrl = '/' . ltrim($requestArguments['url'], '/');
    } else {
      $requestUrl = '/?' . GeneralUtility::implodeArrayForUrl('', $requestArguments);
    }

    if (property_exists($this, 'instancePath')) {
      $instancePath = $this->instancePath;
    } else {
      $instancePath = $this->getInstancePath();
    }

    $arguments = [
      'documentRoot' => $instancePath,
      'requestUrl'   => 'http://localhost' . $requestUrl
    ];

    $template = new \Text_Template('ntf://Frontend/Request.tpl');
    $template->setVar([
      'arguments'    => var_export($arguments, true),
      'originalRoot' => ORIGINAL_ROOT,
      'ntfRoot'      => __DIR__ . '/../../.build/vendor/nimut/testing-framework/'
    ]);

    $php = DefaultPhpProcess::factory();

    $response = $php->runJob($template->render());

    $result = json_decode($response['stdout'], true);

    if ($result === null) {
      $this->fail('Frontend Response is empty:' . LF . 'Error: ' . LF . $response['stderr']);
    }<commit_msg>[♻] Cleaned up.<commit_after><?php
namespace T3v\T3vCore\Tests\Functional;

use TYPO3\CMS\Core\Utility\GeneralUtility;

use Nimut\TestingFramework\Http\Response;
use Nimut\TestingFramework\TestCase\FunctionalTestCase;

use PHPUnit\Util\PHP\DefaultPhpProcess;

/**
 * Rendering Test Class
 *
 * @package T3v\T3vCore\Tests\Functional
 */
class RenderingTest extends FunctionalTestCase {
  /**
   * The core extensions to load.
   *
   * @var array
   */
  protected $coreExtensionsToLoad = ['fluid'];

  /**
   * The test extensions to load.
   *
   * @var array
   */
  protected $testExtensionsToLoad = ['typo3conf/ext/t3v_core'];

  /**
   * Test if template is rendered.
   *
   * @test
   */
  public function templateIsRendered() {
    $expectedDom = new \DomDocument();
    $expectedDom->preserveWhiteSpace = false;
    $expectedDom->loadHTML('<h1>T3v Core</h1>');

    $actualDom = new \DomDocument();
    $actualDom->preserveWhiteSpace = false;
    $actualDom->loadHTML($this->fetchFrontendResponse(['id' => '1'])->getContent());

    $this->assertXmlStringEqualsXmlString($expectedDom->saveHTML(), $actualDom->saveHTML());
  }

  /**
   * Setup before running tests.
   *
   * @return void
   */
  protected function setUp() {
    parent::setUp();

    $this->importDataSet(__DIR__ . '/Fixtures/Database/Pages.xml');

    $this->setUpFrontendRootPage(1, ['EXT:t3v_core/Tests/Functional/Fixtures/Frontend/Basic.ts']);
  }

  /**
   * Helper function to fetch the Front-end response.
   *
   * @param array $requestArguments The request arguments
   * @param boolean $failOnFailure Fail on failure, defaults to `true`
   * @return \Nimut\TestingFramework\Http\Response The Front-end response
   */
  protected function fetchFrontendResponse(array $requestArguments, $failOnFailure = true) {
    $failOnFailure = (boolean) $failOnFailure;

    if (!empty($requestArguments['url'])) {
      $requestUrl = '/' . ltrim($requestArguments['url'], '/');
    } else {
      $requestUrl = '/?' . GeneralUtility::implodeArrayForUrl('', $requestArguments);
    }

    if (property_exists($this, 'instancePath')) {
      $instancePath = $this->instancePath;
    } else {
      $instancePath = $this->getInstancePath();
    }

    $arguments = [
      'documentRoot' => $instancePath,
      'requestUrl'   => 'http://localhost' . $requestUrl
    ];

    $template = new \Text_Template('ntf://Frontend/Request.tpl');
    $template->setVar([
      'arguments'    => var_export($arguments, true),
      'originalRoot' => ORIGINAL_ROOT,
      'ntfRoot'      => __DIR__ . '/../../.build/vendor/nimut/testing-framework/'
    ]);

    $php      = DefaultPhpProcess::factory();
    $response = $php->runJob($template->render());
    $result   = json_decode($response['stdout'], true);

    if ($result === null) {
      $this->fail('Frontend Response is empty:' . LF . 'Error: ' . LF . $response['stderr']);
    }
{'fraction_non_alphanumeric': 0.16064950768699257, 'fraction_numerical': 0.00449127655899119, 'mean_word_length': 3.40974866717441, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6699315', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1796, 'n_words': 336}