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