Exemplo n.º 1
0
 function testCloneFilter()
 {
     $mdFactory = new MockDocman_MetadataFactory();
     $mdFactory->setReturnValue('isRealMetadata', false);
     $md = new Docman_ListMetadata();
     $md->setLabel('item_type');
     $srcFilter = new Docman_FilterItemType($md);
     $dstReport = new Docman_Report();
     $dstReport->setGroupId(123);
     $filterFactory = new Docman_FilterFactoryTestVersion($this);
     $gsMd = new Docman_Metadata();
     $filterFactory->setReturnValue('getGlobalSearchMetadata', $gsMd);
     $gsMd->setLabel('global_txt');
     $itMd = new Docman_ListMetadata();
     $filterFactory->setReturnValue('getItemTypeSearchMetadata', $itMd);
     $itMd->setLabel('item_type');
     $itMd->setUseIt(PLUGIN_DOCMAN_METADATA_USED);
     $metadataMapping = array('md' => array(), 'love' => array());
     $dstFilterFactory = new Docman_FilterFactoryTestVersion($this);
     $filterFactory->setReturnValue('getFilterFactory', $dstFilterFactory);
     $filterFactory->cloneFilter($srcFilter, $dstReport, $metadataMapping);
     $dstFilterFactory->expectOnce('createFromMetadata');
     $filterFactory->expectOnce('cloneFilterValues');
     $dstFilterFactory->expectOnce('createFilter');
 }
