function testMendeleyWithCustomConstructorWorks() { $consumer = Configuration::getConsumer(); $mendeley = new Mendeley($consumer['key'], $consumer['secret']); $groupId = 164791; $url = 'groups/' . $groupId; $params = array('page' => 1, 'items' => 1); $result = $mendeley->get($url, $params); $this->assertEqual((int) $result->group_id, $groupId); }
function testUploadToMendeley() { $node = self::nodeFactory(); $biblioDoc = MendeleyBiblioDoc::constructWithNode($node); $mendeley = new Mendeley(); $response = $mendeley->post('documents', $biblioDoc->toParams()); $this->assertTrue(isset($response->document_id) && is_numeric($response->document_id)); $doc = $mendeley->get('documents/' . $response->document_id); $this->assertEqual($node->title, $doc->title); $this->assertEqual($node->biblio_type, MendeleyBiblioDoc::mendeleyToBiblioType($doc->type)); $this->assertEqual($node->taxonomy['taxonomy_term_1']['title'], $doc->tags[0]); $this->assertEqual($node->taxonomy['taxonomy_term_2']['title'], $doc->tags[1]); $this->assertEqual($node->biblio_contributors[MendeleyBiblioDoc::BIBLIO_AUTHOR][0]['name'], trim(implode(' ', array($doc->authors[0]->forename, $doc->authors[0]->surname)))); $this->assertEqual($node->biblio_contributors[MendeleyBiblioDoc::BIBLIO_AUTHOR][1]['name'], trim(implode(' ', array($doc->authors[1]->forename, $doc->authors[1]->surname)))); $this->assertEqual($node->biblio_abst_e, $doc->abstract); }
/** * Instantiates a Mendeley Document by its internal document id * * This almost an exact copy of @see MendeleyDoc::constructWithDocumentId because get_called_class is only available in PHP >= 5.3 * * @param string $documentId * sent by Mendeley in e.g. collections/*collectionId* */ public static function constructWithDocumentId($documentId) { $that = new MendeleyBiblioDoc(); $mendeley = new Mendeley(); if ($remote = $mendeley->get('documents/' . $documentId)) { $localParams = array_keys(get_object_vars($that)); $remoteParams = array_keys(get_object_vars($remote)); $match = array_intersect($localParams, $remoteParams); foreach ($match as $name) { if (!empty($remote->{$name})) { $that->{$name} = $remote->{$name}; } } $that->documentId = $documentId; } // authors are stored as objects in Mendeley and as strings in Biblio if (isset($that->authors)) { foreach ($that->authors as &$a) { $a = implode(' ', array($a->forename, $a->surname)); } } return $that; }
/** * Instantiate a Mendeley Document by its internal document id * * @param string $documentId * sent by Mendeley in e.g. collections/*collectionId* */ public static function constructWithDocumentId($documentId) { $that = new MendeleyDoc(); $mendeley = new Mendeley(); if ($remote = $mendeley->get('documents/' . $documentId)) { $localParams = array_keys(get_object_vars($that)); $remoteParams = array_keys(get_object_vars($remote)); $match = array_intersect($localParams, $remoteParams); foreach ($match as $name) { if (!empty($remote->{$name})) { $that->{$name} = $remote->{$name}; } } $that->documentId = $documentId; } return $that; }