Ejemplo n.º 1
2
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // force id = 1
     $metadata = $manager->getClassMetaData(get_class(new SecurityType()));
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $file = $this->container->getParameter('sulu_security.security_types.fixture');
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/security-types/security-type');
     if (!is_null($elements)) {
         /** @var $element \DOMNode */
         foreach ($elements as $element) {
             $securityType = new SecurityType();
             $children = $element->childNodes;
             /** @var $child \DOMNode */
             foreach ($children as $child) {
                 if (isset($child->nodeName)) {
                     if ($child->nodeName == 'id') {
                         $securityType->setId($child->nodeValue);
                     }
                     if ($child->nodeName == 'name') {
                         $securityType->setName($child->nodeValue);
                     }
                 }
             }
             $manager->persist($securityType);
         }
     }
     $manager->flush();
 }
Ejemplo n.º 2
0
 public function testPost()
 {
     $client = $this->createAuthenticatedClient();
     $client->request('POST', '/api/roles', ['name' => 'Portal Manager', 'system' => 'Sulu', 'permissions' => [['context' => 'portal1', 'permissions' => ['view' => false, 'add' => false, 'edit' => true, 'delete' => true, 'archive' => false, 'live' => true, 'security' => false]], ['context' => 'portal2', 'permissions' => ['view' => false, 'add' => false, 'edit' => false, 'delete' => true, 'archive' => false, 'live' => false, 'security' => false]]], 'securityType' => ['id' => $this->securityType2->getId()]]);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals('Portal Manager', $response->name);
     $this->assertEquals('Sulu', $response->system);
     $this->assertEquals(2, count($response->permissions));
     $this->assertEquals('portal1', $response->permissions[0]->context);
     $this->assertEquals(false, $response->permissions[0]->permissions->view);
     $this->assertEquals(false, $response->permissions[0]->permissions->add);
     $this->assertEquals(true, $response->permissions[0]->permissions->edit);
     $this->assertEquals(true, $response->permissions[0]->permissions->delete);
     $this->assertEquals(false, $response->permissions[0]->permissions->archive);
     $this->assertEquals(true, $response->permissions[0]->permissions->live);
     $this->assertEquals(false, $response->permissions[0]->permissions->security);
     $this->assertEquals('portal2', $response->permissions[1]->context);
     $this->assertEquals(false, $response->permissions[1]->permissions->view);
     $this->assertEquals(false, $response->permissions[1]->permissions->add);
     $this->assertEquals(false, $response->permissions[1]->permissions->edit);
     $this->assertEquals(true, $response->permissions[1]->permissions->delete);
     $this->assertEquals(false, $response->permissions[1]->permissions->archive);
     $this->assertEquals(false, $response->permissions[1]->permissions->live);
     $this->assertEquals(false, $response->permissions[1]->permissions->security);
     $this->assertEquals('Security Type 2', $response->securityType->name);
     $client->request('GET', '/api/roles/' . $response->id);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertEquals('Portal Manager', $response->name);
     $this->assertEquals('Sulu', $response->system);
     $this->assertEquals(2, count($response->permissions));
     $this->assertEquals('portal1', $response->permissions[0]->context);
     $this->assertEquals(false, $response->permissions[0]->permissions->view);
     $this->assertEquals(false, $response->permissions[0]->permissions->add);
     $this->assertEquals(true, $response->permissions[0]->permissions->edit);
     $this->assertEquals(true, $response->permissions[0]->permissions->delete);
     $this->assertEquals(false, $response->permissions[0]->permissions->archive);
     $this->assertEquals(true, $response->permissions[0]->permissions->live);
     $this->assertEquals(false, $response->permissions[0]->permissions->security);
     $this->assertEquals('portal2', $response->permissions[1]->context);
     $this->assertEquals(false, $response->permissions[1]->permissions->view);
     $this->assertEquals(false, $response->permissions[1]->permissions->add);
     $this->assertEquals(false, $response->permissions[1]->permissions->edit);
     $this->assertEquals(true, $response->permissions[1]->permissions->delete);
     $this->assertEquals(false, $response->permissions[1]->permissions->archive);
     $this->assertEquals(false, $response->permissions[1]->permissions->live);
     $this->assertEquals(false, $response->permissions[1]->permissions->security);
     $this->assertEquals('Security Type 2', $response->securityType->name);
 }