Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[FEATURE] LLL file kickstarting and XLF support #286

Merged
merged 10 commits into from 9 months ago

3 participants

Claus Due Danilo Bürger Björn Fromme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
5 Classes/Backend/TableConfigurationPostProcessor.php
@@ -70,6 +70,9 @@ public function processData() {
70 70 if (NULL === $form) {
71 71 $form = $this->generateFormInstanceFromClassName($modelClassName, $fullTableName);
72 72 }
  73 + if (NULL === $form->getName()) {
  74 + $form->setName($fullTableName);
  75 + }
73 76 $this->processFormForTable($fullTableName, $form);
74 77 }
75 78 }
@@ -105,9 +108,9 @@ protected function processFormForTable($table, Tx_Flux_Form $form) {
105 108 }
106 109 $tableConfiguration['iconfile'] = t3lib_extMgm::extRelPath($extensionKey) . $form->getIcon();
107 110 $tableConfiguration['enablecolumns'] = $enableColumns;
  111 + $tableConfiguration['title'] = $form->getLabel();
108 112 $showRecordsFieldList = implode(',', array_keys($fields));
109 113 $GLOBALS['TCA'][$table] = array(
110   - 'title' => $form->getLabel(),
111 114 'ctrl' => $tableConfiguration,
112 115 'interface' => array(
113 116 'showRecordFieldList' => $showRecordsFieldList
6 Classes/Core.php
@@ -98,6 +98,9 @@ public static function registerFormForTable($table, Tx_Flux_Form $form) {
98 98 if (NULL === $form->getName()) {
99 99 $form->setName($table);
100 100 }
  101 + if (NULL === $form->getExtensionName() && TRUE === isset($GLOBALS['_EXTKEY'])) {
  102 + $form->setExtensionName(t3lib_div::underscoredToUpperCamelCase($GLOBALS['_EXTKEY']));
  103 + }
101 104 self::$forms['tables'][$table] = $form;
102 105 }
103 106
@@ -119,6 +122,9 @@ public static function registerAutoFormForModelObjectClassName($className) {
119 122 * @return void
120 123 */
121 124 public static function registerFormForModelObjectClassName($className, Tx_Flux_Form $form = NULL) {
  125 + if (NULL !== $form && TRUE === isset($GLOBALS['_EXTKEY']) && NULL === $form->getExtensionName()) {
  126 + $form->setExtensionName(t3lib_div::underscoredToUpperCamelCase($GLOBALS['_EXTKEY']));
  127 + }
122 128 self::$forms['models'][$className] = $form;
123 129 }
124 130
4 Classes/Form.php
@@ -74,7 +74,7 @@ class Tx_Flux_Form extends Tx_Flux_Form_AbstractFormContainer implements Tx_Flux
74 74 *
75 75 * @var string
76 76 */
77   - protected $extensionName = 'Flux';
  77 + protected $extensionName;
78 78
79 79 /**
80 80 * If TRUE, removes sheet wrappers if there is only a single sheet.
@@ -292,7 +292,7 @@ public function getIcon() {
292 292 * @return Tx_Flux_Form_FormInterface
293 293 */
294 294 public function setId($id) {
295   - $allowed = 'a-z';
  295 + $allowed = 'a-z0-9_';
296 296 $pattern = '/[^' . $allowed . ']+/i';
297 297 if (preg_match($pattern, $id)) {
298 298 $this->configurationService->message('Flux FlexForm with id "' . $id . '" uses invalid characters in the ID; valid characters
32 Classes/Form/AbstractFormComponent.php
@@ -211,10 +211,12 @@ public function getLabel() {
211 211 $name = $this->getName();
212 212 $root = $this->getRoot();
213 213 if (FALSE === $root instanceof Tx_Flux_Form) {
214   - return $label;
  214 + $id = 'form';
  215 + $extensionName = 'Flux';
  216 + } else {
  217 + $id = $root->getName();
  218 + $extensionName = $root->getExtensionName();
215 219 }
216   - $id = $root->getName();
217   - $extensionName = $root->getExtensionName();
218 220 $extensionKey = t3lib_div::camelCaseToLowerCaseUnderscored($extensionName);
219 221 if (TRUE === isset($label) && FALSE === empty($label)) {
220 222 return $label;
@@ -228,12 +230,14 @@ public function getLabel() {
228 230 $prefix = 'sections';
229 231 } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Container) {
230 232 $prefix = 'containers';
231   - } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Column) {
232   - $prefix = 'columns';
233   - } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Content) {
234   - $prefix = 'areas';
  233 + } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Grid) {
  234 + $prefix = 'grids';
235 235 } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Object) {
236 236 $prefix = 'objects';
  237 + } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Content) {
  238 + $prefix = 'areas';
  239 + } elseif (TRUE === $this instanceof Tx_Flux_Form_Container_Container) {
  240 + $prefix = 'containers';
237 241 } elseif (TRUE === $this instanceof Tx_Flux_Form_FieldInterface) {
238 242 if (TRUE === $this->isChildOfType('Object')) {
239 243 $prefix = 'objects.' . $this->getParent()->getName();
@@ -243,11 +247,23 @@ public function getLabel() {
243 247 }
244 248 $filePrefix = 'LLL:EXT:' . $extensionKey . $this->localLanguageFileRelativePath;
245 249 $labelIdentifier = 'flux.' . $id . (TRUE === empty($prefix) ? '' : '.' . $prefix . '.' . $name);
246   - Tx_Flux_Utility_LanguageFile::autoWriteLanguageLabel($filePrefix, $labelIdentifier, $id);
  250 + $this->writeLanguageLabel($filePrefix, $labelIdentifier, $id);
247 251 return $filePrefix . ':' . $labelIdentifier;
248 252 }
249 253
250 254 /**
  255 + * @param string $filePrefix
  256 + * @param string $labelIdentifier
  257 + * @param string $id
  258 + * @return void
  259 + */
  260 + protected function writeLanguageLabel($filePrefix, $labelIdentifier, $id) {
  261 + if (TRUE === (boolean) $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['rewriteLanguageFiles']) {
  262 + Tx_Flux_Utility_LanguageFile::writeLanguageLabel($filePrefix, $labelIdentifier, $id);
  263 + }
  264 + }
  265 +
  266 + /**
251 267 * @param string $localLanguageFileRelativePath
252 268 * @return Tx_Flux_FormInterface
253 269 */
2  Classes/Provider/AbstractProvider.php
@@ -659,7 +659,7 @@ protected function setDefaultValuesInFieldsWithInheritedValues(Tx_Flux_Form $for
659 659 foreach ($form->getFields() as $field) {
660 660 $name = $field->getName();
661 661 $inheritedValue = $this->getInheritedPropertyValueByDottedPath($row, $name);
662   - if (NULL !== $inheritedValue) {
  662 + if (NULL !== $inheritedValue && TRUE === $field instanceof Tx_Flux_Form_FieldInterface) {
663 663 $field->setDefault($inheritedValue);
664 664 }
665 665 }
294 Classes/Utility/LanguageFile.php
@@ -38,37 +38,92 @@ class Tx_Flux_Utility_LanguageFile {
38 38 protected static $service = NULL;
39 39
40 40 /**
  41 + * @var array
  42 + */
  43 + protected static $validExtensions = array('xml', 'xlf');
  44 +
  45 + /**
  46 + * @var array
  47 + */
  48 + protected static $documents = array();
  49 +
  50 + const TEMPLATE_XML = <<< XML
  51 +<T3locallang>
  52 + <meta type="array">
  53 + <type>module</type>
  54 + <description></description>
  55 + </meta>
  56 + <data type="array"></data>
  57 +</T3locallang>
  58 +XML;
  59 +
  60 + const TEMPLATE_XLF = <<< XML
  61 +<xliff version="1.0">
  62 + <file source-language="en" datatype="plaintext" original="messages" date="" product-name="">
  63 + <header/>
  64 + <body></body>
  65 + </file>
  66 +</xliff>
  67 +XML;
  68 +
  69 + /**
  70 + * @return void
  71 + */
  72 + public static function reset() {
  73 + self::$documents = array();
  74 + }
  75 +
  76 + /**
41 77 * @param string $file
42 78 * @param string $identifier
43 79 * @param string $id
44 80 */
45   - public static function autoWriteLanguageLabel($file, $identifier, $id) {
46   - if (1 > $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['rewriteLanguageFiles']) {
47   - return;
48   - }
49   - self::message('Generated automatic LLL path for entity called "' . $identifier . '" in file "' . $file . '"');
50   - $allowed = 'a-z\.';
51   - $pattern = '/[^' . $allowed . ']+/i';
52   - if (preg_match($pattern, $id) || preg_match($pattern, $identifier)) {
  81 + public static function writeLanguageLabel($file, $identifier, $id) {
  82 + $pattern = '/[^a-z0-9_]+/i';
  83 + $patternIdentifier = '/[^a-z0-9\._]+/i';
  84 + if (preg_match($pattern, $id) || preg_match($patternIdentifier, $identifier)) {
53 85 self::message('Cowardly refusing to create an invalid LLL reference called "' . $identifier . '" ' .
54   - ' in a Flux form called "' . $id . '" - one or both contains invalid characters. Allowed: dots and "' .
55   - $allowed . '".');
  86 + ' in a Flux form called "' . $id . '" - one or both contains invalid characters.');
56 87 return;
57 88 }
58 89 $file = substr($file, 4);
59 90 $filePathAndFilename = t3lib_div::getFileAbsFileName($file);
60   - $dom = new DOMDocument('1.0', 'utf-8');
61   - $dom->preserveWhiteSpace = FALSE;
62   - $dom->load($filePathAndFilename);
63   - $dom->formatOutput = TRUE;
  91 + $extension = pathinfo($filePathAndFilename, PATHINFO_EXTENSION);
  92 + if (FALSE === in_array($extension, self::$validExtensions)) {
  93 + return;
  94 + }
  95 + $buildMethodName = 'buildSourceFor' . ucfirst($extension) . 'File';
  96 + $kickstartMethodName = 'kickstart' . ucfirst($extension) . 'File';
  97 + $languages = self::getLanguageKeys();
  98 + $exists = call_user_func_array(array(self, $kickstartMethodName), array($filePathAndFilename, $languages));
  99 + if (TRUE === $exists) {
  100 + $source = call_user_func_array(array(self, $buildMethodName), array($filePathAndFilename, $identifier));
  101 + if (TRUE === $source) {
  102 + self::message('Wrote "LLL:' . $file . ':' . $identifier . '" - or label already exists');
  103 + return;
  104 + } elseif (FALSE === $source) {
  105 + self::message('Skipping LLL file saving due to an error while generating the XML.', t3lib_div::SYSLOG_SEVERITY_FATAL);
  106 + } else {
  107 + self::message('Wrote "LLL:' . $file . ':' . $identifier . '"');
  108 + file_put_contents($filePathAndFilename, $source);
  109 + }
  110 + }
  111 + }
  112 +
  113 + /**
  114 + * @param string $filePathAndFilename
  115 + * @param string $identifier
  116 + * @return string|boolean
  117 + */
  118 + public static function buildSourceForXmlFile($filePathAndFilename, $identifier) {
  119 + $filePathAndFilename = self::sanitizeFilePathAndFilename($filePathAndFilename, 'xml');
  120 + $dom = self::prepareDomDocument($filePathAndFilename);
64 121 foreach ($dom->getElementsByTagName('languageKey') as $languageNode) {
65 122 $nodes = array();
66 123 foreach ($languageNode->getElementsByTagName('label') as $labelNode) {
67 124 $key = (string) $labelNode->attributes->getNamedItem('index')->firstChild->textContent;
68 125 if ($key === $identifier) {
69   - self::message('Skipping LLL file merge for label "' . $identifier.
70   - '"; it already exists in file "' . $filePathAndFilename . '"');
71   - return;
  126 + return TRUE;
72 127 }
73 128 $nodes[$key] = $labelNode;
74 129 }
@@ -83,13 +138,203 @@ public static function autoWriteLanguageLabel($file, $identifier, $id) {
83 138 }
84 139 }
85 140 $xml = $dom->saveXML();
86   - if (FALSE === $xml) {
87   - self::message('Skipping LLL file saving due to an error while generating the XML.',
88   - t3lib_div::SYSLOG_SEVERITY_FATAL);
89   - } else {
90   - self::message('Rewrote "' . $file . '" by adding placeholder label for "' . $identifier . '"');
91   - file_put_contents($filePathAndFilename, $xml);
  141 + return $xml;
  142 + }
  143 +
  144 + /**
  145 + * @param string $filePathAndFilename
  146 + * @param array $languages
  147 + * @return boolean
  148 + */
  149 + public static function kickstartXmlFile($filePathAndFilename, $languages = array('default')) {
  150 + $filePathAndFilename = self::sanitizeFilePathAndFilename($filePathAndFilename, 'xml');
  151 + if (FALSE === file_exists($filePathAndFilename)) {
  152 + t3lib_div::writeFile($filePathAndFilename, self::TEMPLATE_XML);
  153 + }
  154 + $dom = self::prepareDomDocument($filePathAndFilename);
  155 + $dom->getElementsByTagName('description')->item(0)->nodeValue = 'Labels for languages: ' . implode(', ', $languages);
  156 + $dataNode = $dom->getElementsByTagName('data')->item(0);
  157 + if (NULL === $dataNode) {
  158 + return FALSE;
  159 + }
  160 + $missingLanguages = $languages;
  161 + if (0 < $dataNode->childNodes->length) {
  162 + $missingLanguages = $languages;
  163 + foreach ($dom->getElementsByTagName('languageKey') as $languageNode) {
  164 + $languageKey = $languageNode->getAttribute('index');
  165 + if (TRUE === in_array($languageKey, $missingLanguages)) {
  166 + unset($missingLanguages[array_search($languageKey, $missingLanguages)]);
  167 + }
  168 + }
  169 + }
  170 + foreach ($missingLanguages as $missingLanguageKey) {
  171 + self::createXmlLanguageNode($dom, $dataNode, $missingLanguageKey);
  172 + }
  173 + self::$documents[$filePathAndFilename] = $dom;
  174 + return file_exists($filePathAndFilename);
  175 + }
  176 +
  177 + /**
  178 + * @param DomDocument $dom
  179 + * @param DomNode $parent
  180 + * @param string $languageKey
  181 + * @return void
  182 + */
  183 + protected static function createXmlLanguageNode(DomDocument $dom, DomNode $parent, $languageKey) {
  184 + $languageNode = $dom->createElement('languageKey');
  185 + $indexAttribute = $dom->createAttribute('index');
  186 + $indexAttribute->nodeValue = $languageKey;
  187 + $typeAttribute = $dom->createAttribute('type');
  188 + $typeAttribute->nodeValue = 'array';
  189 + $languageNode->appendChild($indexAttribute);
  190 + $languageNode->appendChild($typeAttribute);
  191 + $parent->appendChild($languageNode);
  192 + }
  193 +
  194 + /**
  195 + * @param string $filePathAndFilename
  196 + * @param string $identifier
  197 + * @return string|NULL
  198 + */
  199 + public static function buildSourceForXlfFile($filePathAndFilename, $identifier) {
  200 + $filePathAndFilename = self::sanitizeFilePathAndFilename($filePathAndFilename, 'xlf');
  201 + $languages = self::getLanguageKeys();
  202 + foreach ($languages as $language) {
  203 + $hasIdentifier = FALSE;
  204 + $translationPathAndFilename = self::localizeXlfFilePathAndFilename($filePathAndFilename, $language);
  205 + $dom = self::prepareDomDocument($translationPathAndFilename);
  206 + $dateNode = $dom->createAttribute('date');
  207 + $dateNode->nodeValue = date('c');
  208 + $dom->getElementsByTagName('file')->item(0)->appendChild($dateNode);
  209 + $body = $dom->getElementsByTagName('body')->item(0);
  210 + foreach ($dom->getElementsByTagName('trans-unit') as $node) {
  211 + if ($node->getAttribute('id') === $identifier) {
  212 + $hasIdentifier = TRUE;
  213 + break;
  214 + }
  215 + }
  216 + if (FALSE === $hasIdentifier) {
  217 + self::createXlfLanguageNode($dom, $body, $identifier);
  218 + }
  219 + $xml = $dom->saveXML();
  220 + if (FALSE == t3lib_div::writeFile($translationPathAndFilename, $xml)) {
  221 + self::message('Unable to write to file "' . $translationPathAndFilename . '" - permission issue?', t3lib_div::SYSLOG_SEVERITY_FATAL);
  222 + }
  223 + self::$documents[$translationPathAndFilename] = $dom;
  224 + }
  225 + return TRUE;
  226 + }
  227 +
  228 + /**
  229 + * @param DomDocument $dom
  230 + * @param DomNode $parent
  231 + * @param string $identifier
  232 + * @return void
  233 + */
  234 + protected static function createXlfLanguageNode(DomDocument $dom, DomNode $parent, $identifier) {
  235 + $labelNode = $dom->createElement('trans-unit');
  236 + $idAttribute = $dom->createAttribute('id');
  237 + $idAttribute->nodeValue = $identifier;
  238 + $spaceAttribute = $dom->createAttribute('xml:space');
  239 + $spaceAttribute->nodeValue = 'preserve';
  240 + $sourceNode = $dom->createElement('source');
  241 + $sourceNode->nodeValue = $identifier;
  242 + $labelNode->appendChild($idAttribute);
  243 + $labelNode->appendChild($spaceAttribute);
  244 + $labelNode->appendChild($sourceNode);
  245 + $parent->appendChild($labelNode);
  246 + }
  247 +
  248 + /**
  249 + * @param string $filePathAndFilename
  250 + * @param array $languageOrLanguages
  251 + * @return boolean|array
  252 + */
  253 + public static function kickstartXlfFile($filePathAndFilename, $languageOrLanguages = array('default')) {
  254 + if (TRUE === is_array($languageOrLanguages)) {
  255 + $results = array();
  256 + foreach ($languageOrLanguages as $language) {
  257 + $results[$language] = self::kickstartXlfFile($filePathAndFilename, $language);
  258 + }
  259 + return $results;
  260 + }
  261 + $filePathAndFilename = self::sanitizeFilePathAndFilename($filePathAndFilename, 'xlf');
  262 + $filePathAndFilename = self::localizeXlfFilePathAndFilename($filePathAndFilename, $languageOrLanguages);
  263 + if (FALSE === file_exists($filePathAndFilename)) {
  264 + t3lib_div::writeFile($filePathAndFilename, self::TEMPLATE_XLF);
  265 + }
  266 + if (TRUE === isset(self::$documents[$filePathAndFilename])) {
  267 + return self::$documents[$filePathAndFilename];
  268 + }
  269 + $truncated = substr($filePathAndFilename, strlen(PATH_site) + 1);
  270 + $truncatedParts = explode('/', $truncated);
  271 + $dom = self::prepareDomDocument($filePathAndFilename);
  272 + $fileNode = $dom->getElementsByTagName('file')->item(0);
  273 + $productNode = $dom->createAttribute('product-name');
  274 + $productNode->nodeValue = $truncatedParts[2];
  275 + $fileNode->appendChild($productNode);
  276 + self::$documents[$filePathAndFilename] = $dom;
  277 + return file_exists($filePathAndFilename);
  278 + }
  279 +
  280 + /**
  281 + * @param string $filePathAndFilename
  282 + * @param string $language
  283 + * @return mixed
  284 + */
  285 + protected static function localizeXlfFilePathAndFilename($filePathAndFilename, $language) {
  286 + $basename = pathinfo($filePathAndFilename, PATHINFO_FILENAME);
  287 + if ('default' !== $language) {
  288 + $filePathAndFilename = str_replace($basename, $language . '.' . $basename, $filePathAndFilename);
  289 + }
  290 + return $filePathAndFilename;
  291 + }
  292 +
  293 + /**
  294 + * @param string $filePathAndFilename
  295 + * @param string $extension
  296 + * @return string
  297 + */
  298 + protected static function sanitizeFilePathAndFilename($filePathAndFilename, $extension) {
  299 + $detectedExtension = pathinfo($filePathAndFilename, PATHINFO_EXTENSION);
  300 + if ($extension !== $detectedExtension) {
  301 + $filePathAndFilename .= '.' . $extension;
92 302 }
  303 + return $filePathAndFilename;
  304 + }
  305 +
  306 + /**
  307 + * @param $filePathAndFilename
  308 + * @return DomDocument
  309 + */
  310 + protected static function prepareDomDocument($filePathAndFilename) {
  311 + if (TRUE === isset(self::$documents[$filePathAndFilename])) {
  312 + return self::$documents[$filePathAndFilename];
  313 + }
  314 + $dom = new DOMDocument('1.0', 'utf-8');
  315 + $dom->preserveWhiteSpace = FALSE;
  316 + $dom->formatOutput = TRUE;
  317 + $dom->load($filePathAndFilename);
  318 + self::$documents[$filePathAndFilename] = $dom;
  319 + return $dom;
  320 + }
  321 +
  322 + /**
  323 + * @return array
  324 + */
  325 + protected static function getLanguageKeys() {
  326 + $cObj = new tslib_cObj();
  327 + $GLOBALS['TSFE'] = new tslib_fe($GLOBALS['TYPO3_CONF_VARS'], 0, 0);
  328 + $GLOBALS['TSFE']->sys_page = new t3lib_pageSelect();
  329 + $select = 'flag';
  330 + $from = 'sys_language';
  331 + $where = '1=1' . $cObj->enableFields('sys_language');
  332 + $sysLanguages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($select, $from, $where);
  333 + $languageKeys = array('default');
  334 + foreach ($sysLanguages as $language) {
  335 + array_push($languageKeys, $language['flag']);
  336 + }
  337 + return array_unique($languageKeys);
93 338 }
94 339
95 340 /**
@@ -109,6 +354,9 @@ protected static function getServiceInstance() {
109 354 * @return void
110 355 */
111 356 protected static function message($message, $severity = t3lib_div::SYSLOG_SEVERITY_INFO) {
  357 + if (FALSE === isset($GLOBALS['BE_USER'])) {
  358 + return;
  359 + }
112 360 self::getServiceInstance()->message($message, $severity, 'Flux Language File Utility');
113 361 }
114 362
2  Tests/Unit/Backend/TableConfigurationPostProcessorTest.php
@@ -54,7 +54,7 @@ public function canCreateTcaFromFluxForm() {
54 54 $this->assertContains($GLOBALS['TCA'][$table]['interface']['showRecordFieldList'], $field);
55 55 $this->assertContains($GLOBALS['TCA'][$table]['types'][0]['showitem'], $field);
56 56 $this->assertEquals($GLOBALS['TCA'][$table]['ctrl']['label'], 'title');
57   - $this->assertStringStartsWith('LLL:EXT', $GLOBALS['TCA'][$table]['title']);
  57 + $this->assertStringStartsWith('LLL:EXT', $GLOBALS['TCA'][$table]['ctrl']['title']);
58 58 }
59 59
60 60 /**
10 Tests/Unit/Backend/TceMainTest.php
@@ -34,6 +34,9 @@ class Tx_Flux_Backend_TceMainTest extends Tx_Flux_Tests_AbstractFunctionalTest {
34 34 */
35 35 public function canExecuteClearAllCacheCommand() {
36 36 $instance = $this->getInstance();
  37 + $mockedFluxService = $this->getMock('Tx_Flux_Service_FluxService', array('resolveConfigurationProviders'));
  38 + $mockedFluxService->expects($this->atLeastOnce())->method('resolveConfigurationProviders')->will($this->returnValue(array()));
  39 + Tx_Extbase_Reflection_ObjectAccess::setProperty($instance, 'configurationService', $mockedFluxService, TRUE);
37 40 $instance->clearCacheCommand('all');
38 41 }
39 42
@@ -42,6 +45,9 @@ public function canExecuteClearAllCacheCommand() {
42 45 */
43 46 public function canExecuteClearAllCacheCommandTwiceWithoutDoubleCalling() {
44 47 $instance = $this->getInstance();
  48 + $mockedFluxService = $this->getMock('Tx_Flux_Service_FluxService', array('resolveConfigurationProviders'));
  49 + $mockedFluxService->expects($this->atLeastOnce())->method('resolveConfigurationProviders')->will($this->returnValue(array()));
  50 + Tx_Extbase_Reflection_ObjectAccess::setProperty($instance, 'configurationService', $mockedFluxService, TRUE);
45 51 $instance->clearCacheCommand('all');
46 52 $instance->clearCacheCommand('all');
47 53 }
@@ -51,6 +57,9 @@ public function canExecuteClearAllCacheCommandTwiceWithoutDoubleCalling() {
51 57 */
52 58 public function canExecuteClearAllCacheCommandAndRemoveManifestFile() {
53 59 $instance = $this->getInstance();
  60 + $mockedFluxService = $this->getMock('Tx_Flux_Service_FluxService', array('resolveConfigurationProviders'));
  61 + $mockedFluxService->expects($this->atLeastOnce())->method('resolveConfigurationProviders')->will($this->returnValue(array()));
  62 + Tx_Extbase_Reflection_ObjectAccess::setProperty($instance, 'configurationService', $mockedFluxService, TRUE);
54 63 $fakeManifestFile = \t3lib_div::getFileAbsFileName('typo3temp/fake-manifest.cache');
55 64 touch($fakeManifestFile);
56 65 $instance->clearCacheCommand('all');
@@ -179,6 +188,7 @@ protected function getInstance() {
179 188 $objectManager = \t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
180 189 /** @var Tx_Flux_Backend_TceMain $tceMainInstance */
181 190 $tceMainInstance = $objectManager->get('Tx_Flux_Backend_TceMain');
  191 + Tx_Extbase_Reflection_ObjectAccess::setProperty($tceMainInstance, 'cachesCleared', FALSE, TRUE);
182 192 return $tceMainInstance;
183 193 }
184 194
50 Tests/Unit/Form/AbstractFormTest.php
@@ -46,6 +46,56 @@ protected function createInstance() {
46 46 /**
47 47 * @test
48 48 */
  49 + public function canGetLabel() {
  50 + $className = $this->getObjectClassName();
  51 + $instance = $this->objectManager->get($className);
  52 + $instance->setName('test');
  53 + if (TRUE === $instance instanceof Tx_Flux_Form_FieldInterface || TRUE === $instance instanceof Tx_Flux_Form_ContainerInterface) {
  54 + $form = Tx_Flux_Form::create(array('extensionKey' => 'flux'));
  55 + $form->add($instance);
  56 + }
  57 + $label = $instance->getLabel();
  58 + $this->assertNotEmpty($label);
  59 + }
  60 +
  61 + /**
  62 + * @test
  63 + */
  64 + public function canAutoWriteLabel() {
  65 + $languageFile = 'LLL:typo3temp/test.xml';
  66 + $absoluteLanguageFile = t3lib_div::getFileAbsFileName(substr($languageFile, 4));
  67 + $className = $this->getObjectClassName();
  68 + $instance = $this->objectManager->get($className);
  69 + $instance->setName('thisIsASpecialFieldName');
  70 + $id = 'somename';
  71 + $form = Tx_Flux_Form::create();
  72 + $form->setId($id);
  73 + $form->setExtensionName('Flux');
  74 + if (FALSE === $instance instanceof Tx_Flux_Form_WizardInterface) {
  75 + $form->add($instance);
  76 + } else {
  77 + $field = $form->createField('Input', 'dummy');
  78 + $field->add($instance);
  79 + }
  80 + $probe = $instance->getName();
  81 + $label = $instance->getLabel();
  82 + $backup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['rewriteLanguageFiles'];
  83 + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['rewriteLanguageFiles'] = 1;
  84 + Tx_Flux_Utility_LanguageFile::reset();
  85 + // note: double call is not an error - designed to trigger caches and assumes no errors happens during that phase
  86 + $this->callInaccessibleMethod($instance, 'writeLanguageLabel', $languageFile, array_pop(explode(':', $label)), $id);
  87 + Tx_Flux_Utility_LanguageFile::reset();
  88 + $this->callInaccessibleMethod($instance, 'writeLanguageLabel', $languageFile, array_pop(explode(':', $label)), $id);
  89 + $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['rewriteLanguageFiles'] = $backup;
  90 + $this->assertNotEmpty($label);
  91 + $this->assertFileExists($absoluteLanguageFile);
  92 + $this->assertContains($probe, file_get_contents($absoluteLanguageFile));
  93 + unlink($absoluteLanguageFile);
  94 + }
  95 +
  96 + /**
  97 + * @test
  98 + */
49 99 public function canGenerateRawLabelWhenLanguageLabelsDisabled() {
50 100 $instance = $this->createInstance();
51 101 $instance->setLabel(NULL);
10 Tests/Unit/Form/Container/ColumnTest.php
@@ -39,4 +39,14 @@ public function canUseGetAreasMethod() {
39 39 $this->assertEmpty($instance->getAreas());
40 40 }
41 41
  42 + /**
  43 + * Override: this Component does not support LLL rewriting
  44 + * and must skip this test which it otherwise inherits
  45 + *
  46 + * @disabledtest
  47 + */
  48 + public function canAutoWriteLabel() {
  49 +
  50 + }
  51 +
42 52 }
10 Tests/Unit/Form/Container/RowTest.php
@@ -39,4 +39,14 @@ public function canUseGetColumnsMethod() {
39 39 $this->assertEmpty($instance->getColumns());
40 40 }
41 41
  42 + /**
  43 + * Override: this Component does not support LLL rewriting
  44 + * and must skip this test which it otherwise inherits
  45 + *
  46 + * @disabledtest
  47 + */
  48 + public function canAutoWriteLabel() {
  49 +
  50 + }
  51 +
42 52 }
14 Tests/Unit/Form/Wizard/AbstractWizardTest.php
@@ -35,6 +35,20 @@
35 35 protected $chainProperties = array('name' => 'test', 'label' => 'Test field', 'hideParent' => FALSE);
36 36
37 37 /**
  38 + * @return void
  39 + */
  40 + public function canAutoWriteLabel() {
  41 +
  42 + }
  43 +
  44 + /**
  45 + * @return void
  46 + */
  47 + public function canGetLabel() {
  48 +
  49 + }
  50 +
  51 + /**
38 52 * @test
39 53 */
40 54 public function hasChildrenAlwaysReturnsFalse() {
16 Tests/Unit/Utility/LanguageFileTest.php
@@ -37,4 +37,20 @@ public function canDispatchMessage() {
37 37 $this->callInaccessibleMethod($instance, 'message', 'Test');
38 38 }
39 39
  40 + /**
  41 + * @test
  42 + */
  43 + public function performsEarlyReturnOnUnsupportedFileExtension() {
  44 + $return = Tx_Flux_Utility_LanguageFile::writeLanguageLabel('/dev/null', 'void', 'void');
  45 + $this->assertEmpty($return);
  46 + }
  47 +
  48 + /**
  49 + * @test
  50 + */
  51 + public function performsEarlyReturnOnInvalidId() {
  52 + $return = Tx_Flux_Utility_LanguageFile::writeLanguageLabel('/dev/null', 'void', 'this-is-an-invalid-id');
  53 + $this->assertEmpty($return);
  54 + }
  55 +
40 56 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.