From 163e985560a43c6bbacb5f8812b75b0fa0a32518 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 31 Jul 2024 16:44:49 -0400 Subject: [PATCH] move to dedicated test --- tests/Antlers/Runtime/CoreModifiersTest.php | 21 ---------- tests/Modifiers/WhereInTest.php | 44 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 tests/Modifiers/WhereInTest.php diff --git a/tests/Antlers/Runtime/CoreModifiersTest.php b/tests/Antlers/Runtime/CoreModifiersTest.php index 014c48ae37..03fc062a60 100644 --- a/tests/Antlers/Runtime/CoreModifiersTest.php +++ b/tests/Antlers/Runtime/CoreModifiersTest.php @@ -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 }}')); diff --git a/tests/Modifiers/WhereInTest.php b/tests/Modifiers/WhereInTest.php new file mode 100644 index 0000000000..c5ff317b60 --- /dev/null +++ b/tests/Modifiers/WhereInTest.php @@ -0,0 +1,44 @@ + '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(); + } +}