HWLDFWordAccumulatorTest.php 1.3 KB

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