File: ConfigDeleteTest.php

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (568 lines) | stat: -rw-r--r-- 27,529 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\CoreAdminHome\tests\Integration\Commands;

use Piwik\Container\Container;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Config;
use Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase;

/**
 * @group Core
 * @group CoreAdminHome
 * @group Integration
 */
class ConfigDeleteTest extends ConsoleCommandTestCase
{
    /*
     * The text config:delete outputs when no matching value is found.
     */

    private const COMMAND = 'config:delete';
    private const CLASS_NAME_SHORT = 'ConfigDeleteTest';
    private const MSG_NOTHING_FOUND = 'Nothing found';

    /*
     * Path to store the test config file. It should be deleted when done.
     */
    private const TEST_CONFIG_PATH = '/tmp/test.config.ini.php';
    // Section 1.
    private const TEST_SECTION_1_NAME = self::CLASS_NAME_SHORT . '_test_section_1';
    // Setting 1.1
    private const TEST_SETTING_1_1_NAME = self::CLASS_NAME_SHORT . '_test_setting_1';
    private const TEST_SETTING_1_1_VALUE = self::CLASS_NAME_SHORT . '_test_value_1';
    // Setting 1.2
    private const TEST_SETTING_1_2_NAME = self::CLASS_NAME_SHORT . '_test_setting_2';
    private const TEST_SETTING_1_2_VALUE = self::CLASS_NAME_SHORT . '_test_value_2';
    // Setting 1.3 - IPv4 address with port
    private const TEST_SETTING_1_3_NAME = self::CLASS_NAME_SHORT . '_test_setting_3_ipv4_address';
    private const TEST_SETTING_1_3_VALUE = self::CLASS_NAME_SHORT . '123.123.123.123:8080';
    // Setting 1.4 - IPv6 address with port
    private const TEST_SETTING_1_4_NAME = self::CLASS_NAME_SHORT . '_test_setting_4_ipv6_address';
    private const TEST_SETTING_1_4_VALUE = self::CLASS_NAME_SHORT . '[2001:858:a6::186]:80';
    // Setting 1.5 - IPv4 subnet
    private const TEST_SETTING_1_5_NAME = self::CLASS_NAME_SHORT . '_test_setting_5_ipv6_subnet';
    private const TEST_SETTING_1_5_VALUE = self::CLASS_NAME_SHORT . '192.168.x.x/24';
    // Setting 1.6 - IPv6 subnet
    private const TEST_SETTING_1_6_NAME = self::CLASS_NAME_SHORT . '_test_setting_6_ipv6_subnet';
    private const TEST_SETTING_1_6_VALUE = self::CLASS_NAME_SHORT . '2001:db8::/32';
    // Setting 1.7 - mail address with extension
    private const TEST_SETTING_1_7_NAME = self::CLASS_NAME_SHORT . '_test_setting_7_mail_address';
    private const TEST_SETTING_1_7_VALUE = self::CLASS_NAME_SHORT . 'no-reply+with-extension@test.at';
    // Setting 1.8 - comma separated list
    private const TEST_SETTING_1_8_NAME = self::CLASS_NAME_SHORT . '_test_setting_8_comma_separated_list';
    private const TEST_SETTING_1_8_VALUE = self::CLASS_NAME_SHORT . '50,100,250,500,1000,2000,5000';

