No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

109 líneas
3.0KB

  1. <?php
  2. namespace Faker\Test\Provider;
  3. use Faker\Provider\Lorem;
  4. class LoremTest extends \PHPUnit_Framework_TestCase
  5. {
  6. /**
  7. * @expectedException \InvalidArgumentException
  8. */
  9. public function testTextThrowsExceptionWhenAskedTextSizeLessThan5()
  10. {
  11. Lorem::text(4);
  12. }
  13. public function testTextReturnsWordsWhenAskedSizeLessThan25()
  14. {
  15. $this->assertEquals('Word word word word.', TestableLorem::text(24));
  16. }
  17. public function testTextReturnsSentencesWhenAskedSizeLessThan100()
  18. {
  19. $this->assertEquals('This is a test sentence. This is a test sentence. This is a test sentence.', TestableLorem::text(99));
  20. }
  21. public function testTextReturnsParagraphsWhenAskedSizeGreaterOrEqualThanThan100()
  22. {
  23. $this->assertEquals('This is a test paragraph. It has three sentences. Exactly three.', TestableLorem::text(100));
  24. }
  25. public function testSentenceWithZeroNbWordsReturnsEmptyString()
  26. {
  27. $this->assertEquals('', Lorem::sentence(0));
  28. }
  29. public function testSentenceWithNegativeNbWordsReturnsEmptyString()
  30. {
  31. $this->assertEquals('', Lorem::sentence(-1));
  32. }
  33. public function testParagraphWithZeroNbSentencesReturnsEmptyString()
  34. {
  35. $this->assertEquals('', Lorem::paragraph(0));
  36. }
  37. public function testParagraphWithNegativeNbSentencesReturnsEmptyString()
  38. {
  39. $this->assertEquals('', Lorem::paragraph(-1));
  40. }
  41. public function testSentenceWithPositiveNbWordsReturnsAtLeastOneWord()
  42. {
  43. $sentence = Lorem::sentence(1);
  44. $this->assertGreaterThan(1, strlen($sentence));
  45. $this->assertGreaterThanOrEqual(1, count(explode(' ', $sentence)));
  46. }
  47. public function testParagraphWithPositiveNbSentencesReturnsAtLeastOneWord()
  48. {
  49. $paragraph = Lorem::paragraph(1);
  50. $this->assertGreaterThan(1, strlen($paragraph));
  51. $this->assertGreaterThanOrEqual(1, count(explode(' ', $paragraph)));
  52. }
  53. public function testWordssAsText()
  54. {
  55. $words = TestableLorem::words(2, true);
  56. $this->assertEquals('word word', $words);
  57. }
  58. public function testSentencesAsText()
  59. {
  60. $sentences = TestableLorem::sentences(2, true);
  61. $this->assertEquals('This is a test sentence. This is a test sentence.', $sentences);
  62. }
  63. public function testParagraphsAsText()
  64. {
  65. $paragraphs = TestableLorem::paragraphs(2, true);
  66. $expected = "This is a test paragraph. It has three sentences. Exactly three.\n\nThis is a test paragraph. It has three sentences. Exactly three.";
  67. $this->assertEquals($expected, $paragraphs);
  68. }
  69. }
  70. class TestableLorem extends Lorem
  71. {
  72. public static function word()
  73. {
  74. return 'word';
  75. }
  76. public static function sentence($nbWords = 5, $variableNbWords = true)
  77. {
  78. return 'This is a test sentence.';
  79. }
  80. public static function paragraph($nbSentences = 3, $variableNbSentences = true)
  81. {
  82. return 'This is a test paragraph. It has three sentences. Exactly three.';
  83. }
  84. }