Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-30662: Add proof of concept cache scenario #86

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@ behat:
suites:
examples:
paths:
- '%paths.base%/vendor/ezsystems/behatbundle/features/'
- '%paths.base%/vendor/ezsystems/behatbundle/features/examples'
contexts:
- EzSystems\Behat\API\Context\TestContext:
userService: '@ezpublish.api.service.user'
permissionResolver: '@eZ\Publish\API\Repository\PermissionResolver'
- EzSystems\Behat\API\Context\ObjectStateContext:
objectStateService: '@ezpublish.api.service.object_state'
- EzSystems\Behat\API\Context\ContentContext:
contentFacade: '@ezbehatbundle.api.facade.contentfacade'
contentFacade: '@EzSystems\Behat\API\Facade\ContentFacade'
argumentParser: '@EzSystems\Behat\Core\Behat\ArgumentParser'
- EzSystems\Behat\API\Context\ContentTypeContext:
contentTypeFacade: '@ezbehatbundle.api.facade.contenttypefacade'
contentTypeFacade: '@EzSystems\Behat\API\Facade\ContentTypeFacade'
- EzSystems\Behat\API\Context\UserContext:
userFacade: '@ezbehatbundle.api.facade.userfacade'
userFacade: '@EzSystems\Behat\API\Facade\UserFacade'
- EzSystems\Behat\API\Context\RoleContext:
roleFacade: '@ezbehatbundle.api.facade.rolefacade'
roleFacade: '@EzSystems\Behat\API\Facade\RoleFacade'
- EzSystems\Behat\API\Context\LanguageContext:
languageFacade: '@ezbehatbundle.api.facade.languagefacade'
languageFacade: '@EzSystems\Behat\API\Facade\LanguageFacade'
- EzSystems\Behat\Core\Context\ConfigurationContext:
projectDir: '%paths.base%'
projectDir: '%paths.base%'
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
"ezsystems/ezpublish-kernel": "^8.0@dev",
"fzaninotto/faker": "^1.8",
"behat/behat": "^3.5",
"behat/mink": "^1.7",
"behat/mink-selenium2-driver": "^1.3",
"behat/symfony2-extension": "^2.1",
"behat/mink-extension": "^2.3",
"symfony/property-access": "^4.3",
"symfony/yaml": "^4.3",
"symfony/config": "^4.3",
Expand Down
36 changes: 0 additions & 36 deletions features/content_creation.feature

This file was deleted.

File renamed without changes.
76 changes: 76 additions & 0 deletions features/examples/content.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Feature: Example scenarios showing how to use steps involving Languages, Content Types and Content Items

@admin
Scenario Outline: Create a language, Content Type and Content Items
Given Language "Polski" with code "pol-PL" exists
And I create a "<contentTypeName>" Content Type in "Content" with "<contentTypeIdentifier>" identifier
| Field Type | Name | Identifier | Required | Searchable | Translatable |
| Text line | Name | name | yes | yes | yes |
| <fieldType> | TestedField | testedfield | yes | no | yes |
And I create "Folder" Content items in root in "pol-PL"
| name | short_name |
| <contentTypeName> | <contentTypeName> |
And I create 50 "<contentTypeIdentifier>" Content items in "<contentTypeName>" in "pol-PL"

Examples:
| contentTypeName | contentTypeIdentifier | fieldType |
| RichText CT | RichTextCT | Rich text |
| URL CT | URLCT | URL |
| Email CT | EmailCT | Email address |
| Textline CT | TextlineCT | Text line |
| ISBN CT | IsbnCT | ISBN |
| Authors CT | AuthorsCT | Authors |
| Text block CT | TextBlockCT | Text block |
| Checkbox CT | CheckboxCT | Checkbox |
| Country CT | CountryCT | Country |
| Date CT | DateCT | Date |
| Time CT | TimeCT | Time |
| Float CT | FloatCT | Float |
| Integer CT | Integer | Integer |
| Map location CT | MapLocationCT | Map location |
| Date and time CT | DateAndTimeCT | Date and time |
| Content relation CT | ContentRelationCT | Content relation (single) |
| Content relations CT | ContentRelationsCT | Content relations (multiple) |
| Image CT | ImageCT | Image |
| File CT | FileCT | File |
| Media CT | MediaCT | Media |

@admin
Scenario Outline: Create a Content item and edit specified field
Given I create a "<contentTypeName>" Content Type in "Content" with "<contentTypeIdentifier>" identifier
| Field Type | Name | Identifier | Required | Searchable | Translatable |
| Text line | Name | name | yes | yes | yes |
| <fieldType> | TestedField | testedfield | yes | no | yes |
And I create <contentTypeIdentifier> Content items in root in "eng-GB"
| name |
| <contentTypeName> |
And I create "Folder" Content items in root in "eng-GB"
| name | short_name |
| RelationFolder1 | RelationFolder1 |
| RelationFolder2 | RelationFolder2 |
When I edit "<contentTypeName>" Content item in "eng-GB"
| testedfield |
| <valueToSet> |

