Skip to content

Commit

Permalink
move to dedicated test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Jul 31, 2024
1 parent e207d98 commit 163e985
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
21 changes: 0 additions & 21 deletions tests/Antlers/Runtime/CoreModifiersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,27 +238,6 @@ public function test_where()
$this->assertSame('DominionNetrunner', $this->resultOf($template));
}

public function test_where_in()
{
$template = <<<'EOT'
{{ complex | where_in("last_name", ["Zebra", "Bravo"]) }}{{ first_name }}{{ /complex }}
EOT;

$this->assertSame('ZealousBlathering', $this->resultOf($template));

$template = <<<'EOT'
{{ complex where_in="{"last_name"}|{["Zebra", "Bravo"]}" }}{{ first_name }}{{ /complex }}
EOT;

$this->assertSame('ZealousBlathering', $this->resultOf($template));

$template = <<<'EOT'
{{ complex | where_in("last_name", "Zebra") }}{{ first_name }}{{ /complex }}
EOT;

$this->assertSame('Zealous', $this->resultOf($template));
}

public function test_unique()
{
$this->assertSame('zebra, hippo, hyena, giraffe', $this->resultOf('{{ checklist | unique | list }}'));
Expand Down
44 changes: 44 additions & 0 deletions tests/Modifiers/WhereInTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Modifiers;

use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Modifiers\Modify;
use Statamic\Support\Arr;
use Tests\TestCase;

#[Group('array')]
class WhereInTest extends TestCase
{
#[Test]
public function it_filters_data_by_key_and_multiple_values(): void
{
$collection = [
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
['product' => 'Bookcase', 'price' => 150],
['product' => 'Door', 'price' => 100],
];
$modified = $this->modify($collection, ['price', [150, 200]]);
$this->assertEquals(['Desk', 'Bookcase'], Arr::pluck($modified, 'product'));
}

#[Test]
public function it_filters_data_by_key_and_single_value(): void
{
$collection = [
['product' => 'Desk', 'price' => 200],
['product' => 'Chair', 'price' => 100],
['product' => 'Bookcase', 'price' => 150],
['product' => 'Door', 'price' => 100],
];
$modified = $this->modify($collection, ['price', 100]);
$this->assertEquals(['Chair', 'Door'], Arr::pluck($modified, 'product'));
}

private function modify($value, array $params)
{
return Modify::value($value)->whereIn($params)->fetch();
}
}

0 comments on commit 163e985

Please sign in to comment.