[TASK] Introduce caching for record titles
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Utility / BackendUtilityTest.php
index 0b69664..5836c9c 100644 (file)
@@ -1022,6 +1022,27 @@ class BackendUtilityTest extends UnitTestCase {
                $this->assertSame($expected, $subject->_call('replaceL10nModeFields', $table, $row));
        }
 
+       /**
+        * @test
+        */
+       public function getRecordTitleHavingLabelUserFuncCachesValue() {
+               $table = 'tx_mytable';
+               $row = ['uid' => 1];
+
+               $mock = $this->getMock('stdClass', ['labelUserFunc']);
+               $mock->expects($this->once())->method('labelUserFunc')->willReturn('Test');
+
+               // Use wrapping closure for GeneralUtility::callUserFunction()
+               $GLOBALS['TCA'][$table]['ctrl']['label_userFunc'] = function(&$parameters) use ($mock) {
+                       $parameters['title'] = $mock->labelUserFunc();
+               };
+
+               $this->assertEquals('Test', BackendUtility::getRecordTitle($table, $row));
+
+               // Call a second time to make sure labelUserFunc is not called again ($this->once())
+               $this->assertEquals('Test', BackendUtility::getRecordTitle($table, $row));
+       }
+
        /**
         * @test
         */