Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
phpbb_console_user_delete_test
100.00% covered (success)
100.00%
37 / 37
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 get_command_tester
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 test_delete
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 test_delete_non_user
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 test_delete_cancel
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14use Symfony\Component\Console\Application;
15use Symfony\Component\Console\Tester\CommandTester;
16use phpbb\console\command\user\delete;
17
18require_once __DIR__ . '/base.php';
19
20class phpbb_console_user_delete_test extends phpbb_console_user_base
21{
22    public function get_command_tester()
23    {
24        $application = new Application();
25        $application->add(new delete(
26            $this->user,
27            $this->language,
28            $this->log,
29            $this->user_loader,
30            $this->phpbb_root_path,
31            $this->php_ext
32        ));
33
34        $command = $application->find('user:delete');
35        $this->question = $command->getHelper('question');
36
37        return new CommandTester($command);
38    }
39
40    public function test_delete()
41    {
42        $command_tester = $this->get_command_tester();
43
44        $this->assertEquals(3, $this->get_user_id('Test'));
45
46        $command_tester->setInputs(['yes', '']);
47
48        $command_tester->execute(array(
49            'username'            => 'Test',
50            '--delete-posts'    => false,
51        ));
52
53        $this->assertNull($this->get_user_id('Test'));
54        $this->assertStringContainsString('USER_DELETED', $command_tester->getDisplay());
55    }
56
57    public function test_delete_non_user()
58    {
59        $command_tester = $this->get_command_tester();
60
61        $this->assertNull($this->get_user_id('Foo'));
62
63        $command_tester->setInputs(['yes', '']);
64
65        $command_tester->execute(array(
66            'username'            => 'Foo',
67            '--delete-posts'    => false,
68        ));
69
70        $this->assertStringContainsString('NO_USER', $command_tester->getDisplay());
71    }
72
73    public function test_delete_cancel()
74    {
75        $command_tester = $this->get_command_tester();
76
77        $this->assertEquals(3, $this->get_user_id('Test'));
78
79        $command_tester->setInputs(['no', '']);
80
81        $command_tester->execute(array(
82            'username'            => 'Test',
83            '--delete-posts'    => false,
84        ));
85
86        $this->assertNotNull($this->get_user_id('Test'));
87    }
88}