diff -u b/tmgmt.module b/tmgmt.module --- b/tmgmt.module +++ b/tmgmt.module @@ -1423,7 +1423,7 @@ function tmgmt_word_count($text) { // Replace each punctuation mark with space. $text = str_replace(array('`', '~', '!', '@', '"', '#', '№', '$', ';', '%', '^', ':', '?', '&', '*', '(', ')', '-', '_', '+', '=', '{', '}', '[', ']', '\\', '|', '/', '\'', '<', '>', ',', '.'), ' ', $text); - // Remove duplicates. + // Remove duplicate spaces. $text = trim(preg_replace('/ {2,}/', ' ', $text)); // Turn into an array. $array = ($text) ? explode(' ', $text) : array(); diff -u b/tmgmt.test b/tmgmt.test --- b/tmgmt.test +++ b/tmgmt.test @@ -995,6 +995,34 @@ ); $this->assertEqual(tmgmt_data_item_label($parent_label), 'Parent label > Sub label'); } + + function testWordCount() { + $unit_tests = array( + 'empty' => array( + 'text' => '', + 'count' => 0, + ), + 'latin' => array( + 'text' => 'Drupal is the best!', + 'count' => 4, + ), + 'non-latin' => array( + 'text' => 'Друпал лучший!', + 'count' => 2, + ), + 'complex punctuation' => array( + 'text' => '<[({-!ReAd@*;: ,?+MoRe...})]>\\|/', + 'count' => 2, + ), + 'repeat' => array( + 'text' => 'repeat repeat', + 'count' => 2, + ), + ); + foreach ($unit_tests as $id => $test_data) { + $this->assertEqual($real_count = tmgmt_word_count($test_data['text']), $desirable_count = $test_data['count'], t('!test_id: Real count (=!real_count) should be equal to desirable (=!desirable_count)', array('!test_id' => $id, '!real_count' => $real_count, '!desirable_count' => $desirable_count))); + } + } } /** @@ -1152,37 +1179,0 @@ - -class TMGMTWordCountUnitTestCase extends DrupalUnitTestCase { - - public static function getInfo() { - return array( - 'name' => 'Unit test for word count calculation', - 'description' => 'Tests the tmgmt_word_count() function.', - 'group' => t('Translation Management'), - ); - } - - public $unit_tests = array( - 'empty' => array( - 'text' => '', - 'count' => 0, - ), - 'latin' => array( - 'text' => 'Drupal is the best!', - 'count' => 4, - ), - 'non-latin' => array( - 'text' => 'Друпал лучший!', - 'count' => 2, - ), - 'complex punctuation' => array( - 'text' => '<[({-!ReAd@*;: ,?+MoRe...})]>\\|/', - 'count' => 2, - ), - ); - - public function testJobItemCount() { - module_load_include('module', 'tmgmt'); - foreach ($this->unit_tests as $id => $test_data) { - $this->assertEqual($real_count = tmgmt_word_count($test_data['text']), $desirable_count = $test_data['count'], t('!test_id: Real count (=!real_count) should be equal to desirable (=!desirable_count)', array('!test_id' => $id, '!real_count' => $real_count, '!desirable_count' => $desirable_count))); - } - } -} \ В конце файла нет новой строки