/**
  * @static
  * @param Element_Interface $element
  * @return Element_Interface
  */
 public static function loadAllFields(Element_Interface $element)
 {
     if ($element instanceof Document) {
         Document_Service::loadAllDocumentFields($element);
     } else {
         if ($element instanceof Object_Concrete) {
             Object_Service::loadAllObjectFields($element);
         }
     }
     return $element;
 }
 /**
  * @param int $id
  * @return Webservice_Data_Document_Snippet_Out
  */
 public function getDocumentSnippetById($id)
 {
     try {
         $snippet = Document::getById($id);
         if ($snippet instanceof Document_Snippet) {
             // load all data (eg. href, snippet, ... which are lazy loaded)
             Document_Service::loadAllDocumentFields($snippet);
             $className = Webservice_Data_Mapper::findWebserviceClass($snippet, "out");
             $apiSnippet = Webservice_Data_Mapper::map($snippet, $className, "out");
             return $apiSnippet;
         }
         throw new Exception("Document Snippet with given ID (" . $id . ") does not exist.");
     } catch (Exception $e) {
         Logger::error($e);
         throw $e;
     }
 }
Exemple #3
0
 protected function documentTest($subtype)
 {
     $client = $this->getSoapClient();
     //get an document list with 3 elements
     $condition = "`type`= '" . $subtype . "'";
     $generalCondition = $this->getListCondition();
     if (!empty($generalCondition)) {
         if (!empty($condition)) {
             $condition .= " AND " . $generalCondition;
         } else {
             $condition = $generalCondition;
         }
     }
     $order = "";
     $orderKey = "";
     $offset = 0;
     $limit = 3;
     $groupBy = "";
     $wsDocument = $client->getDocumentList($condition, $order, $orderKey, $offset, $limit, $groupBy);
     $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Document_List_Item);
     //take the first element and fetch
     $documentId = $wsDocument[0]->id;
     $this->assertTrue(is_numeric($documentId));
     $wsMethod = "getDocument" . ucfirst($subtype) . "ById";
     $wsDocument = $client->{$wsMethod}($documentId);
     $wsDataClassIn = "Webservice_Data_Document_" . ucfirst($subtype) . "_In";
     $wsDataClassOut = "Webservice_Data_Document_" . ucfirst($subtype) . "_Out";
     $localClass = "Document_" . ucfirst($subtype);
     $this->assertTrue($wsDocument instanceof $wsDataClassOut);
     $document = new $localClass();
     $wsDocument->reverseMap($document);
     //some checks to see if we got a valid document
     $this->assertTrue($document->getCreationDate() > 0);
     $this->assertTrue(strlen($document->getPath()) > 0);
     //copy the document retrieved from ws
     $new = clone $document;
     $new->id = null;
     $new->setKey($document->getKey() . "_phpUnitTestCopy");
     $new->setResource(null);
     //send new document back via ws
     $apiPage = Webservice_Data_Mapper::map($new, $wsDataClassIn, "in");
     $wsMethod = "createDocument" . ucfirst($subtype);
     $id = $client->{$wsMethod}($apiPage);
     $this->assertTrue($id > 0);
     $wsMethod = "getDocument" . ucfirst($subtype) . "ById";
     $wsDocument = $client->{$wsMethod}($id);
     $this->assertTrue($wsDocument instanceof $wsDataClassOut);
     $refetchDocument = new $localClass();
     $wsDocument->reverseMap($refetchDocument);
     $this->assertTrue($refetchDocument->getId() > 1);
     $localDocument = $localClass::getById($documentId);
     Document_Service::loadAllDocumentFields($localDocument);
     //do that now, later id is null
     $localDocument->getProperties();
     //remove childs, this can not be set through WS
     $localDocument->childs = null;
     $this->assertTrue(Test_Tool::documentsAreEqual($localDocument, $refetchDocument, true));
     //update document
     if ($document instanceof Document_PageSnippet) {
         $refetchDocument->setPublished(!$refetchDocument->getPublished());
     }
     $refetchDocument->setProperty("updateTest", "text", "a update test");
     $apiPage = Webservice_Data_Mapper::map($refetchDocument, $wsDataClassIn, "in");
     $wsMethod = "updateDocument" . ucfirst($subtype);
     $success = $client->{$wsMethod}($apiPage);
     $this->assertTrue($success);
     $documentId = $refetchDocument->getId();
     $localDocument = $localClass::getById($documentId);
     $localDocument->getProperties();
     $localDocument->childs = null;
     $this->assertTrue(Test_Tool::documentsAreEqual($localDocument, $refetchDocument, true));
     //delete our test copy
     $success = $client->deleteDocument($refetchDocument->getId());
     $this->assertTrue($success);
 }