Beispiel #1
0
 public function map($object)
 {
     $keys = get_object_vars($this);
     foreach ($keys as $key => $value) {
         $method = "get" . $key;
         if (method_exists($object, $method)) {
             if ($object->{$method}()) {
                 $this->{$key} = $object->{$method}();
                 // check for a pimcore data type
                 if ($this->{$key} instanceof Element_Interface) {
                     $this->{$key} = $this->{$key}->getId();
                 }
                 // if the value is an object or array call the mapper again for the value
                 if (is_object($this->{$key}) || is_array($this->{$key})) {
                     $type = "out";
                     if (strpos(get_class($this), "_In") !== FALSE) {
                         $type = "in";
                     }
                     $className = Webservice_Data_Mapper::findWebserviceClass($this->{$key}, "out");
                     $this->{$key} = Webservice_Data_Mapper::map($this->{$key}, $className, $type);
                 }
             }
         }
     }
 }
Beispiel #2
0
 public function testObjectConcrete()
 {
     $client = $this->getSoapClient();
     //get an object list with 3 elements
     $condition = "o_type='object'";
     $generalCondition = $this->getListCondition();
     if (!empty($generalCondition)) {
         if (!empty($condition)) {
             $condition .= " AND " . $generalCondition;
         } else {
             $condition = $generalCondition;
         }
     }
     $order = "";
     $orderKey = "";
     $offset = 0;
     $limit = 3;
     $groupBy = "";
     $wsDocument = $client->getObjectList($condition, $order, $orderKey, $offset, $limit, $groupBy);
     $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Object_List_Item);
     //take first element and fetch object
     $id = $wsDocument[0]->id;
     $this->assertTrue(is_numeric($id));
     $wsDocument = $client->getObjectConcreteById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out);
     $className = "Object_" . ucfirst($wsDocument->className);
     $this->assertTrue(class_exists($className));
     $object = new $className();
     $wsDocument->reverseMap($object);
     //some checks to see if we got a valid object
     $this->assertTrue($object->getCreationDate() > 0);
     $this->assertTrue(strlen($object->getPath()) > 0);
     //copy the object retrieved from ws
     $new = clone $object;
     $new->id = null;
     $new->setKey($object->getKey() . "_phpUnitTestCopy");
     $new->setResource(null);
     //send new object back via ws
     $apiObject = Webservice_Data_Mapper::map($new, "Webservice_Data_Object_Concrete_In", "in");
     $id = $client->createObjectConcrete($apiObject);
     $this->assertTrue($id > 0);
     $wsDocument = $client->getObjectConcreteById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Object_Concrete_Out);
     $refetchObject = new $className();
     $wsDocument->reverseMap($refetchObject);
     //make sure we deal with 2 different objects
     $this->assertTrue($id == $refetchObject->getId());
     $this->assertTrue($id != $object->getId());
     //compare original object, and the one we mangled back and forth through the web service
     $localObject = Object_Abstract::getById($object->getId());
     //remove childs, this can not be set through WS
     $localObject->setChilds(null);
     $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true));
     //update object
     $refetchObject->setProperty("updateTest", "text", "a update test");
     $refetchObject->setInput("my updated test");
     $apiObject = Webservice_Data_Mapper::map($refetchObject, "Webservice_Data_Object_Concrete_In", "in");
     //        Logger::err(print_r($apiObject,true));
     $success = $client->updateObjectConcrete($apiObject);
     Logger::err($client->getLastRequest());
     $this->assertTrue($success);
     $id = $refetchObject->getId();
     Test_Tool::resetRegistry();
     $localObject = Object_Abstract::getById($id);
     $localObject->setChilds(null);
     $this->assertTrue(Test_Tool::objectsAreEqual($localObject, $refetchObject, true));
     //delete our test copy
     $success = $client->deleteObject($refetchObject->getId());
     $this->assertTrue($success);
 }
Beispiel #3
0
 /**
  * @param int $id
  * @return Webservice_Data_Object_Concrete_Out
  */
 public function getObjectConcreteById($id)
 {
     try {
         $object = Object_Concrete::getById($id);
         if ($object instanceof Object_Concrete) {
             // load all data (eg. lazy loaded fields like multihref, object, ...)
             Object_Service::loadAllObjectFields($object);
             $apiObject = Webservice_Data_Mapper::map($object, "Webservice_Data_Object_Concrete_Out", "out");
             return $apiObject;
         }
         throw new Exception("Object with given ID (" . $id . ") does not exist.");
     } catch (Exception $e) {
         Logger::error($e);
         throw $e;
     }
 }
