Changeset 653
- Timestamp:
- Nov 28, 2018 1:40:13 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Prefs.inc.php
r644 r653 518 518 // User_id must not be empty. 519 519 if ('' == $this->getParam('user_id')) { 520 $app->logMsg(sprintf('Cannot saveprefs because user_id not set.', null), LOG_WARNING, __FILE__, __LINE__);520 $app->logMsg(sprintf('Cannot load prefs because user_id not set.', null), LOG_WARNING, __FILE__, __LINE__); 521 521 return false; 522 522 } … … 591 591 // Skip this method if not using the db. 592 592 if ('database' != $this->getParam('storagetype')) { 593 $app->logMsg('Prefs->save() does nothing unless using a database storagetype.', LOG_ NOTICE, __FILE__, __LINE__);593 $app->logMsg('Prefs->save() does nothing unless using a database storagetype.', LOG_DEBUG, __FILE__, __LINE__); 594 594 return true; 595 595 } … … 597 597 // User_id must not be empty. 598 598 if ('' == $this->getParam('user_id')) { 599 $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_ WARNING, __FILE__, __LINE__);599 $app->logMsg(sprintf('Cannot save prefs because user_id not set.', null), LOG_DEBUG, __FILE__, __LINE__); 600 600 return false; 601 601 } -
trunk/lib/Utilities.inc.php
r652 r653 221 221 * @return string Cleaned text. 222 222 */ 223 function fancyTxt($text )223 function fancyTxt($text, $extra_search=null, $extra_replace=null) 224 224 { 225 225 $search = array(); 226 226 $replace = array(); 227 227 228 // "double quoted text" becomes “double quoted text” 229 $search['double_quotes'] = '/(^|[^\w=])(?:"|"|"|"|“)([^"]+?)(?:"|"|"|"|”)([^\w]|$)/ms'; // " is the same as " and " and " 230 $replace['double_quotes'] = '$1“$2”$3'; 231 232 // text's apostrophes become text’s apostrophes 233 $search['apostrophe'] = '/(\w)(?:\'|'|')(\w)/ms'; 234 $replace['apostrophe'] = '$1’$2'; 235 236 // 'single quoted text' becomes ‘single quoted text’ 237 $search['single_quotes'] = '/(^|[^\w=])(?:\'|'|‘)([^\']+?)(?:\'|'|’)([^\w]|$)/ms'; 238 $replace['single_quotes'] = '$1‘$2’$3'; 239 240 // plural posessives' apostrophes become posessives’ 241 $search['apostrophes'] = '/(s)(?:\'|'|')(\s)/ms'; 242 $replace['apostrophes'] = '$1’$2'; 243 244 // em--dashes become em—dashes 245 $search['em_dash'] = '/(\s*[^!<-])--([^>-]\s*)/'; 246 $replace['em_dash'] = '$1—$2'; 247 248 return preg_replace($search, $replace, $text); 228 // "double quoted text" â âdouble quoted textâ 229 $search['_double_quotes'] = '/(?<=^|[^\w=(])(?:"|"|�?34;|"|“)([\w\'.âŠ(ââ-][^"]*?)(?:"|"|�?34;|"|”)(?=[^)\w]|$)/imsu'; // " is the same as " and " and " and " 230 $replace['_double_quotes'] = 'â$1â'; 231 232 // text's apostrophes â textâs apostrophes (except foot marks: 6'3") 233 $search['_apostrophe'] = '/(?<=[a-z])(?:\'|�?39;)(?=\w)/imsu'; 234 $replace['_apostrophe'] = 'â'; 235 236 // 'single quoted text' â âsingle quoted textâ 237 $search['_single_quotes'] = '/(?<=^|[^\w=(])(?:\'|�?39;|‘)([\w"][^\']+?)(?:\'|�?39;|’)(?=[^)\w]|$)/imsu'; 238 $replace['_single_quotes'] = 'â$1â'; 239 240 // plural posessives' apostrophes â posessivesâ (except foot marks: 6') 241 $search['_apostrophes'] = '/(?<=s)(?:\'|�?39;|’)(?=\s)/imsu'; 242 $replace['_apostrophes'] = 'â'; 243 244 // double--hyphens â en â dashes 245 $search['_em_dash'] = '/(?<=[\w\s"\'ââ)])--(?=[\w\sâââ"\'(?])/imsu'; 246 $replace['_em_dash'] = ' â '; 247 248 // ... â ⊠249 $search['_elipsis'] = '/(?<=^|[^.])\.\.\.(?=[^.]|$)/imsu'; 250 $replace['_elipsis'] = 'âŠ'; 251 252 if (is_array($extra_search) && is_array($extra_replace) && sizeof($extra_search) == sizeof($extra_replace)) { 253 // Append additional search replacements. 254 $search = array_merge($search, $extra_search); 255 $replace = array_merge($replace, $extra_replace); 256 } 257 258 return trim(preg_replace($search, $replace, $text)); 249 259 } 250 260 -
trunk/tests/EmailTest.php
r622 r653 99 99 $this->Email->setString('This is a {TEST}'); 100 100 $this->Email->replace(array( 101 'test' => 'â you guessed it â a test! '101 'test' => 'â you guessed it â a test! Sent from ' . __FILE__ 102 102 )); 103 103 $result = $this->Email->send(); -
trunk/tests/UtilitiesTest.php
r545 r653 35 35 function setUp() 36 36 { 37 define('_CLI', true);37 // define('_CLI', true); 38 38 require dirname(__FILE__) . '/_config.inc.php'; 39 39 require_once '../lib/Utilities.inc.php'; … … 255 255 } 256 256 257 function test_fancyTxt() 258 { 259 $strings = [ 260 'Due to the <a href="https://en.wikipedia.org/wiki/Camp_Fire_(2018)">fires in "Paradise," CA</a> it\'s a bad day.' => '⢠Due to the <a href="https://en.wikipedia.org/wiki/Camp_Fire_(2018)">fires in âParadise,â CA</a> itâs a bad day.', 261 'Simply--"\'check back\' later"--in 6\'3"...' => '⢠Simply â ââcheck backâ laterâ â in 6\'3"âŠ', 262 '"Double "double \'single\'""--?' => '⢠"Double âdouble âsingleââ" â ?', 263 '<a href="javascript:openPopup(\'/foo/bar.php\')">Click here</a>....' => '⢠<a href="javascript:openPopup(\'/foo/bar.php\')">Click here</a>....', 264 'If you have any questions please <a href="/contact/">contact the ants\' mailboxes</a>.' => '⢠If you have any questions please <a href="/contact/">contact the antsâ mailboxes</a>.', 265 'This URL: "http://äŸå.å·ç纞/?x=y&1=2#asdf"' => '⢠This URL: âhttp://äŸå.å·ç纞/?x=y&1=2#asdfâ', 266 // '\'...\' and "..."' => '⢠ââŠâ and ââŠâ', // FIXME: this one doesn't work. 267 '\'1...\' and "2..."' => '⢠â1âŠâ and â2âŠâ', 268 '\'One\'s self...\' and "Twosome"' => '⢠âOneâs selfâŠâ and âTwosomeâ', 269 '"\'Well,\' said I, \'the gentleman at No. 4.\'"' => '⢠ââWell,â said I, âthe gentleman at No. 4.ââ', 270 '"...an office in Leadenhall Street--and--" 271 "O\'Reilly\'s office?" 272 "What!" he roared. 273 "Yes, to-day."* She stood smiling.' 274 => 275 '⢠ââŠan office in Leadenhall Street â and â â 276 âOâReillyâs office?â 277 âWhat!â he roared. 278 âYes, to-day.â* She stood smiling.', 279 ]; 280 foreach ($strings as $input => $expected) { 281 $result = fancyTxt($input, ['/^/', '/^·/'], ['· ', 'â¢']); 282 $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input)); 283 } 284 } 257 285 } -
trunk/tests/run_tests.sh
r622 r653 7 7 # export DB_USER="test" 8 8 # export DB_PASS="..." 9 10 # Run an individual test like this: 11 # ./tests/run_tests.sh /Users/q/src/codebase/trunk/tests/UtilitiesTest.php 9 12 10 13 function err { … … 38 41 # Config options go in phpunit.xml 39 42 # phpunit --tap | grep -v '^ok ' 40 ../vendor/phpunit/phpunit/composer/bin/phpunit --stderr || err "\nSomething went wrong (code $?). If there is no output above, check the php_error_log";43 ../vendor/phpunit/phpunit/composer/bin/phpunit --stderr "$@" || err "\nSomething went wrong (code $?). If there is no output above, check the php_error_log"; 41 44
Note: See TracChangeset
for help on using the changeset viewer.