diff --git a/src/Tags/Installed.php b/src/Tags/Installed.php index 242898c1b3f..8c403214a4d 100644 --- a/src/Tags/Installed.php +++ b/src/Tags/Installed.php @@ -6,6 +6,20 @@ class Installed extends Tags { + /** + * Check if composer package is installed via {{ installed package="vendor/package" }}. + * + * @return string|void + */ + public function index() + { + if (! $package = $this->params->get('package')) { + return; + } + + return $this->installed($package); + } + /** * Check if composer package is installed via {{ installed:* }}. * @@ -13,6 +27,11 @@ class Installed extends Tags * @return string|void */ public function wildcard($package) + { + return $this->installed($package); + } + + protected function installed($package) { $installed = Composer::isInstalled($package); diff --git a/tests/Tags/InstalledTest.php b/tests/Tags/InstalledTest.php index 481d653cda9..a7694810c40 100644 --- a/tests/Tags/InstalledTest.php +++ b/tests/Tags/InstalledTest.php @@ -34,4 +34,18 @@ public function it_can_check_if_package_is_installed_using_tag_pair() $this->assertEquals('yes', $this->tag('{{ installed:hasselhoff/baywatch-embeds }}yes{{ /installed:hasselhoff/baywatch-embeds }}')); $this->assertEquals('', $this->tag('{{ installed:hasselhoff/lotr-embeds }}yes{{ /installed:hasselhoff/lotr-embeds }}')); } + + #[Test] + public function it_can_check_if_package_is_installed_using_param() + { + $this->assertEquals('yes', $this->tag('{{ installed package="hasselhoff/baywatch-embeds" }}yes{{ /installed }}')); + $this->assertEquals('', $this->tag('{{ installed package="hasselhoff/lotr-embeds" }}yes{{ /installed }}')); + } + + #[Test] + public function it_outputs_empty_when_passing_nothing() + { + $this->assertEquals('', $this->tag('{{ installed package="" }}yes{{ /installed }}')); + $this->assertEquals('', $this->tag('{{ installed :package="null" }}yes{{ /installed }}')); + } }