Beispiel #4
0
 /**
  * Returns the current tag's data for web service export
  *
  * @abstract
  * @return array
  */
 public function getForWebserviceExport()
 {
     $keys = get_object_vars($this);
     $el = array();
     foreach ($keys as $key => $value) {
         if ($value instanceof Element_Interface) {
             $value = $value->getId();
         }
         $className = Webservice_Data_Mapper::findWebserviceClass($value, "out");
         $el[$key] = Webservice_Data_Mapper::map($value, $className, "out");
     }
     unset($el["resource"]);
     unset($el["documentId"]);
     unset($el["controller"]);
     unset($el["view"]);
     unset($el["editmode"]);
     $el = Webservice_Data_Mapper::toObject($el);
     return $el;
 }
Beispiel #5
0
 public function testAssetFile()
 {
     $client = $this->getSoapClient();
     //get an asset list with 3 elements
     $condition = "`type`='image'";
     $generalCondition = $this->getListCondition();
     if (!empty($generalCondition)) {
         if (!empty($condition)) {
             $condition .= " AND " . $generalCondition;
         } else {
             $condition = $generalCondition;
         }
     }
     $order = "";
     $orderKey = "";
     $offset = 0;
     $limit = 3;
     $groupBy = "";
     $wsDocument = $client->getAssetList($condition, $order, $orderKey, $offset, $limit, $groupBy);
     $this->assertTrue(is_array($wsDocument) and $wsDocument[0] instanceof Webservice_Data_Asset_List_Item);
     //take the first element and fetch asset image
     $id = $wsDocument[0]->id;
     $this->assertTrue(is_numeric($id));
     $wsDocument = $client->getAssetFileById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_File_Out);
     $asset = new Asset_Image();
     $wsDocument->reverseMap($asset);
     //some checks to see if we got a valid object
     $this->assertTrue($asset->getCreationDate() > 0);
     $this->assertTrue(strlen($asset->getPath()) > 0);
     //copy the object retrieved from ws
     $new = clone $asset;
     $new->id = null;
     $new->setFilename("phpUnitTestCopy_" . $asset->getFilename());
     $new->setResource(null);
     //send new asset back via ws
     $apiAsset = Webservice_Data_Mapper::map($new, "Webservice_Data_Asset_File_In", "in");
     $id = $client->createAssetFile($apiAsset);
     $this->assertTrue($id > 0);
     $wsDocument = $client->getAssetFileById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_File_Out);
     $refetchAsset = new Asset_Image();
     $wsDocument->reverseMap($refetchAsset);
     //compare to original
     $original = Asset::getById($id);
     $this->assertTrue(Test_Tool::assetsAreEqual($original, $refetchAsset, true));
     //update asset file and set custom settings
     $refetchAsset->setCustomSettings(array("customSettingTest" => "This is a test"));
     $refetchAsset->setData(file_get_contents(TESTS_PATH . "/resources/assets/images/image5.jpg"));
     $apiAsset = Webservice_Data_Mapper::map($refetchAsset, "Webservice_Data_Asset_File_In", "in");
     $success = $client->updateAssetFile($apiAsset);
     $this->assertTrue($success);
     $wsDocument = $client->getAssetFileById($id);
     $this->assertTrue($wsDocument instanceof Webservice_Data_Asset_File_Out);
     $refetchAsset = new Asset_Image();
     $wsDocument->reverseMap($refetchAsset);
     $cs = $refetchAsset->getCustomSettings();
     $this->assertTrue(is_array($cs));
     $this->assertTrue($cs["customSettingTest"] == "This is a test");
     Test_Tool::resetRegistry();
     //compare to original
     $original = Asset::getById($id);
     $this->assertTrue(Test_Tool::assetsAreEqual($original, $refetchAsset, true));
     //delete our test copy
     $success = $client->deleteAsset($refetchAsset->getId());
     $this->assertTrue($success);
 }
Beispiel #6
0
 /**
  * @expectedException SoapFault
  * @return void
  *
  */
 public function testCreateElementWithoutKey()
 {
     $new = new Document_Page();
     $apiPage = Webservice_Data_Mapper::map($new, Webservice_Data_Document_Page_In, "in");
     $client = $this->getSoapClient();
     $client->createDocumentPage($apiPage);
 }