-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new test case for new provider and refactored existing one
- Loading branch information
Showing
3 changed files
with
114 additions
and
61 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
tests/lib/Content/Form/Provider/AbstractGroupedContentFormFieldsProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\ContentForms\Content\Form\Provider; | ||
|
||
use Ibexa\Contracts\ContentForms\Data\Content\FieldData; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Field; | ||
use Ibexa\Core\FieldType\TextLine\Value; | ||
use Ibexa\Core\Helper\FieldsGroups\FieldsGroupsList; | ||
use Ibexa\Core\Repository\Values\ContentType\FieldDefinition; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Form\FormInterface; | ||
|
||
abstract class AbstractGroupedContentFormFieldsProviderTest extends TestCase | ||
{ | ||
protected function getFieldsGroupsListMock(): FieldsGroupsList | ||
{ | ||
$mock = $this->createMock(FieldsGroupsList::class); | ||
$mock | ||
->expects($this->exactly(3)) | ||
->method('getFieldGroup') | ||
->withConsecutive() | ||
->willReturnOnConsecutiveCalls('group_1', 'group_2', 'group_2'); | ||
|
||
return $mock; | ||
} | ||
|
||
protected function getFormMockWithFieldData( | ||
string $fieldDefIdentifier, | ||
string $fieldTypeIdentifier | ||
): FormInterface { | ||
$formMock = $this | ||
->getMockBuilder(FormInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$formMock | ||
->expects($this->once()) | ||
->method('getViewData') | ||
->willReturn(new FieldData([ | ||
'field' => new Field(['fieldDefIdentifier' => $fieldDefIdentifier]), | ||
'fieldDefinition' => new FieldDefinition(['fieldTypeIdentifier' => $fieldTypeIdentifier]), | ||
'value' => new Value('value'), | ||
])); | ||
|
||
$formMock | ||
->expects($this->once()) | ||
->method('getName') | ||
->willReturn($fieldDefIdentifier); | ||
|
||
return $formMock; | ||
} | ||
|
||
protected function getTestForms(): array | ||
{ | ||
return [ | ||
$this->getFormMockWithFieldData('first_field', 'first_field_type'), | ||
$this->getFormMockWithFieldData('second_field', 'second_field_type'), | ||
$this->getFormMockWithFieldData('third_field', 'third_field_type'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/lib/Content/Form/Provider/NonLocalizedGroupedContentFormFieldsProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\ContentForms\Content\Form\Provider; | ||
|
||
use Ibexa\ContentForms\Content\Form\Provider\NonLocalizedGroupedContentFormFieldsProvider; | ||
|
||
class NonLocalizedGroupedContentFormFieldsProviderTest extends AbstractGroupedContentFormFieldsProviderTest | ||
{ | ||
public function testGetGroupedFields(): void | ||
{ | ||
$fieldsGroupsListMock = $this->getFieldsGroupsListMock(); | ||
|
||
$subject = new NonLocalizedGroupedContentFormFieldsProvider($fieldsGroupsListMock); | ||
$result = $subject->getGroupedFields($this->getTestForms()); | ||
|
||
$expected = [ | ||
'group_1' => [ | ||
0 => 'first_field', | ||
], | ||
'group_2' => [ | ||
0 => 'second_field', | ||
1 => 'third_field', | ||
], | ||
]; | ||
|
||
$this->assertEquals($expected, $result); | ||
} | ||
} |