PHP code example of sbuerk / typo3-site-based-test-trait

1. Go to this page and download the library: Download sbuerk/typo3-site-based-test-trait library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sbuerk / typo3-site-based-test-trait example snippets


$this->writeSiteConfiguration(
    identifier: 'acme',
    site: [], // $this->buildSiteConfiguration(...)
    languages: [], // [$this->buildDefaultLanguageConfiguration(...), $this->buildLanguageConfiguration(...), ...]
    errorHandling: [], // $this->buildErrorHandlingConfiguration(...)
    // additional content
    additional: [
      'settings' => [
        'some_settings' => 123,
      ],
    ],
);

$this->writeSiteConfiguration(
    identifier: 'acme',
    site: [], // $this->buildSiteConfiguration(...)
    languages: [], // [$this->buildDefaultLanguageConfiguration(...), $this->buildLanguageConfiguration(...), ...]
    errorHandling: [], // $this->buildErrorHandlingConfiguration(...)
    // additional content
    additional: [
      'dependencies' => [
        'my-vendor/site-set-identifier',
      ],
    ],
);

$this->buildSiteConfiguration(
    rootPageId: 1,
    base: 'https://acme.com/',
    websiteTitle: 'Home',
    additionalRootConfiguration: [
      'settings' => [
        'some_settings' => 123,
      ],    
    ],
);

/**
 * @param non-empty-string $base
 * @param non-empty-string $websiteTitle
 * @param array<non-empty-string, mixed> $additionalRootConfiguration
 * @return array<non-empty-string, mixed>
 */
protected function buildSiteConfiguration(
    int $rootPageId,
    string $base = '/',
    string $websiteTitle = 'Home',
    array $additionalRootConfiguration = [],
): array {}

protected const LANGUAGE_PRESETS = [
    'EN' => [
        'id' => 0,
        'title' => 'English',
        'locale' => 'en_US.UTF8',
        // custom values added to the language block
        'custom' => [
            'deepltranslate_language' => 'EN',
        ],
    ],
    'FR' => [
        'id' => 1,
        'title' => 'French',
        'locale' => 'fr_FR.UTF8',
        // custom values added to the language block
        'custom' => [
            'deepltranslate_language' => 'FR',
        ],        
    ],
];

/**
 * Sets up a root-page containing TypoScript settings for frontend testing.
 *
 * Parameter `$typoScriptFiles` can either be
 * + `[
 *      'EXT:extension/path/first.typoscript',
 *      'EXT:extension/path/second.typoscript'
 *    ]`
 *   which just loads files to the setup setion of the TypoScript template
 *   record (legacy behavior of this method)
 * + `[
 *      'constants' => ['EXT:extension/path/constants.typoscript'],
 *      'setup' => ['EXT:extension/path/setup.typoscript']
 *    ]`
 *   which allows to define contents for the `constants` and `setup` part
 *   of the TypoScript template record at the same time
 *
 * @param int $pageId
 * @param array{constants?: string[], setup?: string[]}|string[] $typoScriptFiles
 * @param array<string, mixed> $templateValues
 * @param bool $createSysTemplateRecord TRUE if sys_template record should be created, FALSE does not create one
 *                                      but removes an existing one.
 */
protected function setUpFrontendRootPage(
    int $pageId,
    array $typoScriptFiles = [],
    array $templateValues = [],
    bool $createSysTemplateRecord = true,
): void;

$this->setUpFrontendRootPage(
    pageId: 1000,
    createSysTemplateRecord: false,
);

$this->setUpFrontendRootPage(
    1000,
    [], // will be ignored/not used due to false as 4th argument
    [], // will be ignored/not used due to false as 4th argument
    false,
);