public function testReversePagination() { global $wgFlowCacheVersion; $cache = $this->getMockBuilder('Flow\\Data\\BufferedCache')->disableOriginalConstructor()->getMock(); $storage = $this->getMockBuilder('Flow\\Data\\ObjectStorage')->disableOriginalConstructor()->getMock(); $dbId = FeatureIndex::cachedDbId(); $cache->expects($this->any())->method('getMulti')->will($this->returnValue(array("{$dbId}:foo:5:{$wgFlowCacheVersion}" => array(array('some_row' => 40), array('some_row' => 41), array('some_row' => 42), array('some_row' => 43), array('some_row' => 44))))); $storage->expects($this->never())->method('findMulti'); $index = new MockFeatureIndex($cache, $storage, 'foo', array('bar')); $res = $index->find(array('bar' => 5), array('offset-id' => 43, 'offset-dir' => 'rev', 'limit' => 2)); $this->assertEquals(array(array('some_row' => 41, 'bar' => 5), array('some_row' => 42, 'bar' => 5)), array_values($res), 'Data should retain original sort, taking selected items from before the offset'); }
public function testCompositeShallow() { global $wgFlowCacheTime; $bag = new BufferedBagOStuff(new \HashBagOStuff()); $cache = new BufferedCache($bag, $wgFlowCacheTime); $storage = $this->getMock('Flow\\Data\\ObjectStorage'); $unique = new UniqueFeatureIndex($cache, $storage, 'unique', array('id', 'ot')); $secondary = new TopKIndex($cache, $storage, 'secondary', array('name'), array('shallow' => $unique, 'sort' => 'id')); // remember: unique index still stores an array of results to be consistent with other indexes // even though, due to uniqueness, there is only one value per set of keys $db = FeatureIndex::cachedDbId(); $v = Container::get('cache.version'); $bag->set("{$db}:unique:1:9:{$v}", array(array('id' => 1, 'ot' => 9, 'name' => 'foo'))); $bag->set("{$db}:unique:1:8:{$v}", array(array('id' => 1, 'ot' => 8, 'name' => 'foo'))); $bag->set("{$db}:unique:3:7:{$v}", array(array('id' => 3, 'ot' => 7, 'name' => 'baz'))); $bag->set("{$db}:secondary:foo:{$v}", array(array('id' => 1, 'ot' => 9), array('id' => 1, 'ot' => 8))); $bag->set("{$db}:secondary:baz:{$v}", array(array('id' => 3, 'ot' => 7))); $expect = array(array('id' => 1, 'ot' => 9, 'name' => 'foo'), array('id' => 1, 'ot' => 8, 'name' => 'foo')); $this->assertEquals($expect, $secondary->find(array('name' => 'foo'))); $expect = array(array('id' => 3, 'ot' => 7, 'name' => 'baz')); $this->assertEquals($expect, $secondary->find(array('name' => 'baz'))); }