1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\ValidationException;
6use dokuwiki\plugin\struct\types\User;
7
8/**
9 * Testing the User Type
10 *
11 * @group plugin_struct
12 * @group plugins
13 */
14class Type_User_struct_test extends StructTest
15{
16
17    public function test_validate_fail()
18    {
19        $this->expectException(ValidationException::class);
20        $user = new User();
21        $user->validate('nosuchuser');
22    }
23
24    public function test_validate_success()
25    {
26        $user = new User();
27        $user->validate('testuser');
28        $this->assertTrue(true); // we simply check that no exceptions are thrown
29
30        $user = new User(array('existingonly' => false));
31        $user->validate('nosuchuser');
32        $this->assertTrue(true); // we simply check that no exceptions are thrown
33    }
34
35    public function test_ajax()
36    {
37        global $INPUT;
38
39        $user = new User(
40            array(
41                'autocomplete' => array(
42                    'fullname' => true,
43                    'mininput' => 2,
44                    'maxresult' => 5,
45                ),
46            )
47        );
48
49        $INPUT->set('search', 'test');
50        $this->assertEquals(array(array('label' => 'Arthur Dent [testuser]', 'value' => 'testuser')), $user->handleAjax());
51
52        $INPUT->set('search', 'dent');
53        $this->assertEquals(array(array('label' => 'Arthur Dent [testuser]', 'value' => 'testuser')), $user->handleAjax());
54
55        $INPUT->set('search', 'd'); // under mininput
56        $this->assertEquals(array(), $user->handleAjax());
57
58        $user = new User(
59            array(
60                'autocomplete' => array(
61                    'fullname' => false,
62                    'mininput' => 2,
63                    'maxresult' => 5,
64                ),
65            )
66        );
67
68        $INPUT->set('search', 'test');
69        $this->assertEquals(array(array('label' => 'Arthur Dent [testuser]', 'value' => 'testuser')), $user->handleAjax());
70
71        $INPUT->set('search', 'dent');
72        $this->assertEquals(array(), $user->handleAjax());
73
74        $user = new User(
75            array(
76                'autocomplete' => array(
77                    'fullname' => false,
78                    'mininput' => 2,
79                    'maxresult' => 0,
80                ),
81            )
82        );
83
84        $INPUT->set('search', 'test');
85        $this->assertEquals(array(), $user->handleAjax());
86    }
87}
88