Skip to content

Commit

Permalink
Merge branch 'MDL-35206-email-links_25' of git://github.com/mudrd8mz/…
Browse files Browse the repository at this point in the history
…moodle into MOODLE_25_STABLE
  • Loading branch information
Sam Hemelryk committed Jul 1, 2013
2 parents dc59a1b + 52d485c commit 9a561bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/html2text.php
Expand Up @@ -584,7 +584,7 @@ function _build_link_list( $link, $display )
$index = count($this->_link_list);
}

return $display . ' [' . ($index+1) . ']';
return $display . ' [' . ($index) . ']';
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/html2text_readme.txt
Expand Up @@ -12,6 +12,7 @@ Modifications
3. Use textlib, not crappy functions that break UTF-8, in the _strtoupper method. (Tim Hunt 2010-11-02)
4. Make sure html2text does not destroy '0'. (Tim Hunt 2011-09-21)
5. define missing mail charset
6. Fixed the links list enumeration (MDL-35206).


Imported from: https://github.com/moodle/custom-html2text/tree/MOODLE_5886_1
25 changes: 25 additions & 0 deletions lib/tests/html2text_test.php
Expand Up @@ -73,6 +73,31 @@ public function test_zero() {
$this->assertSame('0', html_to_text('0'));
}

/**
* Test the links list enumeration.
*/
public function test_build_link_list() {

// Note the trailing whitespace left intentionally in the text.
$text = 'Total of <a title="List of integrated issues"
href="http://tr.mdl.org/sh.jspa?r=1&j=p+%3D+%22I+d%22+%3D">
<strong>27 issues</strong></a> and <a href="http://another.url/?f=a&amp;b=2">some</a> other
have been fixed <strong><a href="http://third.url/view.php">last week</a></strong>';

// Do not collect links.
$result = html_to_text($text, 5000, false);
$this->assertSame('Total of 27 ISSUES and some other have been fixed LAST WEEK', $result);

// Collect and enumerate links.
$result = html_to_text($text, 5000, true);
$this->assertSame(0, strpos($result, 'Total of 27 ISSUES [1] and some [2] other have been fixed LAST WEEK [3]'));
$this->assertSame(false, strpos($result, '[0]'));
$this->assertSame(1, preg_match('|^'.preg_quote('[1] http://tr.mdl.org/sh.jspa?r=1&j=p+%3D+%22I+d%22+%3D').'$|m', $result));
$this->assertSame(1, preg_match('|^'.preg_quote('[2] http://another.url/?f=a&amp;b=2').'$|m', $result));
$this->assertSame(1, preg_match('|^'.preg_quote('[3] http://third.url/view.php').'$|m', $result));
$this->assertSame(false, strpos($result, '[4]'));
}

// ======= Standard html2text conversion features =======

/**
Expand Down

0 comments on commit 9a561bc

Please sign in to comment.