Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Nov 27, 2024
1 parent 9db1705 commit b6c73ce
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/Tags/IterateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Tests\Tags;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Parse;
use Statamic\Fields\Value;
use Statamic\Fields\Values;
use Tests\TestCase;

class IterateTest extends TestCase
{
#[Test]
#[DataProvider('iterateProvider')]
public function it_iterates($value)
{
$template = '{{ foreach:fieldname }}<{{ key }},{{ value }}>{{ /foreach:fieldname }}';

$this->assertSame('<alfa,one><bravo,two>', $this->tag($template, ['fieldname' => $value]));
}

public static function iterateProvider()
{
return [
'array' => [
['alfa' => 'one', 'bravo' => 'two'],
],
'collection' => [
collect(['alfa' => 'one', 'bravo' => 'two']),
],
'values' => [
new Values(['alfa' => 'one', 'bravo' => 'two']),
],
'value with array' => [
new Value(['alfa' => 'one', 'bravo' => 'two']),
],
'value with collection' => [
new Value(collect(['alfa' => 'one', 'bravo' => 'two'])),
],
'value with values' => [
new Value(new Values(['alfa' => 'one', 'bravo' => 'two'])),
],
];
}

private function tag($tag, $context = [])
{
return (string) Parse::template($tag, $context);
}
}

0 comments on commit b6c73ce

Please sign in to comment.