ccf468d348d605752cd879f15d50ba87370e7355
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Diff / Engine / HWLDFWordAccumulatorTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Diff\Engine;
4
5 use Drupal\Component\Diff\Engine\HWLDFWordAccumulator;
6
7 /**
8  * Test HWLDFWordAccumulator.
9  *
10  * @coversDefaultClass \Drupal\Component\Diff\Engine\HWLDFWordAccumulator
11  *
12  * @group Diff
13  */
14 class HWLDFWordAccumulatorTest extends \PHPUnit_Framework_TestCase {
15
16   /**
17    * Verify that we only get back a NBSP from an empty accumulator.
18    *
19    * @covers ::getLines
20    *
21    * @see Drupal\Component\Diff\Engine\HWLDFWordAccumulator::NBSP
22    */
23   public function testGetLinesEmpty() {
24     $acc = new HWLDFWordAccumulator();
25     $this->assertEquals(['&#160;'], $acc->getLines());
26   }
27
28   /**
29    * @return array
30    *   - Expected array of lines from getLines().
31    *   - Array of strings for the $words parameter to addWords().
32    *   - String tag for the $tag parameter to addWords().
33    */
34   public function provideAddWords() {
35     return [
36       [['wordword2'], ['word', 'word2'], 'tag'],
37       [['word', 'word2'], ['word', "\nword2"], 'tag'],
38       [['&#160;', 'word2'], ['', "\nword2"], 'tag'],
39     ];
40   }
41
42   /**
43    * @covers ::addWords
44    * @dataProvider provideAddWords
45    */
46   public function testAddWords($expected, $words, $tag) {
47     $acc = new HWLDFWordAccumulator();
48     $acc->addWords($words, $tag);
49     $this->assertEquals($expected, $acc->getLines());
50   }
51
52 }