SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/tests/SlugTest.php

  1. <?php
  2.  
  3. use Sprout\Helpers\Slug;
  4. use Sprout\Exceptions\ValidationException;
  5.  
  6. class SlugTest extends PHPUnit_Framework_TestCase
  7. {
  8. public function dataValid()
  9. {
  10. return [
  11. ['a'],
  12. ['0'],
  13. ['-'],
  14. ['test'],
  15. ['test-test'],
  16. ['test--test'],
  17. ['01234'],
  18. ['slug-09-test'],
  19. ['9876-5432-1'],
  20. ['long-page-name-should-still-work-fine'],
  21. ['manywordsnohyphensisntaproblem'],
  22. ];
  23. }
  24.  
  25. /**
  26.   *
  27.   * @dataProvider dataValid
  28.   */
  29. public function testValid($value)
  30. {
  31. try {
  32. Slug::valid($value);
  33. $this->assertEquals(true, true);
  34. } catch (ValidationException $exp) {
  35. $this->assertEquals($value, 'Slug is valid but failed the validation test');
  36. }
  37. }
  38.  
  39. public function dataInvalid()
  40. {
  41. return [
  42. [''],
  43.  
  44. // Capitalisation isn't permitted
  45. ['Test'],
  46. ['INVALID'],
  47.  
  48. ['_test'],
  49. ['test_'],
  50. ['slug_slug'],
  51.  
  52. // All these characters need to be rejected
  53. ['~'],
  54. ['!'],
  55. ['@'],
  56. ['#'],
  57. ['$'],
  58. ['%'],
  59. ['^'],
  60. ['&'],
  61. ['*'],
  62. ['('],
  63. [')'],
  64. ['_'],
  65. ['+'],
  66. ['='],
  67. ['{'],
  68. ['['],
  69. ['}'],
  70. [']'],
  71. [':'],
  72. [';'],
  73. ['"'],
  74. ['\''],
  75. ['<'],
  76. ['>'],
  77. [','],
  78. ['.'],
  79. ['|'],
  80. ['\\'],
  81. ['?'],
  82. ['/'],
  83. ];
  84. }
  85.  
  86. /**
  87.   *
  88.   * @dataProvider dataInvalid
  89.   * @expectedException Sprout\Exceptions\ValidationException
  90.   */
  91. public function testInvalid($value)
  92. {
  93. Slug::valid($value);
  94. }
  95. }
  96.