/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper::getSecurityContext */ public function testGetSecurityContext() { $this->assertSame($this->sc, $this->object->getSecurityContext()); }
/** * Get all the information needed to build a menu tree with one query. * We only fetch the fields we need, instead of fetching full objects to limit the memory usage. * * @param string $lang The locale * @param string $permission The permission (read, write, ...) * @param AclNativeHelper $aclNativeHelper The acl helper * @param bool $includeHiddenFromNav Include nodes hidden from navigation or not * * @return array */ public function getAllMenuNodes($lang, $permission, AclNativeHelper $aclNativeHelper, $includeHiddenFromNav = false) { $connection = $this->_em->getConnection(); $qb = $connection->createQueryBuilder(); $databasePlatformName = $connection->getDatabasePlatform()->getName(); $createIfStatement = function ($expression, $trueValue, $falseValue) use($databasePlatformName) { switch ($databasePlatformName) { case 'sqlite': $statement = 'CASE WHEN %s THEN %s ELSE %s END'; break; default: $statement = 'IF(%s, %s, %s)'; } return sprintf($statement, $expression, $trueValue, $falseValue); }; $sql = <<<SQL n.id, n.parent_id AS parent, t.url, {$createIfStatement('t.weight IS NULL', 'v.weight', 't.weight')} AS weight, {$createIfStatement('t.title IS NULL', 'v.title', 't.title')} AS title, {$createIfStatement('t.online IS NULL', '0', 't.online')} AS online, n.hidden_from_nav AS hidden, n.ref_entity_name AS ref_entity_name SQL; $qb->select($sql)->from('kuma_nodes', 'n')->leftJoin('n', 'kuma_node_translations', 't', '(t.node_id = n.id AND t.lang = ?)')->leftJoin('n', '(SELECT lang, title, weight, node_id, url FROM kuma_node_translations GROUP BY node_id ORDER BY id ASC)', 'v', '(v.node_id = n.id AND v.lang <> ?)')->where('n.deleted = 0')->addGroupBy('n.id')->addOrderBy('t.weight', 'ASC')->addOrderBy('t.title', 'ASC'); if (!$includeHiddenFromNav) { $qb->andWhere('n.hidden_from_nav <> 0'); } $permissionDef = new PermissionDefinition(array($permission)); $permissionDef->setEntity('Kunstmaan\\NodeBundle\\Entity\\Node'); $permissionDef->setAlias('n'); $qb = $aclNativeHelper->apply($qb, $permissionDef); $stmt = $this->_em->getConnection()->prepare($qb->getSQL()); $stmt->bindValue(1, $lang); $stmt->bindValue(2, $lang); $stmt->execute(); return $stmt->fetchAll(); }
/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper::getTokenStorage */ public function testGetTokenStorage() { $this->assertSame($this->tokenStorage, $this->object->getTokenStorage()); }