2019-01-27 06:28:57 -05:00
< ? php
2020-04-09 05:50:14 -04:00
2019-01-27 08:47:19 -05:00
declare ( strict_types = 1 );
2019-01-27 06:28:57 -05:00
/**
2024-05-10 09:09:14 -04:00
* SPDX - FileCopyrightText : 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2019-01-27 06:28:57 -05:00
*/
namespace Tests\Core\Command\Config ;
use OC\Core\Command\App\Enable ;
2025-02-10 05:25:50 -05:00
use OC\Installer ;
2025-06-12 12:31:58 -04:00
use OCP\App\IAppManager ;
use OCP\IGroupManager ;
use OCP\Server ;
2019-01-27 06:28:57 -05:00
use Symfony\Component\Console\Tester\CommandTester ;
use Test\TestCase ;
/**
* Class AppsEnableTest
*/
2025-10-20 19:52:40 -04:00
#[\PHPUnit\Framework\Attributes\Group('DB')]
2019-01-27 06:28:57 -05:00
class AppsEnableTest extends TestCase {
/** @var CommandTester */
private $commandTester ;
2019-11-27 09:27:18 -05:00
protected function setUp () : void {
2019-01-27 06:28:57 -05:00
parent :: setUp ();
$command = new Enable (
2025-06-12 12:31:58 -04:00
Server :: get ( IAppManager :: class ),
Server :: get ( IGroupManager :: class ),
Server :: get ( Installer :: class ),
2019-01-27 06:28:57 -05:00
);
$this -> commandTester = new CommandTester ( $command );
2019-01-27 08:47:19 -05:00
2025-06-12 12:31:58 -04:00
Server :: get ( IAppManager :: class ) -> disableApp ( 'admin_audit' );
Server :: get ( IAppManager :: class ) -> disableApp ( 'comments' );
2019-01-27 06:28:57 -05:00
}
/**
* @ param $appId
* @ param $groups
* @ param $statusCode
2021-10-01 16:30:02 -04:00
* @ param $pattern
2019-01-27 06:28:57 -05:00
*/
2025-06-30 10:56:59 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('dataCommandInput')]
2021-10-01 16:30:02 -04:00
public function testCommandInput ( $appId , $groups , $statusCode , $pattern ) : void {
2019-01-27 06:28:57 -05:00
$input = [ 'app-id' => $appId ];
if ( is_array ( $groups )) {
$input [ '--groups' ] = $groups ;
}
$this -> commandTester -> execute ( $input );
2022-05-24 07:26:58 -04:00
$this -> assertMatchesRegularExpression ( '/' . $pattern . '/' , $this -> commandTester -> getDisplay ());
2019-01-27 06:28:57 -05:00
$this -> assertSame ( $statusCode , $this -> commandTester -> getStatusCode ());
}
2025-05-02 08:00:10 -04:00
public static function dataCommandInput () : array {
2021-06-25 05:18:30 -04:00
return [
2021-10-01 16:30:02 -04:00
[[ 'admin_audit' ], null , 0 , 'admin_audit ([\d\.]*) enabled' ],
[[ 'comments' ], null , 0 , 'comments ([\d\.]*) enabled' ],
[[ 'comments' , 'comments' ], null , 0 , " comments ([ \ d \ .]*) enabled \n comments already enabled " ],
2019-01-27 15:53:09 -05:00
[[ 'invalid_app' ], null , 1 , 'Could not download app invalid_app' ],
2019-01-27 06:28:57 -05:00
2021-10-01 16:30:02 -04:00
[[ 'admin_audit' , 'comments' ], null , 0 , " admin_audit ([ \ d \ .]*) enabled \n comments ([ \ d \ .]*) enabled " ],
[[ 'admin_audit' , 'comments' , 'invalid_app' ], null , 1 , " admin_audit ([ \ d \ .]*) enabled \n comments ([ \ d \ .]*) enabled \n Could not download app invalid_app " ],
2019-01-27 06:28:57 -05:00
[[ 'admin_audit' ], [ 'admin' ], 1 , " admin_audit can't be enabled for groups " ],
[[ 'comments' ], [ 'admin' ], 1 , " comments can't be enabled for groups " ],
2021-10-01 16:30:02 -04:00
[[ 'updatenotification' ], [ 'admin' ], 0 , 'updatenotification ([\d\.]*) enabled for groups: admin' ],
2022-04-20 08:21:42 -04:00
[[ 'updatenotification' , 'dashboard' ], [ 'admin' ], 0 , " updatenotification ([ \ d \ .]*) enabled for groups: admin \n dashboard ([ \ d \ .]*) enabled for groups: admin " ],
2019-01-27 06:28:57 -05:00
2021-10-01 16:30:02 -04:00
[[ 'updatenotification' ], [ 'admin' , 'invalid_group' ], 0 , 'updatenotification ([\d\.]*) enabled for groups: admin' ],
2022-04-20 08:21:42 -04:00
[[ 'updatenotification' , 'dashboard' ], [ 'admin' , 'invalid_group' ], 0 , " updatenotification ([ \ d \ .]*) enabled for groups: admin \n dashboard ([ \ d \ .]*) enabled for groups: admin " ],
[[ 'updatenotification' , 'dashboard' , 'invalid_app' ], [ 'admin' , 'invalid_group' ], 1 , " updatenotification ([ \ d \ .]*) enabled for groups: admin \n dashboard ([ \ d \ .]*) enabled for groups: admin \n Could not download app invalid_app " ],
2019-01-27 06:28:57 -05:00
];
}
}