public function testGetValidOperatorTypesForAllAttributeTypes() { $model = new TestOperatorTypeModel(); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'integerStandard')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateStandard')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateTimeStandard')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'floatStandard')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'timeStandard')); $this->assertEquals('startsWith', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'emailStandard')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'booleanStandard')); $this->assertEquals('contains', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'urlStandard')); //Test all custom fields $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'checkBox')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'currency')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'date')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dateTime')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'decimal')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'dropDown')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'integer')); $this->assertEquals('startsWith', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'phone')); $this->assertEquals('equals', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'radio')); $this->assertEquals('startsWith', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'text')); $this->assertEquals('contains', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'textArea')); $this->assertEquals('contains', ModelAttributeToOperatorTypeUtil::getOperatorType($model, 'url')); }
public static function resolveOperatorsToIncludeByType(&$data, $type) { if ($type == self::AVAILABLE_OPERATORS_TYPE_BOOLEAN) { $data[OperatorRules::TYPE_EQUALS] = OperatorRules::getTranslatedTypeLabel(OperatorRules::TYPE_EQUALS); return; } if ($type == self::AVAILABLE_OPERATORS_TYPE_HAS_ONE) { $data[OperatorRules::TYPE_EQUALS] = OperatorRules::getTranslatedTypeLabel(OperatorRules::TYPE_EQUALS); return; } parent::resolveOperatorsToIncludeByType($data, $type); }
/** * @param $model * @param string $attributeName * @return string */ public static function getAvailableOperatorsType($model, $attributeName) { assert('is_string($attributeName)'); if ($model->{$attributeName} instanceof CurrencyValue) { return self::AVAILABLE_OPERATORS_TYPE_CURRENCY_VALUE; } return parent::getAvailableOperatorsType($model, $attributeName); }
/** * Method for populating clauses for concated attributes. The first concated attribute $attributeNames[0] * will be used to determine the operator types. */ protected function populateClausesAndStructureForConcatedAttributes($model, $attributeNames, $value, &$adaptedMetadataClauseBasePart, &$clauseCount, &$structure, $operatorType = null) { assert('is_array($attributeNames) && count($attributeNames) == 2'); assert('is_array($adaptedMetadataClauseBasePart)'); assert('is_int($clauseCount)'); assert('$structure == null || is_string($structure)'); if ($value !== null) { if ($operatorType == null) { $operatorType = ModelAttributeToOperatorTypeUtil::getOperatorType($model, $attributeNames[0]); $operatorTypeCompare = ModelAttributeToOperatorTypeUtil::getOperatorType($model, $attributeNames[1]); if ($operatorType != $operatorTypeCompare) { throw new NotSupportedException(); } } $value = ModelAttributeToCastTypeUtil::resolveValueForCast($model, $attributeNames[0], $value); $adaptedMetadataClauseBasePart = array('concatedAttributeNames' => $attributeNames, 'operatorType' => $operatorType, 'value' => $value); if ($this->appendStructureAsAnd) { static::appendClauseAsAndToStructureString($structure, $clauseCount); } else { static::appendClauseAsOrToStructureString($structure, $clauseCount); } $clauseCount++; } }
public function testResolveOperatorsToIncludeByType() { $data = array(); ModelAttributeToOperatorTypeUtil::resolveOperatorsToIncludeByType($data, ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING); $expectedData = array('equals' => 'Equals', 'doesNotEqual' => 'Does Not Equal', 'isNull' => 'Is Null', 'isNotNull' => 'Is Not Null', 'startsWith' => 'Starts With', 'doesNotStartsWith' => 'Does Not Start With', 'endsWith' => 'Ends With', 'doesNotEndsWith' => 'Does Not End With', 'contains' => 'Contains', 'doesNotContains' => 'Does Not Contain', 'isEmpty' => 'Is Empty', 'isNotEmpty' => 'Is Not Empty'); $this->assertEquals($expectedData, $data); }
public function testGetAvailableOperatorsType() { $model = new TestOperatorTypeModel(); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'integerStandard')); $this->assertNull(ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateStandard')); $this->assertNull(ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateTimeStandard')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'floatStandard')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'emailStandard')); $this->assertNull(ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'booleanStandard')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'urlStandard')); //Test all custom fields $this->assertNull(ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'checkBoxCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'currencyCstm')); $this->assertNull(ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateCstm')); $this->assertNull(ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dateTimeCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'decimalCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'dropDownCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_NUMBER, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'integerCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'phoneCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_DROPDOWN, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'radioCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'textCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'textAreaCstm')); $this->assertEquals(ModelAttributeToOperatorTypeUtil::AVAILABLE_OPERATORS_TYPE_STRING, ModelAttributeToOperatorTypeUtil::getAvailableOperatorsType($model, 'urlCstm')); }