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     * @expectedException \dokuwiki\plugin\struct\meta\ValidationException
17     */
18    public function test_validate_fail() {
19        $user = new User();
20        $user->validate('nosuchuser');
21    }
22
23    public function test_validate_success() {
24        $user = new User();
25        $user->validate('testuser');
26        $this->assertTrue(true); // we simply check that no exceptions are thrown
27
28        $user = new User(array('existingonly' => false));
29        $user->validate('nosuchuser');
30        $this->assertTrue(true); // we simply check that no exceptions are thrown
31    }
32
33    public function test_ajax() {
34        global $INPUT;
35
36        $user = new User(
37            array(
38                'autocomplete' => array(
39                    'fullname' => true,
40                    'mininput' => 2,
41                    'maxresult' => 5,
42                ),
43            )
44        );
45
46        $INPUT->set('search', 'test');
47        $this->assertEquals(array(array('label' => 'Arthur Dent [testuser]', 'value' => 'testuser')), $user->handleAjax());
48
49        $INPUT->set('search', 'dent');
50        $this->assertEquals(array(array('label' => 'Arthur Dent [testuser]', 'value' => 'testuser')), $user->handleAjax());
51
52        $INPUT->set('search', 'd'); // under mininput
53        $this->assertEquals(array(), $user->handleAjax());
54
55        $user = new User(
56            array(
57                'autocomplete' => array(
58                    'fullname' => false,
59                    'mininput' => 2,
60                    'maxresult' => 5,
61                ),
62            )
63        );
64
65        $INPUT->set('search', 'test');
66        $this->assertEquals(array(array('label' => 'Arthur Dent [testuser]', 'value' => 'testuser')), $user->handleAjax());
67
68        $INPUT->set('search', 'dent');
69        $this->assertEquals(array(), $user->handleAjax());
70
71        $user = new User(
72            array(
73                'autocomplete' => array(
74                    'fullname' => false,
75                    'mininput' => 2,
76                    'maxresult' => 0,
77                ),
78            )
79        );
80
81        $INPUT->set('search', 'test');
82        $this->assertEquals(array(), $user->handleAjax());
83    }
84}
85