summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/cli_options.test.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/_test/tests/inc/cli_options.test.php b/_test/tests/inc/cli_options.test.php
new file mode 100644
index 000000000..ab03ee29b
--- /dev/null
+++ b/_test/tests/inc/cli_options.test.php
@@ -0,0 +1,56 @@
+<?php
+
+class cli_options extends DokuWikiTest {
+
+ function test_simpleshort() {
+ $options = new DokuCLI_Options();
+ $options->registerOption('exclude', 'exclude files', 'x', 'file');
+
+ $options->args = array('-x', 'foo', 'bang');
+ $options->parseOptions();
+
+ $this->assertEquals('foo', $options->getOpt('exclude'));
+ $this->assertEquals(array('bang'), $options->args);
+ $this->assertFalse($options->getOpt('nothing'));
+ }
+
+ function test_simplelong1() {
+ $options = new DokuCLI_Options();
+ $options->registerOption('exclude', 'exclude files', 'x', 'file');
+
+ $options->args = array('--exclude', 'foo', 'bang');
+ $options->parseOptions();
+
+ $this->assertEquals('foo', $options->getOpt('exclude'));
+ $this->assertEquals(array('bang'), $options->args);
+ $this->assertFalse($options->getOpt('nothing'));
+ }
+
+ function test_simplelong2() {
+ $options = new DokuCLI_Options();
+ $options->registerOption('exclude', 'exclude files', 'x', 'file');
+
+ $options->args = array('--exclude=foo', 'bang');
+ $options->parseOptions();
+
+ $this->assertEquals('foo', $options->getOpt('exclude'));
+ $this->assertEquals(array('bang'), $options->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');
+
+ $options->args = array('-p', 'status', '--long', 'foo');
+ $options->parseOptions();
+
+ $this->assertEquals('status', $options->getCmd());
+ $this->assertTrue($options->getOpt('plugins'));
+ $this->assertTrue($options->getOpt('long'));
+ $this->assertEquals(array('foo'), $options->args);
+ }
+} \ No newline at end of file