From 4549822cdd5b5e593357b724170de3402963abb8 Mon Sep 17 00:00:00 2001
From: Simon Wisselink
Date: Fri, 19 Apr 2024 11:10:01 +0200
Subject: [PATCH] fixed sample output of section in the docs and added this
example as a unit test
---
.../language-function-section.md | 8 ++---
.../TagTests/Section/CompileSectionTest.php | 33 +++++++++++++++++++
2 files changed, 37 insertions(+), 4 deletions(-)
diff --git a/docs/designers/language-builtin-functions/language-function-section.md b/docs/designers/language-builtin-functions/language-function-section.md
index ba17224c..42790251 100644
--- a/docs/designers/language-builtin-functions/language-function-section.md
+++ b/docs/designers/language-builtin-functions/language-function-section.md
@@ -178,14 +178,14 @@ The above example will output:
name: Jack Jones
- home phone: 777-555-5555
- cell phone: 888-555-5555
+ home: 777-555-5555
+ cell: 888-555-5555
e-mail: jack@myexample.com
name: Jane Munson
- home phone: 000-555-5555
- cell phone: 123456
+ home: 000-555-5555
+ cell: 123456
e-mail: jane@myexample.com
```
diff --git a/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php b/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php
index bb196012..4e05867a 100644
--- a/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php
+++ b/tests/UnitTests/TemplateSource/TagTests/Section/CompileSectionTest.php
@@ -148,4 +148,37 @@ class CompileSectionTest extends PHPUnit_Smarty
);
}
+ public function testNestedArrayAsLoopParameter()
+ {
+ $data = [
+ ['name' => 'John Smith', 'home' => '555-555-5555',
+ 'cell' => '666-555-5555', 'email' => 'john@myexample.com'],
+ ['name' => 'Jack Jones', 'home' => '777-555-5555',
+ 'cell' => '888-555-5555', 'email' => 'jack@myexample.com'],
+ ['name' => 'Jane Munson', 'home' => '000-555-5555',
+ 'cell' => '123456', 'email' => 'jane@myexample.com']
+ ];
+ $this->smarty->assign('contacts',$data);
+ $result = $this->smarty->fetch('string:{section name=customer loop=$contacts}
+name: {$contacts[customer].name}
+home: {$contacts[customer].home}
+cell: {$contacts[customer].cell}
+e-mail: {$contacts[customer].email}
+{/section}');
+ $this->assertEquals('name: John Smith
+home: 555-555-5555
+cell: 666-555-5555
+e-mail: john@myexample.com
+name: Jack Jones
+home: 777-555-5555
+cell: 888-555-5555
+e-mail: jack@myexample.com
+name: Jane Munson
+home: 000-555-5555
+cell: 123456
+e-mail: jane@myexample.com
+', $result);
+
+ }
+
}