Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
75.00% covered (warning)
75.00%
24 / 32
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
phpbb_console_user_activate_test
75.00% covered (warning)
75.00%
24 / 32
75.00% covered (warning)
75.00%
3 / 4
4.25
0.00% covered (danger)
0.00%
0 / 1
 setUp
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 get_command_tester
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
1
 activate_test_data
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 test_activate
100.00% covered (success)
100.00%
6 / 6
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\activate;
17
18require_once __DIR__ . '/base.php';
19
20class phpbb_console_user_activate_test extends phpbb_console_user_base
21{
22    protected $notifications;
23
24    protected function setUp(): void
25    {
26        parent::setUp();
27
28        $this->notifications = $this->getMockBuilder('\phpbb\notification\manager')
29            ->disableOriginalConstructor()
30            ->getMock();
31    }
32
33    public function get_command_tester()
34    {
35        $application = new Application();
36        $application->add(new activate(
37            $this->user,
38            $this->config,
39            $this->language,
40            $this->log,
41            $this->email,
42            $this->notifications,
43            $this->user_loader,
44            $this->phpbb_root_path,
45            $this->php_ext
46        ));
47
48        $command = $application->find('user:activate');
49
50        return new CommandTester($command);
51    }
52
53    public static function activate_test_data()
54    {
55        return array(
56            // Test an inactive user
57            array('Test', false, 'USER_ADMIN_ACTIVATED'),
58            array('Test', true, 'CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE'),
59
60            // Test an active user
61            array('Test 2', false, 'CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE'),
62            array('Test 2', true, 'USER_ADMIN_DEACTIVED'),
63
64            // Test a non existent user
65            array('Foo', false, 'NO_USER'),
66            array('Foo', true, 'NO_USER'),
67        );
68    }
69
70    /**
71     * @dataProvider activate_test_data
72     */
73    public function test_activate($username, $deactivate, $expected)
74    {
75        $command_tester = $this->get_command_tester();
76
77        $command_tester->execute(array(
78            'username'        => $username,
79            '--deactivate'    => $deactivate,
80        ));
81
82        $this->assertStringContainsString($expected, $command_tester->getDisplay());
83    }
84}