diff --git a/tests/Controller/EmbeddedListTest.php b/tests/Controller/EmbeddedListTest.php index 8cf9fca0..85da9aae 100644 --- a/tests/Controller/EmbeddedListTest.php +++ b/tests/Controller/EmbeddedListTest.php @@ -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); diff --git a/tests/Fixtures/App/config/config_embedded_list.yml b/tests/Fixtures/App/config/config_embedded_list.yml index d6070833..cccd2c10 100644 --- a/tests/Fixtures/App/config/config_embedded_list.yml +++ b/tests/Fixtures/App/config/config_embedded_list.yml @@ -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 diff --git a/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminGroups.php b/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminGroups.php index c6119f4a..fb1af853 100644 --- a/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminGroups.php +++ b/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminGroups.php @@ -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(); diff --git a/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminUsers.php b/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminUsers.php new file mode 100644 index 00000000..85d8fc68 --- /dev/null +++ b/tests/Fixtures/AppTestBundle/DataFixtures/ORM/LoadAdminUsers.php @@ -0,0 +1,37 @@ +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(); + } +} diff --git a/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/AdminUser.php b/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/AdminUser.php index 1682709a..69fbd60c 100644 --- a/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/AdminUser.php +++ b/tests/Fixtures/AppTestBundle/Entity/FunctionalTests/AdminUser.php @@ -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; @@ -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; + } }