コード例 #1
0
 /**
  * Tests fields data that will be returned to the output
  * @group restContentServices
  */
 public function testAttributeOutputData()
 {
     $content = ezpContent::fromNodeId(2);
     $expectedKeys = array('type', 'identifier', 'value', 'id', 'classattribute_id');
     // Browse all the fields and compare result provided by ezpRestContentModel::attributeOutputData() with manually generated data
     foreach ($content->fields as $fieldName => $field) {
         $aAttributeOutput = ezpRestContentModel::attributeOutputData($field);
         foreach ($expectedKeys as $key) {
             self::assertArrayHasKey($key, $aAttributeOutput, "Content field must have '{$key}' metadata");
             switch ($key) {
                 case 'type':
                     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $aAttributeOutput[$key]);
                     self::assertEquals($field->data_type_string, $aAttributeOutput[$key]);
                     break;
                 case 'identifier':
                     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $aAttributeOutput[$key]);
                     self::assertEquals($field->contentclass_attribute_identifier, $aAttributeOutput[$key]);
                     break;
                 case 'value':
                     // Value can be either string or boolean
                     self::assertTrue(is_string($aAttributeOutput[$key]) || is_bool($aAttributeOutput[$key]));
                     break;
                 case 'id':
                     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $aAttributeOutput[$key]);
                     self::assertEquals($field->id, $aAttributeOutput[$key]);
                     break;
                 case 'classattribute_id':
                     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_INT, $aAttributeOutput[$key]);
                     self::assertEquals($field->contentclassattribute_id, $aAttributeOutput[$key]);
                     break;
             }
         }
     }
 }
コード例 #2
0
ファイル: content.php プロジェクト: legende91/ez
 /**
  * Handles a content unique field request through an object or node ID
  *
  * Requests:
  * - GET /api/content/node/:nodeId/field/:fieldIdentifier
  * - GET /api/content/object/:objectId/field/:fieldIdentifier
  *
  * @return ezpRestMvcResult
  */
 public function doViewField()
 {
     $this->setDefaultResponseGroups(array(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES));
     $isNodeRequested = false;
     if (isset($this->nodeId)) {
         $isNodeRequested = true;
         $content = ezpContent::fromNodeId($this->nodeId);
     } else {
         if (isset($this->objectId)) {
             $content = ezpContent::fromObjectId($this->objectId);
         }
     }
     if (!isset($content->fields->{$this->fieldIdentifier})) {
         throw new ezpContentFieldNotFoundException("'{$this->fieldIdentifier}' field is not available for this content.");
     }
     // Translation parameter
     if ($this->hasContentVariable('Translation')) {
         $content->setActiveLanguage($this->getContentVariable('Translation'));
     }
     $result = new ezpRestMvcResult();
     // Field data
     if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)) {
         $result->variables['fields'][$this->fieldIdentifier] = ezpRestContentModel::attributeOutputData($content->fields->{$this->fieldIdentifier});
     }
     // Handle object/node metadata
     if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGORUP_METADATA)) {
         $objectMetadata = ezpRestContentModel::getMetadataByContent($content, $isNodeRequested);
         if ($isNodeRequested) {
             $nodeMetadata = ezpRestContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId));
             $objectMetadata = array_merge($objectMetadata, $nodeMetadata);
         }
         $result->variables['metadata'] = $objectMetadata;
     }
     return $result;
 }