public function testSearchFormDynamicAttributesForRelatedManyManyDateTimeAttributes() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $searchAttributes = array('dateDateTimeADate__Date' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_AFTER, 'firstDate' => '1993-04-04'), 'dateDateTimeADateTime__DateTime' => array('type' => MixedDateTypesSearchFormAttributeMappingRules::TYPE_TODAY)); $searchForm = new MixedRelationsModelSearchFormTestModel(new MixedRelationsModel()); $this->assertTrue($searchForm->isAttributeOnForm('dateDateTimeADate__Date')); $metadataAdapter = new SearchDataProviderMetadataAdapter($searchForm, $super->id, $searchAttributes); $todayDateTime = new DateTime(null, new DateTimeZone(Yii::app()->timeZoneHelper->getForCurrentUser())); $today = Yii::app()->dateFormatter->format(DatabaseCompatibilityUtil::getDateFormat(), $todayDateTime->getTimeStamp()); $todayPlus7Days = MixedDateTypesSearchFormAttributeMappingRules::calculateNewDateByDaysFromNow(7); $metadata = $metadataAdapter->getAdaptedMetadata(); $compareClauses = array(1 => array('attributeName' => 'manyMany', 'relatedAttributeName' => 'aDate', 'operatorType' => 'greaterThanOrEqualTo', 'value' => '1993-04-04'), 2 => array('attributeName' => 'manyMany', 'relatedAttributeName' => 'aDateTime', 'operatorType' => 'greaterThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeBeginningOfDay($today)), 3 => array('attributeName' => 'manyMany', 'relatedAttributeName' => 'aDateTime', 'operatorType' => 'lessThanOrEqualTo', 'value' => DateTimeUtil::convertDateIntoTimeZoneAdjustedDateTimeEndOfDay($today))); $compareStructure = '(1) and (2 and 3)'; $this->assertEquals($compareClauses, $metadata['clauses']); $this->assertEquals($compareStructure, $metadata['structure']); }
public function testDynamicDateTimeAttributeOnForm() { $searchForm = new MixedRelationsModelSearchFormTestModel(new MixedRelationsModel()); //Test get and set. $this->assertEquals(null, $searchForm->dateTime__DateTime); $searchForm->dateTime__DateTime = 'aTest'; $this->assertEquals('aTest', $searchForm->dateTime__DateTime); //Check some other methods to make sure they work ok. $this->assertFalse($searchForm::isRelation('dateTime__DateTime')); $this->assertTrue($searchForm->isAttribute('dateTime__DateTime')); $this->assertFalse($searchForm->isAttributeRequired('dateTime__DateTime')); //Test attributeRules and attributeLabels $attributeLabels = $searchForm->attributeLabels(); $this->assertEquals('Date Time', $attributeLabels['dateTime__DateTime']); $this->assertEquals('Date Time 2', $attributeLabels['dateTime2__DateTime']); //Test additional methods. $mappedData = $searchForm->getAttributesMappedToRealAttributesMetadata(); $this->assertEquals('resolveEntireMappingByRules', $mappedData['dateTime__DateTime']); $mappingRulesType = $searchForm->getSearchFormAttributeMappingRulesTypeByAttribute('dateTime__DateTime'); $this->assertEquals('MixedDateTimeTypes', $mappingRulesType); //Test that the correct elements are used for the dynamic date attribute. $elementType = ModelAttributeToMixedTypeUtil::getType($searchForm, 'dateTime__DateTime'); $this->assertEquals('MixedDateTypesForSearch', $elementType); }
/** * Test validating against a MixedRelationsModel */ public function testValidateDynamicClauses() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $searchForm = new MixedRelationsModelSearchFormTestModel(new MixedRelationsModel()); $searchForm->dynamicClauses = array(array('structurePosition' => '1', 'attributeIndexOrDerivedType' => 'primaryA', 'primaryA' => array('name' => 'xtz'))); $searchForm->dynamicStructure = '1'; $searchForm->validateDynamicClauses('dynamicClauses', array()); $this->assertFalse($searchForm->hasErrors()); $searchForm->clearErrors(); }