/** * @test */ public function inSetForPostgreSQL() { $databasePlatform = $this->prophesize(MockPlatform::class); $databasePlatform->getName()->willReturn('postgresql'); $this->connectionProphet->quote(',', Argument::cetera())->shouldBeCalled()->willReturn("','"); $this->connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($args) { return '"' . $args[0] . '"'; }); $this->connectionProphet->getDatabasePlatform()->willReturn($databasePlatform->reveal()); $result = $this->subject->inSet('aField', "'1'"); $this->assertSame('any(string_to_array("aField", \',\')) = \'1\'', $result); }
/** * Main method to build expressions for given tables * Evaluates the ctrl/enablecolumns/fe_group flag of the table and adds the according restriction if set * * @param array $queriedTables Array of tables, where array key is table name and value potentially an alias * @param ExpressionBuilder $expressionBuilder Expression builder instance to add restrictions with * @return CompositeExpression The result of query builder expression(s) */ public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder) : CompositeExpression { $constraints = []; foreach ($queriedTables as $tableName => $tableAlias) { $groupFieldName = $GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['fe_group'] ?? null; if (!empty($groupFieldName)) { $fieldName = ($tableAlias ?: $tableName) . '.' . $groupFieldName; // Allow records where no group access has been configured (field values NULL, 0 or empty string) $constraints = [$expressionBuilder->isNull($fieldName), $expressionBuilder->eq($fieldName, $expressionBuilder->literal('')), $expressionBuilder->eq($fieldName, $expressionBuilder->literal('0'))]; foreach ($this->frontendGroupIds as $frontendGroupId) { $constraints[] = $expressionBuilder->inSet($fieldName, $expressionBuilder->literal((string) $frontendGroupId)); } } } return $expressionBuilder->orX(...$constraints); }