public function processFile($fileName, $fullPath)
 {
     $indent = '        ';
     $rewriteLexiconFiles = $this->helpers->getProp('rewriteLexiconFiles', false);
     $rewriteCodeFiles = $this->helpers->getProp('rewriteCodeFiles', false);
     $this->helpers->sendLog(modX::LOG_LEVEL_INFO, "\n" . $indent . $this->modx->lexicon('mc_processing') . ' ' . $fileName);
     /* get appropriate LexiconCodeFile object from Factory */
     $lcf = LexiconCodeFileFactory::getInstance($this->modx, $this->helpers, $fullPath, $fileName, $this->targetLexDir);
     $lexFiles = $lcf->lexFiles;
     $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '    ' . $indent . $this->modx->lexicon('mc_lex_files') . ': ' . implode(', ', array_keys($lexFiles)));
     /* Create lexicon files if necessary */
     foreach ($lexFiles as $file => $path) {
         if (!empty($path) && !file_exists($path)) {
             $dir = str_replace($file, '', $path);
             $this->createLexiconFile($dir, $file);
         }
     }
     $used = $lcf->used;
     $defined = $lcf->defined;
     if (!empty($used)) {
         $this->usedSomewhere = array_merge($this->usedSomewhere, $used);
         $this->definedSomewhere = array_merge($this->definedSomewhere, $defined);
         $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '            ' . count($used) . ' ' . $this->modx->lexicon('mc_lex_strings_in_code_file'));
         $missing = $lcf->missing;
         if (!empty($missing)) {
             if (count($lexFiles) > 1) {
                 $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '            ' . $this->modx->lexicon('mc_cannot_update_multiple_lex_files') . ";\n" . $this->modx->lexicon('mc_paste_these_strings') . ':');
             } elseif ($rewriteLexiconFiles) {
                 $lcf->updateLexiconFile();
                 reset($lexFiles);
                 $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '            ' . $this->modx->lexicon('mc_updated_lex_file') . ' ' . key($lexFiles) . ' ' . $this->modx->lexicon('mc_with_these_strings') . ':');
             } else {
                 $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '            ' . $this->modx->lexicon('mc_missing_lex_strings') . ':');
             }
             $code = $this->_formatLexStrings($missing);
             $this->helpers->sendLog(modX::LOG_LEVEL_INFO, "\n" . $this->modx->lexicon('mc_stars'));
             $this->helpers->sendLog(modX::LOG_LEVEL_INFO, $code, true);
             $this->helpers->sendLog(modX::LOG_LEVEL_INFO, "\n" . $this->modx->lexicon('mc_stars'));
         } else {
             $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '            ' . $this->modx->lexicon('mc_all_lex_strings_defined'));
         }
         if ($rewriteCodeFiles) {
             $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '        ' . $this->modx->lexicon('mc_rewriting_code_file'));
             $lcf->updateCodeFile();
         }
     } else {
         $this->helpers->sendLog(modX::LOG_LEVEL_INFO, '            ' . $this->modx->lexicon('mc_no_language_strings_in_file'));
     }
 }
 public function testUpdateCodeFile()
 {
     $files = array($this->targetModelDir => 'example.class.php', $this->targetJsDir => 'example.js', $this->targetChunkDir => 'chunk1.chunk.html', $this->targetPropertiesDir => 'properties.propertyset1.propertyset.php', $this->targetPropertiesDir => 'properties.snippet1.snippet.php', $this->targetDataDir => 'transport.menus.php');
     foreach ($files as $dir => $fileName) {
         $lcf = null;
         $this->assertFileExists($dir . '/' . $fileName);
         $lcf = LexiconCodeFileFactory::getInstance($this->modx, $this->mc->helpers, $dir, $fileName, $this->targetLexDir, $this->languages);
         $updated = $lcf->updateCodeFile();
         $this->assertEmpty($lcf->hasError());
         $content = file_get_contents($dir . '/' . $fileName);
         $this->assertNotEmpty($content, 'File content is empty');
         if ($fileName == 'example.class.php') {
             $this->assertTrue(strpos($content, '~~') === false, '~~ found', $fileName);
             $this->assertContains('$x = $this->modx->lexicon("string1")', $content);
             $this->assertContains('$y = $this->modx->lexicon(\'string2\')', $content);
             $this->assertContains('$z = $this->modx->lexicon(\'string3\')', $content);
         }
         if ($fileName == 'chunk1.chunk.html') {
             $this->assertTrue(strpos($content, '~~') === false, '~~ found', $fileName);
             $this->assertContains('[[%string1]]', $content);
             $this->assertContains('[[%string2]]', $content);
             $this->assertContains('[[%string3]]', $content);
         }
         if ($fileName == 'example.js') {
             $this->assertTrue(strpos($content, '~~') === false, '~~ found', $fileName);
             $this->assertContains('x = _("string1")', $content);
             $this->assertContains('y = _(\'string2\')', $content);
             $this->assertContains('z = _(\'string3\')', $content);
         }
         if ($fileName == 'properties.propertyset1.propertyset.php') {
             $this->assertTrue(strpos($content, '~~') === false, '~~ found', $fileName);
             $this->assertContains("'desc' => \"string1\"", $content);
             $this->assertContains("'desc' => 'string2'", $content);
             $this->assertContains("'desc' => 'string3'", $content);
         }
         if ($fileName == 'transport.menus.php') {
             $this->assertTrue(strpos($content, '~~') === false, '~~ found', $fileName);
             $this->assertContains("'description' => \"string21\"", $content);
             $this->assertContains("'description' => 'string22'", $content);
             $this->assertContains("'description' => 'string23'", $content);
         }
         if ($fileName == 'transport.settings.php') {
             $this->assertTrue(strpos($content, '~~') === false, '~~ found', $fileName);
             $this->assertContains("'key' => \"string1\"", $content);
             $this->assertContains("'key' => 'string2'", $content);
             $this->assertContains("'key' => 'string3'", $content);
         }
     }
 }