public function testRequiredAttributesAreMissingFromLayout() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $account = AccountTestHelper::createAccountByNameForOwner('aTestAccount', $super); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/create'); $this->assertNotContains('There are required fields missing from the following layout', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/list'); $this->assertNotContains('There are required fields missing from the following layout', $content); $this->setGetArray(array('id' => $account->id)); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/edit'); $this->assertNotContains('There are required fields missing from the following layout', $content); //Now create an attribute that is required. $this->createTextCustomFieldByModule('AccountsModule', 'text'); $content = $this->runControllerWithExitExceptionAndGetContent('accounts/default/create'); $this->assertContains('There are required fields missing from the following layout', $content); $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/default/list'); $this->assertNotContains('There are required fields missing from the following layout', $content); $this->setGetArray(array('id' => $account->id)); $content = $this->runControllerWithExitExceptionAndGetContent('accounts/default/edit'); $this->assertContains('There are required fields missing from the following layout', $content); //Remove the new field. $modelAttributesAdapterClassName = TextAttributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new Account()); $adapter->removeAttributeMetadata('text'); RequiredAttributesValidViewUtil::resolveToRemoveAttributeAsMissingRequiredAttribute('Account', 'text'); $account = new Account(); $this->assertFalse($account->isAttribute('text')); unset($account); }
public static function createTextAttribute($attributeName, $withDefaultData, $modelClassName) { assert('isset($attributeName) && $attributeName != null'); assert('isset($withDefaultData) && is_bool($withDefaultData)'); $attributeForm = new TextAttributeForm(); $attributeForm->attributeName = $attributeName; $attributeForm->attributeLabels = array('de' => 'Test' . $attributeName . 'de', 'en' => 'Test' . $attributeName . 'en', 'es' => 'Test' . $attributeName . 'es', 'fr' => 'Test' . $attributeName . 'fr', 'it' => 'Test' . $attributeName . 'it'); $attributeForm->isAudited = true; $attributeForm->isRequired = false; $attributeForm->maxLength = 50; if ($withDefaultData) { $attributeForm->defaultValue = 'Kangaroo'; } $validate = $attributeForm->validate(); if ($validate == false) { throw new FailedToValidateException(); } $modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData(); $adapter = new $modelAttributesAdapterClassName(new $modelClassName()); try { $adapter->setAttributeMetadataFromForm($attributeForm); } catch (FailedDatabaseSchemaChangeException $e) { echo $e->getMessage(); Yii::app()->end(0, false); } }