Skip to content

fix BP inheritance bugs and addd some tests #307

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

Merged
merged 9 commits into from
Dec 23, 2015
2 changes: 1 addition & 1 deletion Bundle/BusinessPageBundle/Entity/BusinessPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BusinessPage extends Page
*
* @var BaseEntityProxy
*
* @ORM\OneToOne(targetEntity="\Victoire\Bundle\CoreBundle\Entity\EntityProxy", cascade={"persist", "remove"})
* @ORM\ManyToOne(targetEntity="\Victoire\Bundle\CoreBundle\Entity\EntityProxy", cascade={"persist", "remove"})
* @ORM\JoinColumn(name="entityProxy_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $entityProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="vic-col-md-12">
{{ 'victoire.form.business_template.query.vic_help_block'|trans|raw }}
{{ form_row(form.query, { 'businessProperties':businessProperties }) }}
<div class="form-group">
<div class="vic-form-group">
{{ form_row(form.authorRestricted) }}
</div>
{{ form_rest(form) }}
Expand Down
5 changes: 0 additions & 5 deletions Bundle/PageBundle/Helper/PageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ public function updatePageWithEntity(BusinessTemplate $page, $entity)
//update the parameters of the page
$this->businessPageBuilder->updatePageParametersByEntity($page, $entity);

$businessEntity = $this->businessEntityHelper->findByEntityInstance($entity);
$entityProxy = new EntityProxy();
$entityProxy->setEntity($entity, $businessEntity->getName());
$page->setEntityProxy($entityProxy);

return $page;
}

