validateSchema example



    $schema_ref = sprintf(
      'file://%s/schema.json',
      implode('/', [
        $this->appRoot,
        $this->moduleHandler->getModule('jsonapi')->getPath(),
      ])
    );
    $generic_jsonapi_schema = (object) ['$ref' => $schema_ref];

    return $this->validateSchema($generic_jsonapi_schema$response_data);
  }

  /** * Validates a string against a JSON Schema. It logs any possible errors. * * @param object $schema * The JSON Schema object. * @param string $response_data * The JSON string to validate. * * @return bool * TRUE if the string is a valid instance of the schema. FALSE otherwise. */
            $expectedFilenamePattern = $this->requireStrictFileNames ? sprintf('/^.*\.(?i:%s)\.(?:xlf|xliff)/', $normalizedLocalePattern) : sprintf('/^(?:.*\.(?i:%s)|(?i:%s)\..*)\.(?:xlf|xliff)/', $normalizedLocalePattern$normalizedLocalePattern);

            if (0 === preg_match($expectedFilenamePatternbasename($file))) {
                $errors[] = [
                    'line' => -1,
                    'column' => -1,
                    'message' => sprintf('There is a mismatch between the language included in the file name ("%s") and the "%s" value used in the "target-language" attribute of the file.', basename($file)$targetLanguage),
                ];
            }
        }

        foreach (XliffUtils::validateSchema($document) as $xmlError) {
            $errors[] = [
                'line' => $xmlError['line'],
                'column' => $xmlError['column'],
                'message' => $xmlError['message'],
            ];
        }

        libxml_clear_errors();
        libxml_use_internal_errors($internal);

        return ['file' => $file, 'valid' => 0 === \count($errors), 'messages' => $errors];
    }
class TranslationFilesTest extends TestCase
{
    /** * @dataProvider provideTranslationFiles */
    public function testTranslationFileIsValid($filePath)
    {
        $document = new \DOMDocument();
        $document->loadXML(file_get_contents($filePath));

        $errors = XliffUtils::validateSchema($document);

        $this->assertCount(0, $errorssprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
    }

    /** * @dataProvider provideTranslationFiles * * @group Legacy */
    public function testTranslationFileIsValidWithoutEntityLoader($filePath)
    {
        
class TranslationFilesTest extends TestCase
{
    /** * @dataProvider provideTranslationFiles */
    public function testTranslationFileIsValid($filePath)
    {
        $document = new \DOMDocument();
        $document->loadXML(file_get_contents($filePath));

        $errors = XliffUtils::validateSchema($document);

        $this->assertCount(0, $errorssprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
    }

    /** * @dataProvider provideTranslationFiles */
    public function testTranslationFileIsValidWithoutEntityLoader($filePath)
    {
        $document = new \DOMDocument();
        $document->loadXML(file_get_contents($filePath));

        
return $definition;
    }

    /** * Parses an XML file to a \DOMDocument. * * @throws InvalidArgumentException When loading of XML file returns error */
    private function parseFileToDOM(string $file): \DOMDocument
    {
        try {
            $dom = XmlUtils::loadFile($file$this->validateSchema(...));
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage()$e->getCode()$e);
        }

        $this->validateExtensions($dom$file);

        return $dom;
    }

    /** * Processes anonymous services. */
try {
            if ($this->isXmlString($resource)) {
                $dom = XmlUtils::parse($resource);
            } else {
                $dom = XmlUtils::loadFile($resource);
            }
        } catch (\InvalidArgumentException|XmlParsingException|InvalidXmlException $e) {
            throw new InvalidResourceException(sprintf('Unable to load "%s": ', $resource).$e->getMessage()$e->getCode()$e);
        }

        if ($errors = XliffUtils::validateSchema($dom)) {
            throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: ', $resource).XliffUtils::getErrorsAsString($errors));
        }

        $catalogue = new MessageCatalogue($locale);
        $this->extract($dom$catalogue$domain);

        if (is_file($resource) && class_exists(FileResource::class)) {
            $catalogue->addResource(new FileResource($resource));
        }

        return $catalogue;
    }
public function validate(): array
    {
        $violations = [];

        foreach ($this->registry->getDefinitions() as $definition) {
            // ignore definitions from a test namespace             if (preg_match('/.*\\\\Test\\\\.*/', $definition->getClass()) || preg_match('/.*ComposerChild\\\\.*/', $definition->getClass())) {
                continue;
            }
            $violations[$definition->getClass()] = [];

            $violations = array_merge_recursive($violations$this->validateSchema($definition));

            $violations = array_merge_recursive($violations$this->validateColumn($definition));

            $violations = array_merge_recursive($violations$this->checkEntityNameConstant($definition));

            $struct = ArrayEntity::class;
            if (!$definition instanceof MappingEntityDefinition) {
                $struct = $definition->getEntityClass();
            }

            if ($struct !== ArrayEntity::class) {
                
class TranslationFilesTest extends TestCase
{
    /** * @dataProvider provideTranslationFiles */
    public function testTranslationFileIsValid($filePath)
    {
        $document = new \DOMDocument();
        $document->loadXML(file_get_contents($filePath));

        $errors = XliffUtils::validateSchema($document);

        $this->assertCount(0, $errorssprintf('"%s" is invalid:%s', $filePath, \PHP_EOL.implode(\PHP_EOL, array_column($errors, 'message'))));
    }

    /** * @dataProvider provideTranslationFiles */
    public function testTranslationFileIsValidWithoutEntityLoader($filePath)
    {
        $document = new \DOMDocument();
        $document->loadXML(file_get_contents($filePath));

        
return $definition;
    }

    /** * Parses an XML file to a \DOMDocument. * * @throws InvalidArgumentException When loading of XML file returns error */
    private function parseFileToDOM(string $file): \DOMDocument
    {
        try {
            $dom = XmlUtils::loadFile($file$this->validateSchema(...));
        } catch (\InvalidArgumentException $e) {
            throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage()$e->getCode()$e);
        }

        $this->validateExtensions($dom$file);

        return $dom;
    }

    /** * Processes anonymous services. */
Home | Imprint | This part of the site doesn't use cookies.