コード例 #1
0
 /**
  * @param Revision $revision
  * @param EditInfo $editInfo
  *
  * @throws RuntimeException
  * @returns array
  */
 private function getEditParams(Revision $revision, EditInfo $editInfo = null)
 {
     if (!$revision->getPageIdentifier()->identifiesPage()) {
         throw new RuntimeException('$revision PageIdentifier does not identify a page');
     }
     $params = [];
     $content = $revision->getContent();
     $data = $content->getData();
     if (!is_string($data)) {
         throw new RuntimeException('Dont know how to save content of this model.');
     }
     $params['text'] = $content->getData();
     $params['md5'] = md5($content->getData());
     $timestamp = $revision->getTimestamp();
     if (!is_null($timestamp)) {
         $params['basetimestamp'] = $timestamp;
     }
     if (!is_null($revision->getPageIdentifier()->getId())) {
         $params['pageid'] = $revision->getPageIdentifier()->getId();
     } else {
         $params['title'] = $revision->getPageIdentifier()->getTitle()->getTitle();
     }
     $params['token'] = $this->api->getToken();
     if ($this->api->isLoggedin()) {
         $params['assert'] = 'user';
     }
     $this->addEditInfoParams($editInfo, $params);
     return $params;
 }
コード例 #2
0
 public function testGoodLoginSequence()
 {
     $client = $this->getMockClient();
     $user = new ApiUser('U1', 'P1');
     $eq1 = array('action' => 'login', 'lgname' => 'U1', 'lgpassword' => 'P1');
     $client->expects($this->at(0))->method('post')->with(null, $this->getExpectedOptsForPostParams($eq1))->will($this->returnValue($this->getMockResponse(array('login' => array('result' => 'NeedToken', 'token' => 'IamLoginTK')))));
     $client->expects($this->at(1))->method('post')->with(null, $this->getExpectedOptsForPostParams(array_merge($eq1, array('lgtoken' => 'IamLoginTK'))))->will($this->returnValue($this->getMockResponse(array('login' => array('result' => 'Success')))));
     $api = new MediawikiApi($client);
     $this->assertTrue($api->login($user));
     $this->assertEquals('U1', $api->isLoggedin());
 }