Skip to content

Commit 70fb0c3

Browse files
daunjasonvarga
andauthored
[6.x] Add explicit package param to installed tag (#14858)
Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent 167987f commit 70fb0c3

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Tags/Installed.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,32 @@
66

77
class Installed extends Tags
88
{
9+
/**
10+
* Check if composer package is installed via {{ installed package="vendor/package" }}.
11+
*
12+
* @return string|void
13+
*/
14+
public function index()
15+
{
16+
if (! $package = $this->params->get('package')) {
17+
return;
18+
}
19+
20+
return $this->installed($package);
21+
}
22+
923
/**
1024
* Check if composer package is installed via {{ installed:* }}.
1125
*
1226
* @param string $package
1327
* @return string|void
1428
*/
1529
public function wildcard($package)
30+
{
31+
return $this->installed($package);
32+
}
33+
34+
protected function installed($package)
1635
{
1736
$installed = Composer::isInstalled($package);
1837

tests/Tags/InstalledTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ public function it_can_check_if_package_is_installed_using_tag_pair()
3434
$this->assertEquals('yes', $this->tag('{{ installed:hasselhoff/baywatch-embeds }}yes{{ /installed:hasselhoff/baywatch-embeds }}'));
3535
$this->assertEquals('', $this->tag('{{ installed:hasselhoff/lotr-embeds }}yes{{ /installed:hasselhoff/lotr-embeds }}'));
3636
}
37+
38+
#[Test]
39+
public function it_can_check_if_package_is_installed_using_param()
40+
{
41+
$this->assertEquals('yes', $this->tag('{{ installed package="hasselhoff/baywatch-embeds" }}yes{{ /installed }}'));
42+
$this->assertEquals('', $this->tag('{{ installed package="hasselhoff/lotr-embeds" }}yes{{ /installed }}'));
43+
}
44+
45+
#[Test]
46+
public function it_outputs_empty_when_passing_nothing()
47+
{
48+
$this->assertEquals('', $this->tag('{{ installed package="" }}yes{{ /installed }}'));
49+
$this->assertEquals('', $this->tag('{{ installed :package="null" }}yes{{ /installed }}'));
50+
}
3751
}

0 commit comments

Comments
 (0)