SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/tests/content_replaceTest.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. use Sprout\Helpers\ContentReplace;
  15.  
  16.  
  17. class content_replaceTest extends PHPUnit_Framework_TestCase
  18. {
  19.  
  20. public function expandoData()
  21. {
  22. return array(
  23. '<p>Just a paragraph</p>',
  24. 'TEST_LINK',
  25. '<p>Just a paragraph</p>'
  26. ),
  27. '<p>Before</p><div>Not an expando</div>',
  28. 'TEST_LINK',
  29. '<p>Before</p><div>Not an expando</div>'
  30. ),
  31. '<p>Before</p><div class="expando">Inside expando</div>',
  32. 'TEST_LINK',
  33. '<p>Before</p><p><a href="TEST_LINK">More information</a></p>'
  34. ),
  35. '<p>Before</p><div class="expando">Inside expando</div>',
  36. null,
  37. '<p>Before</p>'
  38. ),
  39. '<p>Before</p><div class="expando">Inside expando</div><p>After</p>',
  40. 'TEST_LINK',
  41. '<p>Before</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  42. ),
  43. '<p>Before</p><div align="center" class="expando">Inside expando</div><p>After</p>',
  44. 'TEST_LINK',
  45. '<p>Before</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  46. ),
  47. '<p>Before</p><div class="expando" align="center">Inside expando</div><p>After</p>',
  48. 'TEST_LINK',
  49. '<p>Before</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  50. ),
  51. '<p>Before</p><div class = "expando" >Inside expando</div><p>After</p>',
  52. 'TEST_LINK',
  53. '<p>Before</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  54. ),
  55. '<p>Before</p><div class="expando smalltext">Inside expando</div><p>After</p>',
  56. 'TEST_LINK',
  57. '<p>Before</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  58. ),
  59. '<p>Before</p><div class="smalltext expando">Inside expando</div><p>After</p>',
  60. 'TEST_LINK',
  61. '<p>Before</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  62. ),
  63. '<p>Before</p><div class="exp ando">Inside expando</div><p>After</p>',
  64. 'TEST_LINK',
  65. '<p>Before</p><div class="exp ando">Inside expando</div><p>After</p>'
  66. ),
  67. '<p>Before</p><div class="expando">Inside expando</div><p>Middle</p><div class="expando">Inside expando</div>',
  68. 'TEST_LINK',
  69. '<p>Before</p><p>Middle</p><p><a href="TEST_LINK">More information</a></p>'
  70. ),
  71. '<div class="expando">Inside expando</div><p>Middle</p><div class="expando">Inside expando</div>',
  72. 'TEST_LINK',
  73. '<p>Middle</p><p><a href="TEST_LINK">More information</a></p>'
  74. ),
  75. '<p>Before</p><div class="expando">Inside expando</div><p>Middle</p><div class="expando">Inside expando</div><p>After</p>',
  76. 'TEST_LINK',
  77. '<p>Before</p><p>Middle</p><p>After</p><p><a href="TEST_LINK">More information</a></p>'
  78. ),
  79. '<p>Before</p><div class="expando">Inside <div>Another div</div> expando</div>',
  80. 'TEST_LINK',
  81. '<p>Before</p><p><a href="TEST_LINK">More information</a></p>'
  82. ),
  83. );
  84. }
  85.  
  86.  
  87. /**
  88.   * @dataProvider expandoData
  89.   **/
  90. public function testExpandolink($html, $replacement, $expected)
  91. {
  92. $this->assertEquals($expected, ContentReplace::expandolink($html, $replacement));
  93. }
  94.  
  95. }
  96.