From 01ef12c05d862044a7b47c54103069d6d57f72b0 Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 9 Apr 2019 13:17:56 +0200 Subject: [PATCH] Additional section tests --- tests/Cms/Sections/SectionTest.php | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/Cms/Sections/SectionTest.php b/tests/Cms/Sections/SectionTest.php index 197ea35e2c..4f0ac4fc03 100644 --- a/tests/Cms/Sections/SectionTest.php +++ b/tests/Cms/Sections/SectionTest.php @@ -18,6 +18,18 @@ public function setUp(): void ]); } + public function testMissingModel() + { + Section::$types = [ + 'test' => [] + ]; + + $this->expectException('Kirby\Exception\InvalidArgumentException'); + $this->expectExceptionMessage('Undefined section model'); + + $section = new Section('test', []); + } + public function testPropsDefaults() { Section::$types = [ @@ -40,4 +52,38 @@ public function testPropsDefaults() $this->assertEquals('default', $section->example()); $this->assertEquals(['one', 'two'], $section->buttons()); } + + public function testToResponse() + { + Section::$types = [ + 'test' => [ + 'props' => [ + 'a' => function ($a) { + return $a; + }, + 'a' => function ($b) { + return $b; + }, + ] + ] + ]; + + $section = new Section('test', [ + 'model' => new Page(['slug' => 'test']), + 'a' => 'A', + 'b' => 'B' + ]); + + + $expected = [ + 'status' => 'ok', + 'code' => 200, + 'name' => 'test', + 'type' => 'test', + 'a' => 'A', + 'b' => 'B' + ]; + + $this->assertEquals($expected, $section->toResponse()); + } }