Examples:
| contentTypeName | contentTypeIdentifier | fieldType | valueToSet |
| RichText CT2 | RichTextCT2 | Rich text | EditedField |
| URL CT2 | URLCT2 | URL | www.ez.no |
| Email CT2 | EmailCT2 | Email address | nospam@ez.no |
| Textline CT2 | TextlineCT2 | Text line | TestTextLine |
| ISBN CT2 | IsbnCT2 | ISBN | 9783161484100 |
| Authors CT2 | AuthorsCT2 | Authors | AuthorName,nospam@ez.no |
| Text block CT2 | TextBlockCT2 | Text block | TestTextBlock |
| Checkbox CT2 | CheckboxCT2 | Checkbox | true |
| Country CT2 | CountryCT2 | Country | FR |
| Date CT2 | DateCT2 | Date | 2018-12-31 |
| Time CT2 | TimeCT2 | Time | 13:55:00 |
| Float CT2 | FloatCT2 | Float | 2.34 |
| Integer CT2 | Integer2 | Integer | 10 |
| Map location CT2 | MapLocationCT2 | Map location | Tokio |
| Date and time CT2 | DateAndTimeCT2 | Date and time | 2018-12-31 13:55:00 |
| Content relation CT2 | ContentRelationCT2 | Content relation (single) | /RelationFolder1 |
| Content relations CT2 | ContentRelationsCT2 | Content relations (multiple) | RelationFolder1,/RelationFolder2 |
| Image CT2 | ImageCT2 | Image | /var/www/vendor/ezsystems/behatbundle/src/lib/Data/Images/small1.jpg |
| File CT2 | FileCT2 | File | /var/www/vendor/ezsystems/behatbundle/src/lib/Data/Files/file1.txt |
| Media CT2 | MediaCT2 | Media | /var/www/vendor/ezsystems/behatbundle/src/lib/Data/Videos/video1.mp4 |
File renamed without changes.
18 changes: 8 additions & 10 deletions src/bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,22 @@ services:
- '@ezpublish.api.service.content_type'
- '@ezpublish.api.service.content'

ezbehatbundle.api.facade.contentfacade:
class: EzSystems\Behat\API\Facade\ContentFacade
EzSystems\Behat\API\Facade\ContentFacade:
public: true

ezbehatbundle.api.facade.contenttypefacade:
class: EzSystems\Behat\API\Facade\ContentTypeFacade
EzSystems\Behat\API\Facade\ContentTypeFacade:
public: true

ezbehatbundle.api.facade.rolefacade:
class: EzSystems\Behat\API\Facade\RoleFacade
EzSystems\Behat\API\Facade\RoleFacade:
public: true

ezbehatbundle.api.facade.userfacade:
class: EzSystems\Behat\API\Facade\UserFacade
EzSystems\Behat\API\Facade\UserFacade:
public: true

ezbehatbundle.api.facade.languagefacade:
class: EzSystems\Behat\API\Facade\LanguageFacade
EzSystems\Behat\API\Facade\LanguageFacade:
public: true

EzSystems\Behat\Core\Behat\ArgumentParser:
public: true

ezbehatbundle.controller.exception:
Expand Down
33 changes: 28 additions & 5 deletions src/lib/API/ContentData/ContentDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
use eZ\Publish\API\Repository\Values\Content\ContentStruct;
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition;
use EzSystems\Behat\API\ContentData\FieldTypeData\FieldTypeDataProviderInterface;

class ContentDataProvider
Expand Down Expand Up @@ -47,28 +49,49 @@ public function getRandomContentData($language): ContentCreateStruct
$fieldDefinitions = $contentType->getFieldDefinitions();

foreach ($fieldDefinitions as $field) {
$fieldData = $this->getFieldData($field->fieldTypeIdentifier, $language);
$fieldData = $this->getRandomFieldData($field->fieldTypeIdentifier, $language);
$contentCreateStruct->setField($field->identifier, $fieldData, $language);
}

return $contentCreateStruct;
}

public function getFilledContentDataStruct(ContentCreateStruct $contentCreateStruct, $contentItemData, $language): ContentCreateStruct
public function getFilledContentDataStruct(ContentStruct $contentStruct, $contentItemData, $language): ContentStruct
{
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($this->contentTypeIdentifier);
$fieldDefinitions = $contentType->getFieldDefinitions();

foreach ($contentItemData as $fieldIdentifier => $value) {
$contentCreateStruct->setField($fieldIdentifier, $value);
$fieldDefinition = array_values(array_filter($fieldDefinitions, function (FieldDefinition $fieldDefinition) use ($fieldIdentifier) {
return $fieldDefinition->identifier === $fieldIdentifier;
}));

if (empty($fieldDefinition)) {
throw new \Exception(sprintf('Could not find fieldIdentifier: %s in content type: %s', $fieldIdentifier, $this->contentTypeIdentifier));
}

$fieldData = $this->getFieldDataFromString($fieldDefinition[0]->fieldTypeIdentifier, $value);
$contentStruct->setField($fieldIdentifier, $fieldData, $language);
}

return $contentCreateStruct;
return $contentStruct;
}

