Skip to content

Commit

Permalink
Restored deleted files
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof committed Sep 8, 2023
1 parent e02a740 commit a9f279d
Show file tree
Hide file tree
Showing 2 changed files with 407 additions and 0 deletions.
341 changes: 341 additions & 0 deletions tests/lib/Repository/NameSchema/NameSchemaServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,352 @@

namespace Ibexa\Tests\Core\Repository\NameSchema;

use Ibexa\Contracts\Core\Event\NameSchema\AbstractSchemaEvent;
use Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent;
use Ibexa\Contracts\Core\Event\NameSchema\ResolveNameSchemaEvent;
use Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent;
use Ibexa\Contracts\Core\Repository\Values\Content\Field;
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCollection as APIFieldDefinitionCollection;
use Ibexa\Core\FieldType\TextLine\Type as TextLineFieldType;
use Ibexa\Core\FieldType\TextLine\Value as TextLineValue;
use Ibexa\Core\Repository\NameSchema\NameSchemaService;
use Ibexa\Core\Repository\NameSchema\SchemaIdentifierExtractor;
use Ibexa\Core\Repository\Values\Content\Content;
use Ibexa\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Core\Repository\Values\ContentType\ContentType;
use Ibexa\Core\Repository\Values\ContentType\FieldDefinition;
use Ibexa\Core\Repository\Values\ContentType\FieldDefinitionCollection;
use Ibexa\Tests\Core\Repository\Service\Mock\Base as BaseServiceMockTest;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Traversable;

