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