function ExtensionListCommandTest::testExtensionList

Tests the 'ex:list' command.

File

core/modules/system/tests/src/Kernel/Command/ExtensionListCommandTest.php, line 35

Class

ExtensionListCommandTest
Tests the 'ex:list' command.

Namespace

Drupal\Tests\system\Kernel\Command

Code

public function testExtensionList() : void {
  $tester = $this->applicationTester();
  // Detailed testing using json output format.
  $cmd = [
    'command' => 'ex:list',
    '--format' => 'json',
  ];
  $this->assertEquals(Command::SUCCESS, $tester->run($cmd));
  $json = json_decode($tester->getDisplay());
  $this->assertSame('Field types', $json->datetime->package);
  $this->assertSame('Datetime (datetime)', $json->datetime->display_name);
  $this->assertSame('Uninstalled', $json->datetime->status);
  $this->assertSame(\Drupal::VERSION, $json->datetime->version);
  $this->assertSame('Installed', $json->system->status);
  // Exercise the filtering options.
  $cmd = [
    'command' => 'ex:list',
    '--format' => 'json',
    '--type' => 'module',
    '--installed' => TRUE,
  ];
  $this->assertEquals(Command::SUCCESS, $tester->run($cmd));
  $json = json_decode($tester->getDisplay());
  $this->assertObjectHasProperty('system', $json);
  $this->assertObjectNotHasProperty('datetime', $json);
  $cmd = [
    'command' => 'ex:list',
    '--format' => 'json',
    '--no-core' => TRUE,
  ];
  $this->assertEquals(Command::SUCCESS, $tester->run($cmd));
  $json = json_decode($tester->getDisplay());
  $this->assertObjectNotHasProperty('system', $json);
  $cmd = [
    'command' => 'ex:list',
    '--format' => 'json',
    '--type' => 'theme',
  ];
  $this->assertEquals(Command::SUCCESS, $tester->run($cmd));
  $json = json_decode($tester->getDisplay());
  $this->assertObjectNotHasProperty('system', $json);
  // Sanity check the human readable output.
  $this->assertEquals(Command::SUCCESS, $tester->run([
    'command' => 'ex:list',
  ]));
  $display = $tester->getDisplay();
  $this->assertStringContainsString('Package', $display);
  $this->assertStringContainsString('Version', $display);
  $this->assertStringContainsString('User', $display);
  $this->assertStringContainsString('Installed', $display);
  $this->assertStringContainsString('Uninstalled', $display);
  $this->assertStringContainsString(\Drupal::VERSION, $display);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.