Esempio n. 1
0
 /**
  * @covers ApiResult
  */
 public function testDeprecatedContinuation()
 {
     // Ignore ApiResult deprecation warnings during this test
     set_error_handler(function ($errno, $errstr) use(&$warnings) {
         if (preg_match('/Use of ApiResult::\\S+ was deprecated in MediaWiki \\d+.\\d+\\./', $errstr)) {
             return true;
         }
         return false;
     });
     $reset = new ScopedCallback('restore_error_handler');
     $allModules = array(new MockApiQueryBase('mock1'), new MockApiQueryBase('mock2'), new MockApiQueryBase('mocklist'));
     $generator = new MockApiQueryBase('generator');
     $main = new ApiMain(RequestContext::getMain());
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->setGeneratorContinueParam($generator, 'gcontinue', 3);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'm1continue' => '1|2', 'continue' => '||mock2'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2'), 'mocklist' => array('mlcontinue' => 2), 'generator' => array('gcontinue' => 3)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->setGeneratorContinueParam($generator, 'gcontinue', array(3, 4));
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('m1continue' => '1|2', 'continue' => '||mock2|mocklist'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2'), 'generator' => array('gcontinue' => '3|4')), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->setGeneratorContinueParam($generator, 'gcontinue', 3);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'gcontinue' => 3, 'continue' => 'gcontinue||'), $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mocklist' => array('mlcontinue' => 2), 'generator' => array('gcontinue' => 3)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setGeneratorContinueParam($generator, 'gcontinue', 3);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('gcontinue' => 3, 'continue' => 'gcontinue||mocklist'), $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(array('generator' => array('gcontinue' => 3)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'm1continue' => '1|2', 'continue' => '||mock2'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2'), 'mocklist' => array('mlcontinue' => 2)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[0], 'm1continue', array(1, 2));
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('m1continue' => '1|2', 'continue' => '||mock2|mocklist'), $result->getResultData('continue'));
     $this->assertSame(null, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mock1' => array('m1continue' => '1|2')), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->setContinueParam($allModules[2], 'mlcontinue', 2);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(array('mlcontinue' => 2, 'continue' => '-||mock1|mock2'), $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(array('mocklist' => array('mlcontinue' => 2)), $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation(null, $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, $allModules), $ret);
     $result->endContinuation('raw');
     $result->endContinuation('standard');
     $this->assertSame(null, $result->getResultData('continue'));
     $this->assertSame(true, $result->getResultData('batchcomplete'));
     $this->assertSame(null, $result->getResultData('query-continue'));
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation('||mock2', $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(false, array_values(array_diff_key($allModules, array(1 => 1)))), $ret);
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $ret = $result->beginContinuation('-||', $allModules, array('mock1', 'mock2'));
     $this->assertSame(array(true, array_values(array_diff_key($allModules, array(0 => 0, 1 => 1)))), $ret);
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     try {
         $result->beginContinuation('foo', $allModules, array('mock1', 'mock2'));
         $this->fail('Expected exception not thrown');
     } catch (UsageException $ex) {
         $this->assertSame('Invalid continue param. You should pass the original value returned by the previous query', $ex->getMessage(), 'Expected exception');
     }
     $main->setContinuationManager(null);
     $result = new ApiResult(8388608);
     $result->setMainForContinuation($main);
     $result->beginContinuation('||mock2', array_slice($allModules, 0, 2), array('mock1', 'mock2'));
     try {
         $result->setContinueParam($allModules[1], 'm2continue', 1);
         $this->fail('Expected exception not thrown');
     } catch (UnexpectedValueException $ex) {
         $this->assertSame('Module \'mock2\' was not supposed to have been executed, but it was executed anyway', $ex->getMessage(), 'Expected exception');
     }
     try {
         $result->setContinueParam($allModules[2], 'mlcontinue', 1);
         $this->fail('Expected exception not thrown');
     } catch (UnexpectedValueException $ex) {
         $this->assertSame('Module \'mocklist\' called ApiContinuationManager::addContinueParam ' . 'but was not passed to ApiContinuationManager::__construct', $ex->getMessage(), 'Expected exception');
     }
     $main->setContinuationManager(null);
 }