Skip to content

Commit

Permalink
test for ManyToMany EmbeddedList
Browse files Browse the repository at this point in the history
  • Loading branch information
alterphp committed Aug 29, 2018
1 parent 0ebf265 commit 48aea1c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 7 deletions.
9 changes: 9 additions & 0 deletions tests/Controller/EmbeddedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ public function setUp()
$this->initClient(array('environment' => 'embedded_list'));
}

public function testManyToManyEmbedddLists()
{
$crawler = $this->requestEditView('AdminGroup', 1);

$forAttrValue = '/admin/?entity=AdminUser&action=embeddedList&filters%5Bentity.id%5D%5B0%5D=1&filters%5Bentity.id%5D%5B1%5D=2&filters%5Bentity.id%5D%5B2%5D=3&filters%5Bentity.id%5D%5B3%5D=4&filters%5Bentity.id%5D%5B4%5D=5&filters%5Bentity.id%5D%5B5%5D=6&filters%5Bentity.id%5D%5B6%5D=7&filters%5Bentity.id%5D%5B7%5D=8&filters%5Bentity.id%5D%5B8%5D=9&filters%5Bentity.id%5D%5B9%5D=10&filters%5Bentity.id%5D%5B10%5D=11&filters%5Bentity.id%5D%5B11%5D=12&filters%5Bentity.id%5D%5B12%5D=13&filters%5Bentity.id%5D%5B13%5D=14&filters%5Bentity.id%5D%5B14%5D=15&filters%5Bentity.id%5D%5B15%5D=16&filters%5Bentity.id%5D%5B16%5D=17&filters%5Bentity.id%5D%5B17%5D=18&filters%5Bentity.id%5D%5B18%5D=19&filters%5Bentity.id%5D%5B19%5D=20';

$this->assertSame(1, $crawler->filter('.embedded-list[for="'.$forAttrValue.'"]')->count());
}

public function testEmbeddedListIsDisplaidInEdit()
{
$crawler = $this->requestEditView('Category', 1);
Expand Down
8 changes: 8 additions & 0 deletions tests/Fixtures/App/config/config_embedded_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ easy_admin:
embeddedList:
open_new_tab: true
sort: [createdAt, DESC]
AdminGroup:
class: AppTestBundle\Entity\FunctionalTests\AdminGroup
form:
fields:
- { property: name }
- { property: users, label: '', type: embedded_list }
AdminUser:
class: AppTestBundle\Entity\FunctionalTests\AdminUser
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public function getOrder()
public function load(ObjectManager $manager)
{
foreach (range(1, 20) as $i) {
$group = new AdminGroup();
$group->setName('group'.$i);
$group->setRoles(array('ROLE_GROUP_'.$i, 'ROLE_GROUP_'.($i + 1)));
$adminGroup = new AdminGroup();
$adminGroup->setName('admin-group'.$i);
$adminGroup->setRoles(array('ROLE_GROUP_'.$i, 'ROLE_GROUP_'.($i + 1)));

$this->addReference('group-'.$i, $group);
$manager->persist($group);
$this->addReference('admin-group-'.$i, $adminGroup);
$manager->persist($adminGroup);
}

$manager->flush();
Expand Down
37 changes: 37 additions & 0 deletions tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminUsers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace AlterPHP\EasyAdminExtensionBundle\Tests\Fixtures\AppTestBundle\DataFixtures\ORM;

use AppTestBundle\Entity\FunctionalTests\AdminUser;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class LoadAdminUsers extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
{
return 11;
}

public function load(ObjectManager $manager)
{
foreach (range(1, 20) as $i) {
$adminUser = new AdminUser();
$adminUser->updateFromData(array(
'gSuiteId' => 'g-suite-id-'.$i,
'email' => 'email-'.$i.'@easyadmin.com',
'lastname' => 'lastname-'.$i,
'firstname' => 'firstname-'.$i,
));

// All users are members of first AdminGroup
$adminUser->addGroup($this->getReference('admin-group-1'));

$this->addReference('admin-user-'.$i, $adminUser);
$manager->persist($adminUser);
}

$manager->flush();
}
}
13 changes: 11 additions & 2 deletions tests/Fixtures/AppTestBundle/Entity/FunctionalTests/AdminUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class AdminUser extends BaseAdminUser
private $gSuiteId;

/**
* @ORM\Column(type="string", unique=true)
* @ORM\Column(type="string")
*/
private $lastname;

/**
* @ORM\Column(type="string", unique=true)
* @ORM\Column(type="string")
*/
private $firstname;

Expand Down Expand Up @@ -71,4 +71,13 @@ public function getFirstname()
{
return $this->firstname;
}

public function addGroup(AdminGroup $adminGroup)
{
if (!$this->groups->contains($adminGroup)) {
$this->groups->add($adminGroup);
}

return $this;
}
}

0 comments on commit 48aea1c

Please sign in to comment.