Expand Down
4 changes: 2 additions & 2 deletions Bundle/WidgetBundle/Controller/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ public function editAction(Widget $widget, $viewReference, $mode = Widget::MODE_
$this->get('victoire_widget_map.builder')->build($widgetView, true);
$this->get('victoire_widget_map.widget_data_warmer')->warm($this->getDoctrine()->getManager(), $view);

if (!$reference = $this->container->get('victoire_view_reference.cache.repository')
if ($view instanceof BusinessTemplate && !$reference = $this->container->get('victoire_view_reference.cache.repository')
->getOneReferenceByParameters(['viewId' => $view->getId()])) {
$reference = new ViewReference($viewReference);
$widgetView->setReference($reference);
}

$widgetView->setReference($reference);
$this->get('victoire_core.current_view')->setCurrentView($view);
try {
$response = new JsonResponse(
Expand Down
39 changes: 22 additions & 17 deletions Bundle/WidgetBundle/Model/WidgetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,43 +347,48 @@ public function deleteWidget(Widget $widget, View $view)
*/
public function overwriteWidget(View $view, Widget $widget)
{
$widgetCopy = clone $widget;
$widgetCopy = $this->cloneEntity($widget);
$widgetCopy->setView($view);

//we have to persist the widget to get its id
$this->entityManager->persist($view);
$this->entityManager->flush();

$this->widgetMapManager->overwriteWidgetMap($widgetCopy, $widget, $view);

return $widgetCopy;
}

public function cloneEntity($entity)
{
$entityCopy = clone $entity;
//Look for on_to_many relations, if found, duplicate related entities.
//It is necessary for 'list' widgets, this algo duplicates and persists list items.
$associations = $this->entityManager->getClassMetadata(get_class($widget))->getAssociationMappings();
$associations = $this->entityManager->getClassMetadata(get_class($entity))->getAssociationMappings();
$accessor = PropertyAccess::createPropertyAccessor();
foreach ($associations as $name => $values) {
if ($values['type'] === ClassMetadataInfo::ONE_TO_MANY) {
$relatedEntities = $accessor->getValue($widget, $values['fieldName']);
$relatedEntities = $accessor->getValue($entity, $values['fieldName']);
$relatedEntitiesCopies = [];
foreach ($relatedEntities as $relatedEntity) {
$relatedEntityCopy = clone $relatedEntity;
$this->entityManager->persist($relatedEntity);
$relatedEntityCopy = $this->cloneEntity($relatedEntity);
$relatedEntitiesCopies[] = $relatedEntityCopy;
}
$accessor->setValue($widgetCopy, $name, $relatedEntitiesCopies);
$accessor->setValue($entityCopy, $name, $relatedEntitiesCopies);
}

//Clone OneToOne relation objects
if ($values['type'] === ClassMetadataInfo::ONE_TO_ONE) {
$relatedEntity = $accessor->getValue($widget, $values['fieldName']);
$relatedEntity = $accessor->getValue($entity, $values['fieldName']);
if ($relatedEntity) {
$relatedEntityCopy = clone $relatedEntity;
$this->entityManager->persist($relatedEntity);
$accessor->setValue($widgetCopy, $name, $relatedEntityCopy);
$relatedEntityCopy = $this->cloneEntity($relatedEntity);
$accessor->setValue($entityCopy, $name, $relatedEntityCopy);
}
}
}

//we have to persist the widget to get its id
$this->entityManager->persist($view);
$this->entityManager->persist($widgetCopy);
$this->entityManager->flush();

$this->widgetMapManager->overwriteWidgetMap($widgetCopy, $widget, $view);
$this->entityManager->persist($entityCopy);

return $widgetCopy;
return $entityCopy;
}
}
50 changes: 49 additions & 1 deletion Tests/Features/BusinessEntityPage/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ Feature: Create business entity pages
And I submit the widget
Then I should see "Victoire !"
Then I should see "Le Côté jedi -> side de la force"

Given I am on "/victoire-dcms/backend/jedi/"
When I follow "Nouveau jedi"
Then I should be on "/victoire-dcms/backend/jedi/new"
Expand All @@ -162,5 +161,54 @@ Feature: Create business entity pages
Given I am on "/fr/fiche-jedi-mace-windu"
Then I should see "Le Côté obscure de la force"

Scenario: I can create businessPage of the same entity on different businessTemplates
Given the following Jedis:
| name | side | midiChlorians | slug |
| Kylo Ren | Double | 20000 | kylo-ren |
Given I open the hamburger menu
Then I should see "Représentation métier"
When I follow "Représentation métier"
And I close the hamburger menu
Then I should see "Jedi"
Then I should see "Ajouter une représentation métier"
When I follow the tab "Jedi"
And I should see "Ajouter une représentation métier"
And I follow "Ajouter une représentation métier"
Then I should see "Créer une représentation métier"
When I fill in "Nom" with "Fiche Jedi - {{item.name}}"
And I fill in "URL" with "fiche-jedi-{{item.slug}}"
And I fill in "victoire_business_template_type_query" with "WHERE LOWER(item.side) LIKE LOWER('bright') OR LOWER(item.side) LIKE LOWER('double')"
And I follow "Créer"
And I wait 5 seconds
And I switch to "layout" mode
When I select "Force" from the "1" select of "content" slot
Then I should see "Créer"
And I fill in "Côté de la force" with "Bright"
And I submit the widget
And I wait 5 seconds
Given I open the hamburger menu
Then I should see "Représentation métier"
When I follow "Représentation métier"
And I close the hamburger menu
Then I should see "Jedi"
Then I should see "Ajouter une représentation métier"
When I follow the tab "Jedi"
And I should see "Ajouter une représentation métier"
And I follow "Ajouter une représentation métier"
Then I should see "Créer une représentation métier"
When I fill in "Nom" with "Fiche Sith - {{item.name}}"
And I fill in "URL" with "fiche-sith-{{item.slug}}"
And I fill in "victoire_business_template_type_query" with "WHERE LOWER(item.side) LIKE LOWER('dark') OR LOWER(item.side) LIKE LOWER('double')"
And I follow "Créer"
And I wait 5 seconds
When I select "Force" from the "1" select of "content" slot
Then I should see "Créer"
And I fill in "Côté de la force" with "Dark"
And I submit the widget
And I wait 5 seconds
Given I am on "/fr/fiche-jedi-kylo-ren"
Then I should see "Le côté Bright de la force"
Given I am on "/fr/fiche-sith-kylo-ren"
Then I should see "Le côté Dark de la force"


26 changes: 25 additions & 1 deletion Tests/Features/Widget/edit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,32 @@ Feature: Edit a widget
And I submit the widget
Then I should see "Victoire !"
And I should see "Le Côté obscure de la force"

Scenario: I cannot edit widget for an entity with missing business parameter
When I select "Force" from the "1" select of "content" slot
Then I should see "Créer"
And I should see disable tab "Vaisseaux"

Scenario: I can edit the original widget from a child page
Given the following Jedis:
| name | side | midiChlorians | slug |
| Anakin | Dark | 20000 | anakin |
When I select "Force" from the "1" select of "content" slot
Then I should see "Créer"
When I fill in "Côté de la force" with "Obscure"
When I submit the widget
Then I should see "Victoire !"
And I should see "Le Côté Obscure de la force"
Given I am on "/fr/fiche-jedi-anakin"
When I switch to "edit" mode
And I edit the "Force" widget
Then I should see "Attention ! Ce contenu appartient à un modèle parent"
And I follow "modifier le contenu original"
And I wait 5 seconds
Then I should not see "Attention ! Ce contenu appartient à un modèle parent"
When I fill in "Côté de la force" with "Dark"
And I submit the widget
Then I should see "Victoire"
Given I am on "/fr/victoire-dcms/business-template/show/5"
Then I should see "Le Côté Dark de la force"