    // Section 2.
    private const TEST_SECTION_2_NAME = self::CLASS_NAME_SHORT . '_test_section_2';
    // Setting 2.1
    private const TEST_SETTING_2_1_NAME = self::CLASS_NAME_SHORT . '_array_setting_1';
    private const TEST_SETTING_2_1_VALUE_0 = self::CLASS_NAME_SHORT . '_arr_val_1';
    private const TEST_SETTING_2_1_VALUE_1 = self::CLASS_NAME_SHORT . '_arr_val_2';
    private const TEST_SETTING_2_1_VALUE_2 = self::CLASS_NAME_SHORT . '_arr_val_3';
    private const TEST_SETTING_2_1_VALUES = [self::TEST_SETTING_2_1_VALUE_0, self::TEST_SETTING_2_1_VALUE_1, self::TEST_SETTING_2_1_VALUE_2];
    // Setting 2.2 - IPv4 address with port
    private const TEST_SETTING_2_2_NAME = self::CLASS_NAME_SHORT . '_array_setting_2_ipv4_address';
    private const TEST_SETTING_2_2_VALUE_0 = self::CLASS_NAME_SHORT . '123.123.123.123:8080';
    private const TEST_SETTING_2_2_VALUE_1 = self::CLASS_NAME_SHORT . '234.234.234.234:8080';
    private const TEST_SETTING_2_2_VALUE_2 = self::CLASS_NAME_SHORT . '16.16.16.16:5423';
    private const TEST_SETTING_2_2_VALUES = [self::TEST_SETTING_2_2_VALUE_0, self::TEST_SETTING_2_2_VALUE_1, self::TEST_SETTING_2_2_VALUE_2];
    // Setting 2.3 - IPv6 address with port
    private const TEST_SETTING_2_3_NAME = self::CLASS_NAME_SHORT . '_array_setting_3_ipv6_address';
    private const TEST_SETTING_2_3_VALUE_0 = self::CLASS_NAME_SHORT . '[2001:858:dead::186]:80';
    private const TEST_SETTING_2_3_VALUE_1 = self::CLASS_NAME_SHORT . '[2001:858:beef::186]:180';
    private const TEST_SETTING_2_3_VALUE_2 = self::CLASS_NAME_SHORT . '[2001:858:cafe::186]:9080';
    private const TEST_SETTING_2_3_VALUES = [self::TEST_SETTING_2_3_VALUE_0, self::TEST_SETTING_2_3_VALUE_1, self::TEST_SETTING_2_3_VALUE_2];
    // Setting 2.4 - IPv4 subnet
    private const TEST_SETTING_2_4_NAME = self::CLASS_NAME_SHORT . '_array_setting_4_ipv4_subnet';
    private const TEST_SETTING_2_4_VALUE_0 = self::CLASS_NAME_SHORT . '192.168.x.x/24';
    private const TEST_SETTING_2_4_VALUE_1 = self::CLASS_NAME_SHORT . '172.16.x.x/30';
    private const TEST_SETTING_2_4_VALUE_2 = self::CLASS_NAME_SHORT . '10.0.0.0/16';
    private const TEST_SETTING_2_4_VALUES = [self::TEST_SETTING_2_4_VALUE_0, self::TEST_SETTING_2_4_VALUE_1, self::TEST_SETTING_2_4_VALUE_2];
    // Setting 2.5 - IPv6 subnet
    private const TEST_SETTING_2_5_NAME = self::CLASS_NAME_SHORT . '_array_setting_5_ipv6_subnet';
    private const TEST_SETTING_2_5_VALUE_0 = self::CLASS_NAME_SHORT . '2001:db8:dead:/32';
    private const TEST_SETTING_2_5_VALUE_1 = self::CLASS_NAME_SHORT . '2001:db8:beef:/32';
    private const TEST_SETTING_2_5_VALUE_2 = self::CLASS_NAME_SHORT . '2001:858:cafe:/64';
    private const TEST_SETTING_2_5_VALUES = [self::TEST_SETTING_2_5_VALUE_0, self::TEST_SETTING_2_5_VALUE_1, self::TEST_SETTING_2_5_VALUE_2];
    // Setting 2.6 - mail address with extension
    private const TEST_SETTING_2_6_NAME = self::CLASS_NAME_SHORT . '_array_setting_6_mail_address';
    private const TEST_SETTING_2_6_VALUE_0 = self::CLASS_NAME_SHORT . 'no-reply+with_extension@test.at';
    private const TEST_SETTING_2_6_VALUE_1 = self::CLASS_NAME_SHORT . 'your-mail_address@example.com';
    private const TEST_SETTING_2_6_VALUE_2 = self::CLASS_NAME_SHORT . 'noreply@example.com';
    private const TEST_SETTING_2_6_VALUES = [self::TEST_SETTING_2_6_VALUE_0, self::TEST_SETTING_2_6_VALUE_1, self::TEST_SETTING_2_6_VALUE_2];
    // Setting 2.7 - comma separated list
    private const TEST_SETTING_2_7_NAME = self::CLASS_NAME_SHORT . '_array_setting_7_commaseparated_list';
    private const TEST_SETTING_2_7_VALUE_0 = self::CLASS_NAME_SHORT . '50,100,250,500,1000,2000,5000';
    private const TEST_SETTING_2_7_VALUE_1 = self::CLASS_NAME_SHORT . '1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597';
    private const TEST_SETTING_2_7_VALUE_2 = self::CLASS_NAME_SHORT . 'm,a,t,o,m,o,r,p,h,o,s,i,s';
    private const TEST_SETTING_2_7_VALUES = [self::TEST_SETTING_2_7_VALUE_0, self::TEST_SETTING_2_7_VALUE_1, self::TEST_SETTING_2_7_VALUE_2];

