summaryrefslogtreecommitdiff
path: root/_test/tests/inc/cli_options.test.php
blob: 1d121d7ce23a108c3b5f0f8e662aab98db3b5a4b (plain)
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
47
48
49
50
51
52
53
54
55
56
<?php

class cli_options extends DokuWikiTest {

    function test_simpleshort() {
        $options = new DokuCLI_Options();
        $options->registerOption('exclude', 'exclude files', 'x', true);

        $args = array('-x', 'foo', 'bang');
        $options->parseOptions($args);

        $this->assertEquals('foo', $options->getOpt('exclude'));
        $this->assertEquals(array('bang'), $args);
        $this->assertFalse($options->getOpt('nothing'));
    }

    function test_simplelong1() {
        $options = new DokuCLI_Options();
        $options->registerOption('exclude', 'exclude files', 'x', true);

        $args = array('--exclude', 'foo', 'bang');
        $options->parseOptions($args);

        $this->assertEquals('foo', $options->getOpt('exclude'));
        $this->assertEquals(array('bang'), $args);
        $this->assertFalse($options->getOpt('nothing'));
    }

    function test_simplelong2() {
        $options = new DokuCLI_Options();
        $options->registerOption('exclude', 'exclude files', 'x', true);

        $args = array('--exclude=foo', 'bang');
        $options->parseOptions($args);

        $this->assertEquals('foo', $options->getOpt('exclude'));
        $this->assertEquals(array('bang'), $args);
        $this->assertFalse($options->getOpt('nothing'));
    }

    function test_complex() {
        $options = new DokuCLI_Options();

        $options->registerOption('plugins', 'run on plugins only', 'p');
        $options->registerCommand('status', 'display status info');
        $options->registerOption('long', 'display long lines', 'l', false, 'status');

        $args = array('-p', 'status', '--long', 'foo');
        $options->parseOptions($args);

        $this->assertEquals('status', $options->getCmd());
        $this->assertTrue($options->getOpt('plugins'));
        $this->assertTrue($options->getOpt('long'));
        $this->assertEquals(array('foo'), $args);
    }
}