Exemplo n.º 2
0
 function testCloneRealMetadata()
 {
     // Parameters
     $dstGroupId = '321';
     $metadataMapping = array();
     // Factory to test
     $srcMdF = new MetadataFactoryMockedForCloneRealMd($this);
     $srcMd1 = new Docman_ListMetadata();
     $srcMd1->setId(301);
     $srcMd1->setType(PLUGIN_DOCMAN_METADATA_TYPE_LIST);
     $srcMd2 = new Docman_Metadata();
     $srcMd2->setId(302);
     $srcMd2->setType(PLUGIN_DOCMAN_METADATA_TYPE_STRING);
     $srcMdF->setReturnValue('getRealMetadataList', array($srcMd1, $srcMd2));
     $srcMdF->expectOnce('getRealMetadataList', array(false));
     $srcMdF->expectCallCount('_cloneOneMetadata', 2);
     $srcMdF->expectAt(0, '_cloneOneMetadata', array($dstGroupId, $srcMd1, $metadataMapping));
     $srcMdF->expectAt(1, '_cloneOneMetadata', array($dstGroupId, $srcMd2, $metadataMapping));
     // Run the test
     $srcMdF->_cloneRealMetadata($dstGroupId, $metadataMapping);
 }
 function &getHardCodedMetadataFromLabel($label, $value = null)
 {
     $md = null;
     switch ($label) {
         case 'title':
             $md = new Docman_Metadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_title_name'));
             $md->setLabel('title');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_title_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_STRING);
             $md->setIsRequired(true);
             $md->setIsEmptyAllowed(false);
             $md->setKeepHistory(false);
             $md->setUseIt(true);
             $md->setCanChangeValue(true);
             break;
         case 'description':
             $md = new Docman_Metadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_desc_name'));
             $md->setLabel('description');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_desc_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_TEXT);
             $md->setIsRequired(true);
             $md->setIsEmptyAllowed(true);
             $md->setKeepHistory(false);
             $md->setUseIt(true);
             $md->setCanChangeValue(true);
             break;
         case 'owner':
             $md = new Docman_Metadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_owner_name'));
             $md->setLabel('owner');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_owner_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_STRING);
             $md->setIsRequired(true);
             $md->setIsEmptyAllowed(true);
             $md->setKeepHistory(true);
             $md->setUseIt(true);
             $md->setCanChangeValue(true);
             break;
         case 'create_date':
             $md = new Docman_Metadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_cdate_name'));
             $md->setLabel('create_date');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_cdate_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_DATE);
             $md->setIsRequired(true);
             $md->setIsEmptyAllowed(false);
             $md->setKeepHistory(true);
             $md->setUseIt(true);
             $md->setCanChangeValue(false);
             break;
         case 'update_date':
             $md = new Docman_Metadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_udate_name'));
             $md->setLabel('update_date');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_udate_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_DATE);
             $md->setIsRequired(true);
             $md->setIsEmptyAllowed(false);
             $md->setKeepHistory(true);
             $md->setUseIt(true);
             $md->setCanChangeValue(false);
             break;
         case 'status':
             $md = new Docman_ListMetadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_status_name'));
             $md->setLabel('status');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_status_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_LIST);
             $md->setIsRequired(false);
             $md->setIsEmptyAllowed(true);
             $md->setKeepHistory(true);
             $md->setCanChangeValue(true);
             $md->setDefaultValue(PLUGIN_DOCMAN_ITEM_STATUS_NONE);
             break;
         case 'obsolescence_date':
             $md = new Docman_Metadata();
             $md->setName($GLOBALS['Language']->getText('plugin_docman', 'md_odate_name'));
             $md->setLabel('obsolescence_date');
             $md->setDescription($GLOBALS['Language']->getText('plugin_docman', 'md_odate_desc'));
             $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_DATE);
             $md->setIsRequired(false);
             $md->setIsEmptyAllowed(true);
             $md->setKeepHistory(false);
             $md->setCanChangeValue(true);
             $md->setDefaultValue(0);
             break;
     }
     if ($md !== null) {
         $md->setValue($value);
         $md->setSpecial(true);
         $md->setCanChangeName(false);
         $md->setCanChangeIsEmptyAllowed(false);
         $md->setCanChangeDescription(false);
         $md->setGroupId($this->groupId);
     }
     return $md;
 }
 private function metadataIsRequieredAndAtLeastOneValueIsSelected(Docman_ListMetadata $metadata, array $selectedElements)
 {
     if ($metadata->isEmptyAllowed()) {
         return true;
     } elseif (count($selectedElements) > 1) {
         return true;
     } elseif (count($selectedElements) === 1 && isset($selectedElements[0]) && $selectedElements[0] != 100) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * 2 values + None in the source, one already exists in destination.
  * 1 value must be create and 1 updated
  */
 function testExportValuesWithNonEmptyDest()
 {
     // Factory to test
     $srcLoveF = new MetadataListOfValuesElementFactoryMocked($this);
     // Parameters
     $valuesMapping = array(101 => 201);
     $srcMd = new Docman_ListMetadata();
     $srcMd->setId(123);
     $srcMd->setLabel('field_123');
     $dstMd = new Docman_ListMetadata();
     $dstMd->setId(321);
     // Src elements
     $loveArray[0] = new MockDocman_MetadataListOfValuesElement($this);
     $loveArray[0]->setReturnValue('getId', 100);
     $loveArray[1] = new MockDocman_MetadataListOfValuesElement($this);
     $loveArray[1]->setReturnValue('getId', 101);
     $loveArray[2] = new MockDocman_MetadataListOfValuesElement($this);
     $loveArray[2]->setReturnValue('getId', 102);
     $srcLoveF->setReturnValue('getListByFieldId', $loveArray);
     $srcLoveF->expectOnce('getListByFieldId');
     $dstLoveF = new MockDocman_MetadataListOfValuesElementFactory($this);
     $dstLoveF->expectCallCount('create', 1);
     $dstLoveF->expectCallCount('update', 1);
     $srcLoveF->setReturnReference('getMetadataListOfValuesElementFactory', $dstLoveF);
     $srcLoveF->exportValues($srcMd, $dstMd, $valuesMapping);
 }
 function getItemTypeSearchMetadata()
 {
     // Special case for a fake metadata: item type search
     $md = new Docman_ListMetadata();
     $md->setGroupId($this->groupId);
     $md->setName($GLOBALS['Language']->getText('plugin_docman', 'filters_item_type'));
     $md->setType(PLUGIN_DOCMAN_METADATA_TYPE_LIST);
     $md->setUseIt(PLUGIN_DOCMAN_METADATA_USED);
     $md->setLabel('item_type');
     $md->setIsMultipleValuesAllowed(true);
     $row = array();
     $values = array();
     foreach (array('file', 'wiki', 'embeddedfile', 'empty', 'link', 'folder') as $type) {
         $row['value_id'] = constant('PLUGIN_DOCMAN_ITEM_TYPE_' . strtoupper($type));
         $row['name'] = $GLOBALS['Language']->getText('plugin_docman', 'filters_item_type_' . $type);
         $row['status'] = 'A';
         $love = new Docman_MetadataListOfValuesElement();
         $love->initFromRow($row);
         $values[] = $love;
     }
     $md->setListOfValueElements($values);
     return $md;
 }