diff --git a/application/modules/admin/views/scripts/custom-fields-meta/index.phtml b/application/modules/admin/views/scripts/custom-fields-meta/index.phtml index 4bd5eb058b98f1a881c6afb74253e9be66f85725..5aacf9a6523c3a5b44091babdd7d7fd42362be62 100644 --- a/application/modules/admin/views/scripts/custom-fields-meta/index.phtml +++ b/application/modules/admin/views/scripts/custom-fields-meta/index.phtml @@ -13,14 +13,27 @@ echo $this->bouton('id=add_meta', 'largeur=250px;' ); -echo $this->tagModelTable($this->custom_fields_metas, - - [$this->_('Libellé'), $this->_('Type')], +$indexable_renderer = function($model, $attrib) { + return $model->getIndexable() ? + $this->tagImg(URL_ADMIN_IMG . '/ico/coche_verte.gif', ['alt' => $this->_('Oui')]): + $this->tagImg(URL_ADMIN_IMG . '/ico/del.gif', ['alt' => $this->_('Non')]); +}; - ['label', 'field_type_label'], +echo $this + ->tagModelTable($this->custom_fields_metas, - [ ['action' => 'edit', 'content' => $this->boutonIco('type=edit')], - ['action' => 'delete', 'content' => $this->boutonIco('type=del')] ], + [$this->_('Libellé'), + $this->_('Type'), + $this->_('Indexable ?')], - 'custom-fields-meta'); -?> + ['label', + 'field_type_label', + 'indexable'], + + [ ['action' => 'edit', 'content' => $this->boutonIco('type=edit')], + ['action' => 'delete', 'content' => $this->boutonIco('type=del')] ], + + 'custom-fields-meta', + null, + + ['indexable' => $indexable_renderer]); diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 633bd0493dc62447f2d64905cc6f127767b62ea6..6ab78cb83b050683157bc45a09053b727fa5d895 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -1,7 +1,7 @@ <?php error_reporting(E_ERROR | E_PARSE); -define("PATCH_LEVEL","264"); +define("PATCH_LEVEL","265"); define("APPLI","cosmogramme"); define("COSMOPATH", "/var/www/html/vhosts/opac2/www/htdocs"); diff --git a/cosmogramme/sql/patch/patch_265.php b/cosmogramme/sql/patch/patch_265.php new file mode 100644 index 0000000000000000000000000000000000000000..9de7e85278dd535f21fe9251e19894bc5f5633c9 --- /dev/null +++ b/cosmogramme/sql/patch/patch_265.php @@ -0,0 +1,17 @@ +<?php + +$sql = Zend_Db_Table_Abstract::getDefaultAdapter(); + +try { + $sql->query('select `indexable` from custom_field_meta limit 1;'); + +} catch(Exception $e) { + $sql->query("alter table `custom_field_meta` +add column `indexable` INT(1) unsigned NOT NULL DEFAULT '0', +add key `indexable` (`indexable`);"); +} + + +if (!$sql->query("select id from `codif_thesaurus` where id_thesaurus='CFCF';") + ->fetch()) + $sql->query("insert into `codif_thesaurus` (id_thesaurus, libelle, code) values ('CFCF', 'Champs personnalisés', 'Custom fields');"); diff --git a/library/Class/CustomField.php b/library/Class/CustomField.php index 888822702559b45f628d844d8ecacfc52b279b4a..49aafae70573704715b0683cdfafc0b8fe8a83d6 100644 --- a/library/Class/CustomField.php +++ b/library/Class/CustomField.php @@ -29,7 +29,6 @@ class CustomFieldsLoader extends Storm_Model_Loader { 'model' => $model]); if (!array_filter($custom_fields)) $availables_meta[] = $custom_field_meta; - } return $availables_meta; @@ -55,7 +54,35 @@ class Class_CustomField extends Storm_Model_Abstract { $_has_many = ['values' => ['model' => 'Class_CustomField_Value', 'role' => 'field', 'dependents' => 'delete']], - $_default_attribute_values = ['priority' => 0]; + $_default_attribute_values = ['priority' => 0], + $_forwarded_to_meta = ['label', 'field_type', 'options_list', 'indexable']; + + + public function __call($method, $args) { + if ($this->_shouldBeForwardedToMeta($method)) { + $result = call_user_func_array([$this->getMeta(), $method], $args); + return $this->_isGetter($method) ? $result : $this; + } + + return parent::__call($method, $args); + } + + + protected function _shouldBeForwardedToMeta($method) { + return preg_match('/(get|set)(\w+)/', $method, $matches) + && ($attribute = $this->_accessorToAttributeName($matches[2])) + && in_array($attribute, $this->_forwarded_to_meta); + } + + + protected function _isGetter($method) { + return $this->_startsWith($method, 'get'); + } + + + protected function _startsWith($method, $value) { + return $value == substr($method, 0, strlen($value)); + } public function getMeta() { @@ -76,11 +103,6 @@ class Class_CustomField extends Storm_Model_Abstract { return $this->getTitre(); } - public function setLabel($value) { - $this->getMeta()->setLabel($value); - return $this; - } - public function getLabel() { return $this->getTitre(); @@ -92,44 +114,23 @@ class Class_CustomField extends Storm_Model_Abstract { } - public function setFieldType($value) { - $this->getMeta()->setFieldType($value); - return $this; - } - - - public function getFieldType() { - return $this->getMeta()->getFieldType(); - } - - - public function setOptionsList($options) { - $this->getMeta()->setOptionsList($options); - return $this; - } - + public function toArray() { + $from_meta = []; + foreach($this->_forwarded_to_meta as $property) { + $method = 'get' . $this->attributeNameToAccessor($property); + $from_meta[$property] = $this->$method(); + } - public function getOptionsList() { - return $this->getMeta()->getOptionsList(); + return array_merge(parent::toArray(), $from_meta); } - public function getOptionsListAsArray() { - return $this->getMeta()->getOptionsListAsArray(); - } - - - public function toArray() { - return array_merge(parent::toArray(), ['label' => $this->getLabel(), - 'field_type' => $this->getFieldType(), - 'options_list' => $this->getOptionsList()]); - } - public function getFieldsOfSameModel() { - return Class_CustomField::getLoader()->findAllBy(['model' => $this->getModel(), - 'order' => 'priority']); + return $this->getLoader()->findAllBy(['model' => $this->getModel(), + 'order' => 'priority']); } + public function movePriorityUp() { $this ->getLoader() @@ -164,5 +165,19 @@ class Class_CustomField extends Storm_Model_Abstract { return array_values(array_filter($new_order)); } -} -?> \ No newline at end of file + + + public function getOptionsListAsArray() { + return $this->getMeta()->getOptionsListAsArray(); + } + + + public function isIndexable() { + return 1 == $this->getIndexable(); + } + + + public function getFacet() { + return $this->getMeta()->getFacet(); + } +} \ No newline at end of file diff --git a/library/Class/CustomField/Meta.php b/library/Class/CustomField/Meta.php index 797b497f039edce5a37b6b918b8064c7f153ae52..a17d06c4f6dd2dd3b1e8a7397d45d28d7c25342a 100644 --- a/library/Class/CustomField/Meta.php +++ b/library/Class/CustomField/Meta.php @@ -27,7 +27,8 @@ class Class_CustomField_Meta extends Storm_Model_Abstract { TEXT_INPUT = 'text', TEXT_AREA = 'textarea', CKEDITOR = 'ckeditor', - SELECT = 'select'; + SELECT = 'select', + SELECT_SEPARATOR = ';'; protected static $_models = []; @@ -39,7 +40,8 @@ class Class_CustomField_Meta extends Storm_Model_Abstract { 'dependents' => 'delete']], $_default_attribute_values = ['label' => '', 'field_type' => self::TEXT_INPUT, - 'options_list' => '']; + 'options_list' => '', + 'indexable' => 0]; public function getLibelle() { return $this->getLabel(); @@ -47,15 +49,15 @@ class Class_CustomField_Meta extends Storm_Model_Abstract { public function getFieldTypes() { return - [Class_CustomField_Meta::TEXT_INPUT => $this->_('Texte'), - Class_CustomField_Meta::TEXT_AREA => $this->_('Zone de texte simple'), - Class_CustomField_Meta::CKEDITOR => $this->_('Zone de texte HTML'), - Class_CustomField_Meta::SELECT => $this->_("Liste d'options")]; + [self::TEXT_INPUT => $this->_('Texte'), + self::TEXT_AREA => $this->_('Zone de texte simple'), + self::CKEDITOR => $this->_('Zone de texte HTML'), + self::SELECT => $this->_("Liste d'options")]; } public function getOptionsListAsArray() { - $options = explode(';',$this->getOptionsList()); + $options = explode(self::SELECT_SEPARATOR, $this->getOptionsList()); $options = array_map(function($option) {return trim($option);}, $options); return array_filter($options); } @@ -64,5 +66,9 @@ class Class_CustomField_Meta extends Storm_Model_Abstract { public function getFieldTypeLabel() { return $this->getFieldTypes()[$this->getFieldType()]; } -} -?> \ No newline at end of file + + + public function getFacetLabel() { + return $this->getLabel(); + } +} \ No newline at end of file diff --git a/library/Class/CustomField/Value.php b/library/Class/CustomField/Value.php index 2c5fa4cdfadf0798109e96e6a6f21150c96100d9..8bd29280d432ca959fc4c9193097561dfda8ea03 100644 --- a/library/Class/CustomField/Value.php +++ b/library/Class/CustomField/Value.php @@ -52,14 +52,17 @@ class Class_CustomField_Value extends Storm_Model_Abstract { 'referenced_in' => 'custom_field_id']], $_default_attribute_values = ['value' => '']; + public function getFieldType() { return $this->getField()->getFieldType(); } + public function getLabel() { return $this->getField()->getLabel(); } + public function getOptionsListAsArray() { return $this->getField()->getOptionsListAsArray(); } diff --git a/library/ZendAfi/Form/Admin/CustomFields.php b/library/ZendAfi/Form/Admin/CustomFields.php index b16393ca1810b0b368b8ddccba39435f3ffc93fb..84e121357dce82673ea6daea5bcb0297b068aab0 100644 --- a/library/ZendAfi/Form/Admin/CustomFields.php +++ b/library/ZendAfi/Form/Admin/CustomFields.php @@ -24,42 +24,54 @@ class ZendAfi_Form_Admin_CustomFields extends ZendAfi_Form { public function init() { parent::init(); - $this->_toggleOptionsList(); - $this + ->_toggleOptionsList() + ->setAttrib('id', 'custom_field') ->setAttrib('action', '') + ->addElement('text', 'label', ['label' => $this->_('Libellé du champ'), 'size' => 50, 'required' => true, 'allowEmpty' => false]) + ->addElement('select', 'field_type', ['label' => $this->_('Type de champ'), 'multioptions' => (new Class_CustomField_Meta())->getFieldTypes(), 'required' => true, 'allowEmpty' => false]) + + ->addElement('checkbox', + 'indexable', + ['label' => $this->_('Indexable dans les notices ?'), + 'required' => true, + 'allowEmpty' => false]) + ->addElement('text', 'options_list', ['label' => $this->_('Options pour le type "liste d\'options"'), 'size' => 50, - 'placeholder' => $this->_('option 1; option 2; option 3')]); + 'placeholder' => $this->_('option 1; option 2; option 3')]) + + ->addDisplayGroup(['label', 'field_type', 'indexable'], 'base', ['legend' => '']) + ->addDisplayGroup(['options_list'], 'options', ['legend' => $this->_('Options')]); } protected function _toggleOptionsList() { - return Class_ScriptLoader::getInstance() - ->addJQueryBackEnd('formSelectToggleVisibilityForElement("#field_type", "#fieldset-options", "'.Class_CustomField_Meta::SELECT.'");'); + Class_ScriptLoader::getInstance() + ->addJQueryBackEnd('formSelectToggleVisibilityForElement("#field_type", "#fieldset-options", "' . Class_CustomField_Meta::SELECT . '");'); + return $this; } + public function getFieldTypeLabel($fieldType) { return (new Class_CustomField_Meta())->getFieldTypes()[$fieldType]; } - -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Admin/CustomFields/CustomFieldMeta.php b/library/ZendAfi/Form/Admin/CustomFields/CustomFieldMeta.php index 1b8dd83f62492c37e32176d6c3fce1f11b2cc697..bd1d3486a98897bab31fcbf13929afc4154f27b3 100644 --- a/library/ZendAfi/Form/Admin/CustomFields/CustomFieldMeta.php +++ b/library/ZendAfi/Form/Admin/CustomFields/CustomFieldMeta.php @@ -21,13 +21,4 @@ class ZendAfi_Form_Admin_CustomFields_CustomFieldMeta extends ZendAfi_Form_Admin_CustomFields { - public static function newWith($custom_field_meta_array=[], $custom_form=null) { - $form = new self(); - $form - ->populate($custom_field_meta_array) - ->addDisplayGroup(['label', 'field_type'],'base',['legend' => '']) - ->addDisplayGroup(['options_list'], 'options', ['legend' => $form->_('Options')]); - return $form; - } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Admin/CustomFields/CustomFieldModel.php b/library/ZendAfi/Form/Admin/CustomFields/CustomFieldModel.php index 4398b8ee56b37c6118e98a365b245770264d1ee2..e0676be37750f3a6a70b8663c141f8d435629ad0 100644 --- a/library/ZendAfi/Form/Admin/CustomFields/CustomFieldModel.php +++ b/library/ZendAfi/Form/Admin/CustomFields/CustomFieldModel.php @@ -21,16 +21,8 @@ class ZendAfi_Form_Admin_CustomFields_CustomFieldModel extends ZendAfi_Form_Admin_CustomFields { - - public static function newWith($custom_field_array=[], $custom_form=null) { - $form = new self(); - $form - ->addElement('hidden', 'model') - ->populate($custom_field_array) - ->addDisplayGroup(['label', 'field_type', 'model'],'base',['legend' => '']) - ->addDisplayGroup(['options_list'], 'options', ['legend' => $form->_('Options'), - 'class' => 'invisible']); - return $form; + public function init() { + parent::init(); + $this->addElement('hidden', 'model'); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php b/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php index 3e29f2be181439df86d23a4648b4777b4e752f03..1b1df326912921a0db16d0192c429a1b12767f98 100644 --- a/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php +++ b/tests/application/modules/admin/controllers/CustomFieldsControllerTest.php @@ -18,20 +18,20 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once 'AbstractControllerTestCase.php'; - abstract class CustomFieldControllerTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { parent::setUp(); $this->fixture('Class_CustomField_Meta', - ['id' => 1, - 'label' => 'Address', - 'field_type' => Class_CustomField_Meta::TEXT_INPUT, - 'options_list' => '']); - + ['id' => 1, + 'label' => 'Address', + 'field_type' => Class_CustomField_Meta::TEXT_INPUT, + 'options_list' => '', + 'indexable' => 1]); $this->fixture('Class_CustomField', ['id' => 1, @@ -39,7 +39,6 @@ abstract class CustomFieldControllerTestCase extends AbstractControllerTestCase 'priority' => 1, 'model' => 'Article']); - $this->fixture('Class_CustomField', ['id' => 2, 'meta_id' => 1, @@ -81,12 +80,10 @@ abstract class CustomFieldControllerTestCase extends AbstractControllerTestCase 'field_type' => Class_CustomField_Meta::CKEDITOR, 'model' => 'UserGroup']); - $this->fixture('Class_UserGroup', ['id' => 1, 'libelle' => 'Teachers']); - $this->fixture('Class_CustomField_Value', //teachers address ['id' => 23, 'custom_field_id' => 3, @@ -104,7 +101,6 @@ abstract class CustomFieldControllerTestCase extends AbstractControllerTestCase 'custom_field_id' => 5, 'model_id' => 1, 'value' => 'enabled']); - } } @@ -229,6 +225,12 @@ class CustomFieldsControllerAddIndexTest extends CustomFieldControllerTestCase { } + /** @test */ + public function indexableShouldBeDisplay() { + $this->assertXPath('//form//input[@name="indexable"]'); + } + + /** @test */ public function hiddenInputModelValueShouldBeUserGroup() { $this->assertXPath('//form//input[@name="model"][@value="UserGroup"]'); @@ -264,41 +266,49 @@ class CustomFieldsControllerAddIndexTest extends CustomFieldControllerTestCase { class CustomFieldsControllerPostAddActionTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setup() { parent::setup(); - Class_CustomField::beVolatile(); - Class_CustomField_Meta::beVolatile(); - $this->postDispatch('admin/custom-fields/add/model/Article', ['label' => 'public', - 'field_type' => 'text', - 'model' => 'Article']); + 'field_type' => 'text', + 'indexable' => 1, + 'model' => 'Article']); + + $this->field = Class_CustomField::find(1); } /** @test */ public function customFieldMetaShouldHaveBeenCreated() { - $this->assertEquals('public', Class_CustomField::find(1)->getLabel()); + $this->assertEquals('public', $this->field->getLabel()); } /** @test */ public function customFieldShouldNotHaveAttributFieldType() { - $attributes = Class_CustomField::find(1)->getRawAttributes(); + $attributes = $this->field->getRawAttributes(); $this->assertFalse(isset($attributes['field_type'])); } /** @test */ public function customFieldMetaShouldBeText() { - $this->assertEquals('text', Class_CustomField_Meta::find(1)->getFieldType()); + $this->assertEquals('text', $this->field->getFieldType()); } /** @test */ public function customFieldModelShouldBeClassArticle() { - $this->assertEquals('Article', Class_CustomField::find(1)->getModel()); + $this->assertEquals('Article', $this->field->getModel()); + } + + + /** @test */ + public function shouldBeIndexable() { + $this->assertEquals(1, $this->field->getIndexable()); } } @@ -323,6 +333,12 @@ class CustomFieldsControllerEditIndexTest extends CustomFieldControllerTestCase } + /** @test */ + public function shouldBeIndexable() { + $this->assertXPath('//input[@name="indexable"][@checked="checked"]'); + } + + /** @test */ public function optionsListShouldBeEmpty() { $this->assertXPath('//input[@name="options_list"][@value=""]'); @@ -341,10 +357,11 @@ class CustomFieldsControllerPostEditActionTest extends CustomFieldControllerTest public function setUp() { parent::setUp(); - $this->postDispatch('admin/custom-fields/edit/model/Article/id/1', ['label' => 'public', - 'field_type' => 'SELECT', - 'options_list' => 'all; teens', - 'model' => 'Article']); + $this->postDispatch('admin/custom-fields/edit/model/Article/id/1', + ['label' => 'public', + 'field_type' => 'SELECT', + 'options_list' => 'all; teens', + 'model' => 'Article']); } @@ -433,7 +450,6 @@ class CustomFieldsControllerValuesForUserGroupWithMetaDeletedTest extends Custom public function setUp() { parent::setUp(); Class_CustomField_Meta::deleteBy([]); - } @@ -504,6 +520,7 @@ class CustomFieldsControllerValuesForUserGroupTeachersTest extends CustomFieldCo $this->assertXPath('//form//fieldset//select//option[@value="enabled"][@selected="selected"]',$this->_response->getBody()); } + /** @test */ public function backButtonShouldLinkToUsergroupsEditTeachers() { $this->assertXPathContentContains('//div[contains(@onclick, "admin/usergroup/edit/id/1")]//td', 'Retour'); diff --git a/tests/application/modules/admin/controllers/CustomFieldsMetaControllerTest.php b/tests/application/modules/admin/controllers/CustomFieldsMetaControllerTest.php index 0744275c3cd7b2c1679cce96d56282f3c5b540d4..04e91229d327b61c6262a8dc9d9f667c0c58d280 100644 --- a/tests/application/modules/admin/controllers/CustomFieldsMetaControllerTest.php +++ b/tests/application/modules/admin/controllers/CustomFieldsMetaControllerTest.php @@ -20,26 +20,29 @@ */ abstract class CustomFieldsMetaControllerTestCase extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + public function setUp() { parent::setUp(); - $this->fixture('Class_CustomField_Meta', [ - 'id' => 1, - 'label' => 'Address', - 'field_type' => Class_CustomField_Meta::TEXT_INPUT, - 'options_list' => '']); - - $this->fixture('Class_CustomField_Meta', [ - 'id' => 2, - 'label' => 'Status', - 'field_type' => Class_CustomField_Meta::SELECT]); - - - $this->fixture('Class_CustomField', [ - 'id' => 1, - 'meta_id' => 1, - 'priority' => 2, - 'model' => 'Article']); + $this->fixture('Class_CustomField_Meta', + ['id' => 1, + 'label' => 'Address', + 'field_type' => Class_CustomField_Meta::TEXT_INPUT, + 'options_list' => '', + 'indexable' => 0]); + + $this->fixture('Class_CustomField_Meta', + ['id' => 2, + 'label' => 'Status', + 'field_type' => Class_CustomField_Meta::SELECT, + 'indexable' => 1]); + + $this->fixture('Class_CustomField', + ['id' => 1, + 'meta_id' => 1, + 'priority' => 2, + 'model' => 'Article']); } } @@ -53,45 +56,76 @@ class CustomFieldsMetaControllerIndexActionTest extends CustomFieldsMetaControll } + public function columnsProvider() { + return [ ['Libellé', 'Type', 'Indexable'] ]; + } + + + /** + * @test + * @dataProvider columnsProvider + */ + public function columnShouldBePresent($header) { + $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//th', $header); + } + + + /** @test */ + public function shouldListAddress() { + $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//tr[1]/td', + 'Address'); + } + + /** @test */ - public function tableCustomFieldsMetaShouldListAddress() { - $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//td', 'Address'); + public function addressShouldBeChampTexte() { + $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//tr[1]//td', + 'Texte'); } /** @test */ - public function fieldTypeForAddressShouldBeChampTexte() { - $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//td', 'Texte'); + public function addressShouldNotBeIndexable() { + $this->assertXPath('//table[@id="custom-fields-meta"]//tr[1]//td//img[@alt="Non"]'); } /** @test */ - public function tableCustomFieldsMetaShouldListStatus() { - $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//td', 'Status'); + public function shouldListStatus() { + $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//tr[2]//td', 'Status'); } /** @test */ - public function fieldTypeForStatusShouldBeListeDOptions() { - $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//td', 'Liste d\'options'); + public function statusShouldBeListeDOptions() { + $this->assertXPathContentContains('//table[@id="custom-fields-meta"]//tr[2]//td', 'Liste d\'options'); + } + + + /** @test */ + public function statusShouldBeIndexable() { + $this->assertXPath('//table[@id="custom-fields-meta"]//tr[2]//td//img[@alt="Oui"]'); } /** @test */ public function linkToAddNewShouldBePresent() { - $this->assertXPathContentContains('//div[contains(@onclick, "/admin/custom-fields-meta/add")]//td', 'Nouveau type de champ'); + $this->assertXPathContentContains('//div[contains(@onclick, "/admin/custom-fields-meta/add")]//td', + 'Nouveau type de champ'); } + /** @test */ public function backToCustomFieldsLinkShouldBePresent() { - $this->assertXPathContentContains('//div[contains(@onclick, "/admin/custom-fields\'")]', 'Retour à la liste'); + $this->assertXPathContentContains('//div[contains(@onclick, "/admin/custom-fields\'")]', + 'Retour à la liste'); } } -class CustomFieldsMetaControllerEditActionTest extends CustomFieldsMetaControllerTestCase { +class CustomFieldsMetaControllerEditAddressActionTest extends CustomFieldsMetaControllerTestCase { public function setUp() { parent::setUp(); $this->dispatch('admin/custom-fields-meta/edit/id/1', true); @@ -108,6 +142,39 @@ class CustomFieldsMetaControllerEditActionTest extends CustomFieldsMetaControlle public function fieldTypeShouldBeText() { $this->assertXPath('//select/option[@value="text"][@selected="selected"]'); } + + + /** @test */ + public function shouldNotBeIndexable() { + $this->assertNotXPath('//input[@name="indexable"][@checked="checked"]'); + } +} + + + +class CustomFieldsMetaControllerEditStatusActionTest extends CustomFieldsMetaControllerTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('admin/custom-fields-meta/edit/id/2', true); + } + + + /** @test */ + public function inputLabelShouldContainsStatus() { + $this->assertXPath('//input[@name="label"][@value="Status"]'); + } + + + /** @test */ + public function fieldTypeShouldBeSelect() { + $this->assertXPath('//select/option[@value="select"][@selected="selected"]'); + } + + + /** @test */ + public function shouldBeIndexable() { + $this->assertXPath('//input[@name="indexable"][@checked="checked"]'); + } } @@ -124,6 +191,11 @@ class CustomFieldsMetaControllerAddActionTest extends CustomFieldsMetaController $this->assertXPath('//input[@name="label"][@value=""]'); } + + /** @test */ + public function shouldNotBeIndexable() { + $this->assertNotXPath('//input[@name="indexable"][@checked="checked"]'); + } } @@ -135,13 +207,16 @@ class CustomFieldsMetaControllerPostEditActionTest extends CustomFieldsMetaContr $this->postDispatch('admin/custom-fields-meta/edit/id/1', ['label' => 'public', 'field_type' => Class_CustomField_Meta::SELECT, - 'options_list' => 'teens; parents ; all public ; ']); + 'options_list' => 'teens; parents ; all public ; ', + 'indexable' => 1]); + + $this->meta = Class_CustomField_Meta::find(1); } /** @test */ public function labelShouldBePublic() { - $this->assertEquals('public', Class_CustomField_Meta::find(1)->getLabel()); + $this->assertEquals('public', $this->meta->getLabel()); } @@ -149,7 +224,7 @@ class CustomFieldsMetaControllerPostEditActionTest extends CustomFieldsMetaContr public function fieldTypeShouldBeSelect() { $this->assertEquals( Class_CustomField_Meta::SELECT, - Class_CustomField_Meta::find(1)->getFieldType()); + $this->meta->getFieldType()); } @@ -157,7 +232,13 @@ class CustomFieldsMetaControllerPostEditActionTest extends CustomFieldsMetaContr public function optionsListShouldBeTeensAndParents() { $this->assertEquals( ['teens', 'parents', 'all public'], - Class_CustomField_Meta::find(1)->getOptionsListAsArray()); + $this->meta->getOptionsListAsArray()); + } + + + /** @test */ + public function shouldBecomeIndexable() { + $this->assertEquals(1, $this->meta->getIndexable()); } } @@ -182,6 +263,4 @@ class CustomFieldsMetaControllerDeleteAddressFieldTest extends CustomFieldsMetaC public function customFieldAddressShouldBeDeleted() { $this->assertEmpty(Class_CustomField::find(1)); } -} - -?> \ No newline at end of file +} \ No newline at end of file