/**
* @covers \Ibexa\Core\Repository\NameSchema\NameSchemaService
*/
final class NameSchemaServiceTest extends BaseServiceMockTest
{
private const NAME_SCHEMA = '<name_schema>';

public function testResolveUrlAliasSchema(): void
{
$content = $this->buildTestContentObject();
$contentType = $this->buildTestContentTypeStub();

$event = new ResolveUrlAliasSchemaEvent(['field' => ['<url_alias_schema>']], $content);

Check failure on line 42 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.

Check failure on line 42 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.

Check failure on line 42 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.
$event->setTokenValues(['eng-GB' => ['url_alias_schema' => 'foo']]);

$nameSchemaService = $this->buildNameSchemaService($event);

$result = $nameSchemaService->resolveUrlAliasSchema($content, $contentType);

self::assertEquals(['eng-GB' => 'foo'], $result);
}

public function testResolveUrlAliasSchemaFallbackToNameSchema(): void
{
$content = $this->buildTestContentObject();
$contentType = $this->buildTestContentTypeStub(self::NAME_SCHEMA, '');

$event = new ResolveUrlAliasSchemaEvent(['field' => [self::NAME_SCHEMA]], $content);

Check failure on line 57 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.

Check failure on line 57 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.

Check failure on line 57 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveUrlAliasSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.
$event->setTokenValues(['eng-GB' => ['name_schema' => 'bar']]);

$nameSchemaService = $this->buildNameSchemaService($event);
$result = $nameSchemaService->resolveUrlAliasSchema($content, $contentType);

self::assertEquals(['eng-GB' => 'bar'], $result);
}

/**
* @return iterable<array<string, array<string, string>>, array<string>, array<string, string>>
*/
public static function getDataForTestResolveNameSchema(): iterable

Check failure on line 69 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::getDataForTestResolveNameSchema() return type has no value type specified in iterable type iterable.

Check failure on line 69 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

PHPDoc tag @return contains unresolvable type.

Check failure on line 69 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::getDataForTestResolveNameSchema() return type has no value type specified in iterable type iterable.

Check failure on line 69 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

PHPDoc tag @return contains unresolvable type.

Check failure on line 69 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::getDataForTestResolveNameSchema() return type has no value type specified in iterable type iterable.

Check failure on line 69 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

PHPDoc tag @return contains unresolvable type.
{
yield 'Default: Field Map and Languages taken from Content Version' => [
[],
[
'eng-GB' => ['text2' => 'two'],
'cro-HR' => ['text2' => 'dva'],
],
[],
[
'eng-GB' => 'two',
'cro-HR' => 'dva',
],
];

yield 'Field Map and Languages for update' => [
[
'text1' => ['cro-HR' => new TextLineValue('jedan'), 'eng-GB' => new TextLineValue('one')],
'text2' => ['cro-HR' => new TextLineValue('Dva'), 'eng-GB' => new TextLineValue('two')],
'text3' => ['eng-GB' => new TextLineValue('three')],
],
[
'eng-GB' => ['text2' => 'two', 'text3' => 'three'],
'cro-HR' => ['text2' => 'Dva'],
],
['eng-GB', 'cro-HR'],
[
'eng-GB' => 'three',
'cro-HR' => 'Dva',
],
];
}

/**
* @dataProvider getDataForTestResolveNameSchema
*
* @param array<string, array<string, string>> $fieldMap A map of Field Definition Identifier and Language Code to Field Value
* @param array<string, array<string, string>> $tokenValues
* @param array<string> $languageCodes
* @param array<string, string> $expectedNames
*/
public function testResolveNameSchema(
array $fieldMap,
array $tokenValues,
array $languageCodes,
array $expectedNames
): void {
$content = $this->buildTestContentObject();
$nameSchema = '<text3|text2>';
$contentType = $this->buildTestContentTypeStub($nameSchema, $nameSchema);
$event = new ResolveContentNameSchemaEvent(
$content,
['field' => ['text3', 'text2']],

Check failure on line 121 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #2 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.

Check failure on line 121 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #2 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.

Check failure on line 121 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #2 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent constructor expects array<string, array<string, string>>, array<string, array<int, string>> given.
$contentType,
$fieldMap,

Check failure on line 123 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #4 $fieldMap of class Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent constructor expects array<int|string, array<string, Ibexa\Contracts\Core\FieldType\Value>>, array<string, array<string, string>> given.

Check failure on line 123 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #4 $fieldMap of class Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent constructor expects array<int|string, array<string, Ibexa\Contracts\Core\FieldType\Value>>, array<string, array<string, string>> given.

Check failure on line 123 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #4 $fieldMap of class Ibexa\Contracts\Core\Event\NameSchema\ResolveContentNameSchemaEvent constructor expects array<int|string, array<string, Ibexa\Contracts\Core\FieldType\Value>>, array<string, array<string, string>> given.
$languageCodes
);
$event->setTokenValues($tokenValues);

$nameSchemaService = $this->buildNameSchemaService(
$event
);

$result = $nameSchemaService->resolveContentNameSchema($content, $fieldMap, $languageCodes, $contentType);

Check failure on line 132 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #2 $fieldMap of method Ibexa\Core\Repository\NameSchema\NameSchemaService::resolveContentNameSchema() expects array<int|string, array<string, Ibexa\Contracts\Core\FieldType\Value>>, array<string, array<string, string>> given.

Check failure on line 132 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #2 $fieldMap of method Ibexa\Core\Repository\NameSchema\NameSchemaService::resolveContentNameSchema() expects array<int|string, array<string, Ibexa\Contracts\Core\FieldType\Value>>, array<string, array<string, string>> given.

Check failure on line 132 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #2 $fieldMap of method Ibexa\Core\Repository\NameSchema\NameSchemaService::resolveContentNameSchema() expects array<int|string, array<string, Ibexa\Contracts\Core\FieldType\Value>>, array<string, array<string, string>> given.

self::assertEquals(
$expectedNames,
$result
);
}

/**
* Data provider for the testResolve method.
*
* @see testResolve
*/
public static function getDataForTestResolve(): array

Check failure on line 145 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::getDataForTestResolve() return type has no value type specified in iterable type array.

Check failure on line 145 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::getDataForTestResolve() return type has no value type specified in iterable type array.

Check failure on line 145 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::getDataForTestResolve() return type has no value type specified in iterable type array.
{
return [
[
['text1'],
'<text1>',
[
'eng-GB' => 'one',
'cro-HR' => 'jedan',
],
[
'eng-GB' => ['text1' => 'one'],
'cro-HR' => ['text1' => 'jedan'],
],
],
[
['text2'],
'<text2>',
[
'eng-GB' => 'two',
'cro-HR' => 'dva',
],
[
'eng-GB' => ['text2' => 'two'],
'cro-HR' => ['text2' => 'dva'],
],
],
[
['text1', 'text2'],
'Hello, <text1> and <text2> and then goodbye and hello again',
[
'eng-GB' => 'Hello, one and two and then goodbye...',
'cro-HR' => 'Hello, jedan and dva and then goodb...',
],
[
'eng-GB' => ['text1' => 'one', 'text2' => 'two'],
'cro-HR' => ['text1' => 'jedan', 'text2' => 'dva'],
],
[
'limit' => 38,
'sequence' => '...',
],
],
];
}

/**
* @dataProvider getDataForTestResolve
*
* @param string[] $schemaIdentifiers
* @param string[] $languageFieldValues field value translations
* @param string[] $fieldTitles [language => [field_identifier => title]]
* @param array $settings NameSchemaService settings
*/
public function testResolve(

Check failure on line 199 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::testResolve() has parameter $settings with no value type specified in iterable type array.

Check failure on line 199 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::testResolve() has parameter $settings with no value type specified in iterable type array.

Check failure on line 199 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Method Ibexa\Tests\Core\Repository\NameSchema\NameSchemaServiceTest::testResolve() has parameter $settings with no value type specified in iterable type array.
array $schemaIdentifiers,
string $nameSchema,
array $languageFieldValues,
array $fieldTitles,
array $settings = []
): void {
$content = $this->buildTestContentObject();
$contentType = $this->buildTestContentTypeStub($nameSchema, $nameSchema);

$event = new ResolveNameSchemaEvent(
$schemaIdentifiers,

Check failure on line 210 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveNameSchemaEvent constructor expects array<string, array<string, string>>, array<string> given.

Check failure on line 210 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveNameSchemaEvent constructor expects array<string, array<string, string>>, array<string> given.

Check failure on line 210 in tests/lib/Repository/NameSchema/NameSchemaServiceTest.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Parameter #1 $schemaIdentifiers of class Ibexa\Contracts\Core\Event\NameSchema\ResolveNameSchemaEvent constructor expects array<string, array<string, string>>, array<string> given.
$contentType,
$content->fields,
$content->versionInfo->languageCodes
);

$event->setTokenValues($fieldTitles);

$nameSchemaService = $this->buildNameSchemaService(
$event,
$settings
);

$result = $nameSchemaService->resolveNameSchema(
$nameSchema,
$contentType,
$content->fields,
$content->versionInfo->languageCodes
);

self::assertEquals($languageFieldValues, $result);
}

/**
* @return \Traversable<\Ibexa\Contracts\Core\Repository\Values\Content\Field>
*/
protected function getFields(): Traversable
{
$translatedFieldValueMap = [
'eng-GB' => [
'text1' => 'one',
'text2' => 'two',
'text3' => '',
],
'cro-HR' => [
'text1' => 'jedan',
'text2' => 'dva',
'text3' => '',
],
];

foreach ($translatedFieldValueMap as $languageCode => $fieldValues) {
foreach ($fieldValues as $fieldDefinitionIdentifier => $textValue) {
yield new Field(
[
'languageCode' => $languageCode,
'fieldDefIdentifier' => $fieldDefinitionIdentifier,
'value' => new TextLineValue($textValue),
'fieldTypeIdentifier' => 'ezstring',
]
);
}
}
}

protected function getFieldDefinitions(): APIFieldDefinitionCollection
{
return new FieldDefinitionCollection(
[
new FieldDefinition(
[
'id' => '1',
'identifier' => 'text1',
'fieldTypeIdentifier' => 'ezstring',
]
),
new FieldDefinition(
[
'id' => '2',
'identifier' => 'text2',
'fieldTypeIdentifier' => 'ezstring',
]
),
new FieldDefinition(
[
'id' => '3',
'identifier' => 'text3',
'fieldTypeIdentifier' => 'ezstring',
]
),
]
);
}

/**
* Build Content Object stub for testing purpose.
*
* @return \Ibexa\Contracts\Core\Repository\Values\Content\Content
*/
protected function buildTestContentObject()
{
return new Content(
[
'internalFields' => iterator_to_array($this->getFields()),
'versionInfo' => new VersionInfo(
[
'languageCodes' => ['eng-GB', 'cro-HR'],
]
),
]
);
}

protected function buildTestContentTypeStub(
string $nameSchema = '<name_schema>',
string $urlAliasSchema = '<url_alias_schema>'
): ContentType {
return new ContentType(
[
'nameSchema' => $nameSchema,
'urlAliasSchema' => $urlAliasSchema,
'fieldDefinitions' => $this->getFieldDefinitions(),
]
);
}

/**
* @param array<string, array<string, string>> $schemaIdentifiers
*/
protected function getEventDispatcherMock(
AbstractSchemaEvent $event
): EventDispatcherInterface {
$eventDispatcherMock = $this->getEventDispatcher();
$eventDispatcherMock->method('dispatch')
->willReturn($event);

return $eventDispatcherMock;
}

/**
* @param array{limit?: integer, sequence?: string} $settings
*/
private function buildNameSchemaService(
AbstractSchemaEvent $event,
array $settings = []
): NameSchemaService {
$fieldTypeRegistryMock = $this->getFieldTypeRegistryMock();
$fieldTypeRegistryMock
->method('getFieldType')
->with('ezstring')
->willReturn(new TextLineFieldType());

return new NameSchemaService(
$fieldTypeRegistryMock,
new SchemaIdentifierExtractor(),
$this->getEventDispatcherMock($event),
$settings
);
}
}
Loading

0 comments on commit a9f279d

Please sign in to comment.