public function getFieldData($fieldIdentifier, $language = 'eng-GB')
public function getRandomFieldData($fieldIdentifier, $language = 'eng-GB')
{
foreach ($this->fieldTypeDataProviders as $provider) {
if ($provider->supports($fieldIdentifier)) {
return $provider->generateData($language);
}
}
}

public function getFieldDataFromString($fieldIdentifier, $value)
{
foreach ($this->fieldTypeDataProviders as $provider) {
if ($provider->supports($fieldIdentifier)) {
return $provider->parseFromString($value);
}
}
}
}
17 changes: 14 additions & 3 deletions src/lib/API/ContentData/FieldTypeData/AuthorDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,30 @@ public function supports(string $fieldTypeIdentifier): bool
return $fieldTypeIdentifier === 'ezauthor';
}

public function generateData(string $language = 'eng-GB')
public function generateData(string $language = 'eng-GB'): Value
{
return new Value([$this->getSingleAuthor($language), $this->getSingleAuthor($language)]);
}

private function getSingleAuthor(string $language = 'eng-GB'): Author
{
$author = new Author();

$this->setLanguage($language);

$author = new Author();
$author->name = $this->getFaker()->name;
$author->email = $this->getFaker()->email;

return $author;
}

public function parseFromString(string $value): Value
{
[$name, $email] = explode(',', $value);

$author = new Author();
$author->name = $name;
$author->email = $email;

return new Value([$author]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public function generateData(string $language = 'eng-GB')

return new Value(['inputUri' => $filePath]);
}

public function parseFromString(string $value)
{
return new Value(['inputUri' => $value]);
}
}
5 changes: 5 additions & 0 deletions src/lib/API/ContentData/FieldTypeData/BooleanDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public function generateData(string $language = 'eng-GB')
// if the field is required then the value has to be true.
return true;
}

public function parseFromString(string $value)
{
return $value === 'true';
}
}
5 changes: 5 additions & 0 deletions src/lib/API/ContentData/FieldTypeData/CountryDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public function generateData(string $language = 'eng-GB')

return new Value([$randomCountry => self::COUNTRY_DATA[$randomCountry]]);
}

public function parseFromString(string $value)
{
return new Value([$value => self::COUNTRY_DATA[$value]]);
}
}
6 changes: 6 additions & 0 deletions src/lib/API/ContentData/FieldTypeData/DateDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace EzSystems\Behat\API\ContentData\FieldTypeData;

use DateTime;
use eZ\Publish\Core\FieldType\Date\Value;

class DateDataProvider extends RandomDataGenerator implements FieldTypeDataProviderInterface
Expand All @@ -19,4 +20,9 @@ public function generateData(string $language = 'eng-GB')
{
return new Value($this->getFaker()->dateTimeThisCentury());
}

public function parseFromString(string $value)
{
return DateTime::createFromFormat('Y-m-d', $value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
namespace EzSystems\Behat\API\ContentData\FieldTypeData;

use DateTime;
use eZ\Publish\Core\FieldType\DateAndTime\Value;

class DateTimeDataProvider extends RandomDataGenerator implements FieldTypeDataProviderInterface
Expand All @@ -19,4 +20,9 @@ public function generateData(string $language = 'eng-GB')
{
return new Value($this->getFaker()->dateTimeThisCentury());
}

public function parseFromString(string $value)
{
return DateTime::createFromFormat('Y-m-d H:i:s', $value);
}
}
5 changes: 5 additions & 0 deletions src/lib/API/ContentData/FieldTypeData/EmailDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public function generateData(string $language = 'eng-GB'): string

return $this->getFaker()->companyEmail;
}

public function parseFromString(string $value)
{
return $value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ interface FieldTypeDataProviderInterface
public function supports(string $fieldTypeIdentifier): bool;

public function generateData(string $language = 'eng-GB');

public function parseFromString(string $value);
}
5 changes: 5 additions & 0 deletions src/lib/API/ContentData/FieldTypeData/FloatDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public function generateData(string $language = 'eng-GB')
{
return $this->getFaker()->randomFloat(4);
}

public function parseFromString(string $value)
{
return (float) $value;
}
}
5 changes: 5 additions & 0 deletions src/lib/API/ContentData/FieldTypeData/ISBNDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ public function generateData(string $language = 'eng-GB')
{
return $this->getFaker()->isbn13;
}

public function parseFromString(string $value)
{
return $value;
}
}
Loading