From 83f543d5d113443e8971a0c2574de0a0220c3617 Mon Sep 17 00:00:00 2001 From: Robert Lange Date: Fri, 18 Oct 2024 16:36:47 +0200 Subject: [PATCH] refs vufind-org#2999 add testGetCheckboxWithoutIdAndWithEmptyPrefix --- .../View/Helper/Root/RecordTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php index f5423e605e3..5ea2b8d5bf9 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php @@ -432,6 +432,56 @@ public function testGetCheckbox(): void $this->assertEquals('success', $record->getCheckbox('bar', 'foo', 2)); } + /** + * Test getCheckboxWithoutIdAndWithoutPrefix. + * + * @return void + */ + public function testGetCheckboxWithoutIdAndWithEmptyPrefix(): void + { + $driver = $this->loadRecordFixture('testbug1.json'); + $tpl = 'record/checkbox.phtml'; + $context = $this->getMockContext(); + + $expectedCalls = [ + [ + $tpl, + [ + 'number' => 1, + 'id' => 'Solr|000105196', + 'checkboxElementId' => '000105196', + 'prefix' => '', + 'formAttr' => 'foo', + ], + ], + [ + $tpl, + [ + 'number' => 2, + 'id' => 'Solr|000105196', + 'checkboxElementId' => '000105196', + 'prefix' => '', + 'formAttr' => 'foo', + ], + ], + ]; + + $record = $this->getRecord($driver, [], $context); + + $this->expectConsecutiveCalls( + $context, + 'renderInContext', + $expectedCalls, + ['success', 'success'] + ); + + $record = $this->getRecord($driver, [], $context); + + // We run the test twice to ensure that checkbox incrementing works properly: + $this->assertEquals('success', $record->getCheckbox(formAttr: 'foo', number: 1)); + $this->assertEquals('success', $record->getCheckbox('', 'foo', 2)); + } + /** * Test getUniqueHtmlElementId. *