File: Restrictgroups.php

package info (click to toggle)
php-horde-kolab-server 2.0.5-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,860 kB
  • sloc: php: 11,626; xml: 844; sh: 3; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,612 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

class Horde_Kolab_Server_Constraint_Restrictgroups extends PHPUnit\Framework\Constraint\Constraint
{
    public function evaluate($other, $description = '', $returnResult = FALSE)
    {
        if ($other instanceof Horde_Kolab_Server_Query_Element_Interface) {
            if ($other instanceof Horde_Kolab_Server_Query_Element_Group) {
                $elements = $other->getElements();
                foreach ($elements as $element) {
                    if ($this->evaluate($element)) {
                        return true;
                    }
                }
                return true;
            } else {
                if ($other->getName() == 'objectClass'
                    && $other->getValue() == Horde_Kolab_Server_Object_Groupofnames::OBJECTCLASS_GROUPOFNAMES) {
                    return true;
                } else {
                    return false;
                }                    
            }
        } else {
            return false;
        }
    }

    public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL): void
    {
        throw new PHPUnit_Framework_ExpectationFailedException(
          sprintf(
            '%sFailed asserting that %s contains a query element that restricts the search to groups',

            !empty($description) ? $description . "\n" : '',
            PHPUnit_Util_Type::toString($other, TRUE)
          ),
          NULL
        );
    }

    public function toString(): string
    {
        return 'contains a query element that restricts the search to groups';
    }
}