    public static function setUpBeforeClass(): void
    {
        self::removeTestConfigFile();
        parent::setUpBeforeClass();
    }

    public function setUp(): void
    {
        self::removeTestConfigFile();
        parent::setUp();
    }

    private static function getTestConfigFilePath()
    {
        return PIWIK_INCLUDE_PATH . self::TEST_CONFIG_PATH;
    }

    public static function provideContainerConfigBeforeClass()
    {
        return array(
            // use a config instance that will save to a test INI file
            'Piwik\Config' => function (Container $container) {
                /** @var GlobalSettingsProvider $actualGlobalSettingsProvider */
                $actualGlobalSettingsProvider = $container->get('Piwik\Application\Kernel\GlobalSettingsProvider');

                $config = self::makeTestConfig();

                // copy over sections required for tests
                $config->tests = $actualGlobalSettingsProvider->getSection('tests');
                $config->database = $actualGlobalSettingsProvider->getSection('database_tests');

                return $config;
            },
        );
    }

    private static function makeTestConfig()
    {
        $settingsProvider = new GlobalSettingsProvider(null, self::getTestConfigFilePath());
        $config = new Config($settingsProvider);

        // Add the first section.
        $sectionName = self::TEST_SECTION_1_NAME;
        $config->$sectionName[self::TEST_SETTING_1_1_NAME] = self::TEST_SETTING_1_1_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_2_NAME] = self::TEST_SETTING_1_2_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_3_NAME] = self::TEST_SETTING_1_3_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_4_NAME] = self::TEST_SETTING_1_4_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_5_NAME] = self::TEST_SETTING_1_5_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_6_NAME] = self::TEST_SETTING_1_6_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_7_NAME] = self::TEST_SETTING_1_7_VALUE;
        $config->$sectionName[self::TEST_SETTING_1_8_NAME] = self::TEST_SETTING_1_8_VALUE;

        // Add a second section so we are testing that we do not accidentally return it.
        $sectionName = self::TEST_SECTION_1_NAME . '_second_section';
        // Add a setting with the same name as in section #1 but with a random int value.
        $config->$sectionName[self::TEST_SETTING_1_1_NAME] = random_int(PHP_INT_MIN, PHP_INT_MAX);
        // Add another setting to the same section with some bogus content.
        $config->$sectionName[self::TEST_SETTING_1_2_NAME . '_another'] = '127.0.0.1';


        // Add the second section.
        // Add an array value like section=PluginsInstalled; setting=PluginsInstalled[].
        $sectionName = self::TEST_SECTION_2_NAME;
        // Add some values to the setting array.
        $config->$sectionName[self::TEST_SETTING_2_1_NAME] = self::TEST_SETTING_2_1_VALUES;
        $config->$sectionName[self::TEST_SETTING_2_2_NAME] = self::TEST_SETTING_2_2_VALUES;
        $config->$sectionName[self::TEST_SETTING_2_3_NAME] = self::TEST_SETTING_2_3_VALUES;
        $config->$sectionName[self::TEST_SETTING_2_4_NAME] = self::TEST_SETTING_2_4_VALUES;
        $config->$sectionName[self::TEST_SETTING_2_5_NAME] = self::TEST_SETTING_2_5_VALUES;
        $config->$sectionName[self::TEST_SETTING_2_6_NAME] = self::TEST_SETTING_2_6_VALUES;
        $config->$sectionName[self::TEST_SETTING_2_7_NAME] = self::TEST_SETTING_2_7_VALUES;

        $config->forceSave();
        return $config;
    }

    private static function removeTestConfigFile()
    {
        $configPath = self::getTestConfigFilePath();
        if (file_exists($configPath)) {
            unlink($configPath);
        }
    }

    private static function makeNewConfig()
    {
        $settings = new GlobalSettingsProvider(null, self::getTestConfigFilePath());
        return new Config($settings);
    }

    private function runCommandWithOptions(string $sectionName, string $settingName, string $value = ''): object
    {

        $inputArr = [
            'command' => self::COMMAND,
            '--section' => $sectionName,
            '--key' => $settingName,
            '-vvv' => false,
        ];
        if (!empty($value)) {
            $inputArr['--value'] = $value;
        }
        $exitCode = $this->applicationTester->run($inputArr);

        // Pass true to getDisplay(true) to normalize line endings, then trim() bc CLI adds an \ automatically.
        $output = trim($this->applicationTester->getDisplay(true));

        // Put the results in an easy-to-handle object format.
        return (object) ['exitCode' => $exitCode, 'output' => $output];
    }

    private function runCommandWithArguments(string $sectionName, string $settingName = '', string $value = ''): object
    {

        $inputArr = [
            'command' => self::COMMAND,
            '-vvv' => false,
            'argument' => $sectionName . '.' . $settingName . (empty($value) ? '' : ".$value"),
        ];

        $exitCode = $this->applicationTester->run($inputArr);

        // Pass true to getDisplay(true) to normalize line endings, then trim() bc CLI adds an \ automatically.
        $output = trim($this->applicationTester->getDisplay(true));

        // Put the results in an easy-to-handle object format.
        return (object) ['exitCode' => $exitCode, 'output' => $output];
    }

    //
    //*************************************************************************
    // Tests that should yield errors.
    //*************************************************************************
    //
    public function testNoArgsShouldYieldError()
    {

        $inputArr = [
            'command' => 'config:get',
            '-vvv' => false,
        ];
        $exitCode = $this->applicationTester->run($inputArr);

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $exitCode);

        // Pass true to getDisplay(true) to normalize line endings, then trim() bc CLI adds an \ automatically.
        $output = trim($this->applicationTester->getDisplay(true));

        $this->assertStringContainsString('InvalidArgumentException', $output);
    }

    public function testEmptyArgsShouldYieldError()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithArguments('');

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $resultObj->exitCode);

        $this->assertStringContainsString('InvalidArgumentException', $resultObj->output);
    }

    public function testEmptyOptionsShouldYieldError()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions('', '');

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $resultObj->exitCode);

        $this->assertStringContainsString('InvalidArgumentException', $resultObj->output);
    }

    public function testSetArgsAndOptionsShouldYieldError()
    {
        $inputArr = [
            'command' => 'config:get',
            'argument' => self::TEST_SECTION_1_NAME . '.' . self::TEST_SETTING_1_1_NAME,
            '--section' => self::TEST_SECTION_1_NAME,
            '--key' => self::TEST_SETTING_1_1_NAME,
            '-vvv' => false,
        ];
        $exitCode = $this->applicationTester->run($inputArr);

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $exitCode);

        // Pass true to getDisplay(true) to normalize line endings, then trim() bc CLI adds an \ automatically.
        $output = trim($this->applicationTester->getDisplay(true));

        $this->assertStringContainsString('InvalidArgumentException', $output);
    }

    public function testEmptySectionShouldYieldError()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions('', self::TEST_SETTING_1_1_NAME);

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $resultObj->exitCode);

        $this->assertStringContainsString('InvalidArgumentException', $resultObj->output);
    }

    public function testScalarSettingWithArrayValShouldYieldError()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions(self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_1_NAME, self::CLASS_NAME_SHORT . '_Array_key_does_not_exist');

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $resultObj->exitCode);

        $this->assertStringContainsString('InvalidArgumentException', $resultObj->output);
    }

    public function testArrayWithNoValShouldYieldError()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions(self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_1_NAME);

        // The CLI error code should be >0 indicating failure.
        $this->assertGreaterThan(0, $resultObj->exitCode);

        $this->assertStringContainsString('InvalidArgumentException', $resultObj->output);
    }

    //
    //*************************************************************************
    // Tests for nonexistent data.
    //*************************************************************************
    //
    public function testUsingOptsNonExistentSectionShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions(self::CLASS_NAME_SHORT . '_Section_does_not_exist', self::TEST_SETTING_1_1_NAME);

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingArgsNonExistentSectionShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithArguments(self::CLASS_NAME_SHORT . '_Section_does_not_exist', self::TEST_SETTING_1_1_NAME);

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingOptsNonExistentSectionAndSettingShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions(self::CLASS_NAME_SHORT . '_Section_does_not_exist', self::CLASS_NAME_SHORT . '_Setting_does_not_exist');

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingArgsNonExistentSectionAndSettingShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithArguments(self::CLASS_NAME_SHORT . '_Section_does_not_exist', self::CLASS_NAME_SHORT . '_Setting_does_not_exist');

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingOptsNonExistentSettingShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions(self::TEST_SECTION_1_NAME, self::CLASS_NAME_SHORT . '_Setting_does_not_exist');

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingArgsNonExistentSettingShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithArguments(self::TEST_SECTION_1_NAME, self::CLASS_NAME_SHORT . '_Setting_does_not_exist');

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingOptsArrayWithInvalidValShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithOptions(self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_1_NAME, self::CLASS_NAME_SHORT . '_Array_key_does_not_exist');

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    public function testUsingArgsArrayWithInvalidValShouldYieldEmpty()
    {

        // Pass empty section name.
        $resultObj = $this->runCommandWithArguments(self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_1_NAME, self::CLASS_NAME_SHORT . '_Array_key_does_not_exist');

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $expectedValue = self::MSG_NOTHING_FOUND;
        $this->assertEquals($expectedValue, $resultObj->output);
    }

    //
    //*************************************************************************
    // Tests for existing data.
    //*************************************************************************
    //

    /**
     * @dataProvider getSingleSettingDataProvider1
     */
    public function testUsingOptsDeleteSingleSetting($sectionName, $settingName, $settingValue)
    {

        $resultObj = $this->runCommandWithOptions($sectionName, $settingName);

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $this->assertStringContainsString('Success:', $resultObj->output);

        $config = $this->makeNewConfig();
        $configDump = $config->dumpConfig();
        $needle = $settingName . ' = ' . $settingValue;
        $this->assertStringNotContainsString($needle, $configDump);
    }

    /**
     * @dataProvider getSingleSettingDataProvider2
     */
    public function testUsingArgsDeleteSingleSetting($sectionName, $settingName, $settingValue)
    {

        $resultObj = $this->runCommandWithArguments($sectionName, $settingName);

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $this->assertStringContainsString('Success:', $resultObj->output);

        $config = $this->makeNewConfig();
        $configDump = $config->dumpConfig();
        $needle = $settingName . ' = ' . $settingValue;
        $this->assertStringNotContainsString($needle, $configDump);
    }

    /**
     * @dataProvider getArraySettingDataProvider1
     */
    public function testUsingOptsDeleteArraySetting($sectionName, $settingName, $settingValue)
    {

        $resultObj = $this->runCommandWithOptions($sectionName, $settingName, $settingValue);

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $this->assertStringContainsString('Success:', $resultObj->output);

        $config = $this->makeNewConfig();
        $configDump = $config->dumpConfig();
        $needle = $settingName . ' = ' . $settingValue;
        $this->assertStringNotContainsString($needle, $configDump);
    }

    /**
     * @dataProvider getArraySettingDataProvider2
     */
    public function testUsingArgsDeleteArraySetting($sectionName, $settingName, $settingValue)
    {

        $resultObj = $this->runCommandWithArguments($sectionName, $settingName, $settingValue);

        // The CLI error code should be 0 indicating success.
        $this->assertEquals(0, $resultObj->exitCode, $this->getCommandDisplayOutputErrorMessage());

        $this->assertStringContainsString('Success:', $resultObj->output);

        $config = $this->makeNewConfig();
        $configDump = $config->dumpConfig();
        $needle = $settingName . ' = ' . $settingValue;
        $this->assertStringNotContainsString($needle, $configDump);
    }

    public function getSingleSettingDataProvider1()
    {
        yield 'Section 1, Setting 1.1'                                  => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_1_NAME, self::TEST_SETTING_1_1_VALUE];
        yield 'Section 1, Setting 1.2'                                  => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_2_NAME, self::TEST_SETTING_1_2_VALUE];
        yield 'Section 1, Setting 1.3 - IPv4 address with port'         => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_3_NAME, self::TEST_SETTING_1_3_VALUE];
        yield 'Section 1, Setting 1.4 - IPv6 address with port'         => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_4_NAME, self::TEST_SETTING_1_4_VALUE];
    }

    public function getSingleSettingDataProvider2()
    {
        yield 'Section 1, Setting 1.5 - IPv4 subnet'                    => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_5_NAME, self::TEST_SETTING_1_5_VALUE];
        yield 'Section 1, Setting 1.6 - IPv6 subnet'                    => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_6_NAME, self::TEST_SETTING_1_6_VALUE];
        yield 'Section 1, Setting 1.7 - mail address with extension'    => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_7_NAME, self::TEST_SETTING_1_7_VALUE];
        yield 'Section 1, Setting 1.8 - comma separated list'           => [self::TEST_SECTION_1_NAME, self::TEST_SETTING_1_8_NAME, self::TEST_SETTING_1_8_VALUE];
    }

    public function getArraySettingDataProvider1()
    {
        yield 'Section 2, Setting 2.1'                                  => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_1_NAME, self::TEST_SETTING_2_1_VALUE_0];
        yield 'Section 2, Setting 2.2 - IPv4 address with port'         => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_2_NAME, self::TEST_SETTING_2_2_VALUE_0];
        yield 'Section 2, Setting 2.3 - IPv6 address with port'         => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_3_NAME, self::TEST_SETTING_2_3_VALUE_0];
        yield 'Section 2, Setting 2.4 - IPv4 subnet'                    => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_4_NAME, self::TEST_SETTING_2_4_VALUE_0];
        yield 'Section 2, Setting 2.5 - IPv6 subnet'                    => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_5_NAME, self::TEST_SETTING_2_5_VALUE_0];
        yield 'Section 2, Setting 2.6 - mail address with extension'    => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_6_NAME, self::TEST_SETTING_2_6_VALUE_0];
        yield 'Section 2, Setting 2.7 - comma separated list'           => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_7_NAME, self::TEST_SETTING_2_7_VALUE_0];
    }

    public function getArraySettingDataProvider2()
    {
        yield 'Section 2, Setting 2.1'                                  => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_1_NAME, self::TEST_SETTING_2_1_VALUE_1];
        yield 'Section 2, Setting 2.2 - IPv4 address with port'         => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_2_NAME, self::TEST_SETTING_2_2_VALUE_1];
        yield 'Section 2, Setting 2.3 - IPv6 address with port'         => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_3_NAME, self::TEST_SETTING_2_3_VALUE_1];
        yield 'Section 2, Setting 2.4 - IPv4 subnet'                    => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_4_NAME, self::TEST_SETTING_2_4_VALUE_1];
        yield 'Section 2, Setting 2.5 - IPv6 subnet'                    => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_5_NAME, self::TEST_SETTING_2_5_VALUE_1];
        yield 'Section 2, Setting 2.6 - mail address with extension'    => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_6_NAME, self::TEST_SETTING_2_6_VALUE_1];
        yield 'Section 2, Setting 2.7 - comma separated list'           => [self::TEST_SECTION_2_NAME, self::TEST_SETTING_2_7_NAME, self::TEST_SETTING_2_7_VALUE_1];
    }
}