/** * This function shows the fields which are usable referring to the Mendeley API error message * Right now the error message (i.e. fields you can use) is equal for all document types */ public function testGetDocumentTypeFields() { $doc = new MendeleyDoc(); $doc->authors = array('a'); $doc->keywords = array('a'); $doc->tags = array('a'); $doc->title = '1'; $doc->website = '1'; $doc->year = 2011; $doc->bogus = 1; // will throw error which hopefully explains which fields are allowed foreach (MendeleyDoc::getTypes() as $type) { $doc->type = $type; try { $result = $this->mendeley->post('documents/', $doc->toParams()); } catch (Exception $e) { $fields[$type] = self::extractMendeleyTypes($e->getMessage()); } } // get fields all types have in common $intersect = reset($fields); foreach ($fields as $f) { $intersect = array_intersect($intersect, $f); } var_export($intersect); // remove fields which are common by all types foreach ($fields as &$f) { $f = array_diff($f, $intersect); } var_export($fields); }
function testCreateGenericDocument() { $title = 'Example Title'; $tags = array('a', 'b'); $groupId = 504091; $type = 'Generic'; $doc = new MendeleyDoc(); $doc->title = $title; $doc->tags = $tags; $doc->group_id = $groupId; $doc->type = $type; $result = $this->mendeley->post('documents/', $doc->toParams()); $this->assertTrue(!empty($result)); $this->assertTrue(isset($result->document_id) && is_numeric($result->document_id)); $this->tmp['documentId'] = $result->document_id; }