예제 #1
0
 /**
  * Tests metadata returned by model for given location
  * @group restContentServices
  */
 public function testGetMetadataByLocation()
 {
     $res = ezpRestContentModel::getMetadataByLocation( ezpContentLocation::fetchByNodeId( 2 ) );
     self::assertType( PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $res );
     
     $expectedKeys = array(
         'nodeId',
         'nodeRemoteId',
         'fullUrl'
     );
     
     foreach( $expectedKeys as $key )
     {
         self::assertArrayHasKey( $key, $res, "Content location must contain $key metadata" );
         switch( $key )
         {
             case 'nodeId':
                 self::assertType( PHPUnit_Framework_Constraint_IsType::TYPE_INT, $res[$key], 'NodeId must be an integer' );
             break;
                
             case 'nodeRemoteId':
             case 'fullUrl':
                 self::assertType( PHPUnit_Framework_Constraint_IsType::TYPE_STRING, $res[$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;
 }