xref: /dokuwiki/_test/tests/Search/Query/PageSetTest.php (revision ede4646658cf51245060332d97a319a39c788ea1)
1*ede46466SAndreas Gohr<?php
2*ede46466SAndreas Gohr
3*ede46466SAndreas Gohrnamespace dokuwiki\test\Search\Query;
4*ede46466SAndreas Gohr
5*ede46466SAndreas Gohruse dokuwiki\Search\Query\PageSet;
6*ede46466SAndreas Gohr
7*ede46466SAndreas Gohrclass PageSetTest extends \DokuWikiTest
8*ede46466SAndreas Gohr{
9*ede46466SAndreas Gohr    public function testIntersect()
10*ede46466SAndreas Gohr    {
11*ede46466SAndreas Gohr        $a = new PageSet(['p1' => 2, 'p2' => 3, 'p3' => 1]);
12*ede46466SAndreas Gohr        $b = new PageSet(['p1' => 1, 'p3' => 4]);
13*ede46466SAndreas Gohr
14*ede46466SAndreas Gohr        $result = $a->intersect($b);
15*ede46466SAndreas Gohr
16*ede46466SAndreas Gohr        $this->assertEquals(['p1' => 3, 'p3' => 5], $result->getPages());
17*ede46466SAndreas Gohr    }
18*ede46466SAndreas Gohr
19*ede46466SAndreas Gohr    public function testUnite()
20*ede46466SAndreas Gohr    {
21*ede46466SAndreas Gohr        $a = new PageSet(['p1' => 2, 'p2' => 3]);
22*ede46466SAndreas Gohr        $b = new PageSet(['p1' => 1, 'p3' => 4]);
23*ede46466SAndreas Gohr
24*ede46466SAndreas Gohr        $result = $a->unite($b);
25*ede46466SAndreas Gohr
26*ede46466SAndreas Gohr        $this->assertEquals(['p1' => 3, 'p2' => 3, 'p3' => 4], $result->getPages());
27*ede46466SAndreas Gohr    }
28*ede46466SAndreas Gohr
29*ede46466SAndreas Gohr    public function testSubtract()
30*ede46466SAndreas Gohr    {
31*ede46466SAndreas Gohr        $a = new PageSet(['p1' => 2, 'p2' => 3, 'p3' => 1]);
32*ede46466SAndreas Gohr        $b = new PageSet(['p2' => 1]);
33*ede46466SAndreas Gohr
34*ede46466SAndreas Gohr        $result = $a->subtract($b);
35*ede46466SAndreas Gohr
36*ede46466SAndreas Gohr        $this->assertEquals(['p1' => 2, 'p3' => 1], $result->getPages());
37*ede46466SAndreas Gohr    }
38*ede46466SAndreas Gohr
39*ede46466SAndreas Gohr    public function testIsEmpty()
40*ede46466SAndreas Gohr    {
41*ede46466SAndreas Gohr        $this->assertTrue((new PageSet())->isEmpty());
42*ede46466SAndreas Gohr        $this->assertTrue((new PageSet([]))->isEmpty());
43*ede46466SAndreas Gohr        $this->assertFalse((new PageSet(['p1' => 1]))->isEmpty());
44*ede46466SAndreas Gohr    }
45*ede46466SAndreas Gohr
46*ede46466SAndreas Gohr    public function testIntersectNoOverlap()
47*ede46466SAndreas Gohr    {
48*ede46466SAndreas Gohr        $a = new PageSet(['p1' => 1]);
49*ede46466SAndreas Gohr        $b = new PageSet(['p2' => 1]);
50*ede46466SAndreas Gohr
51*ede46466SAndreas Gohr        $this->assertEquals([], $a->intersect($b)->getPages());
52*ede46466SAndreas Gohr    }
53*ede46466SAndreas Gohr}
54