SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/tests/lnkTest.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\Lnk;
  15. use Sprout\Helpers\Register;
  16.  
  17.  
  18. class lnkTest extends PHPUnit_Framework_TestCase
  19. {
  20.  
  21. public function setUp()
  22. {
  23. Register::linkspec('\\Sprout\\Helpers\\LinkSpecExternal', 'External URL');
  24. }
  25.  
  26. public function testExternal()
  27. {
  28. $spec = '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }';
  29.  
  30. $this->assertTrue(Lnk::url($spec) === 'http://www.chaoticrage.com');
  31. $this->assertTrue(Lnk::atag($spec) === '<a href="http://www.chaoticrage.com" target="_blank">');
  32. }
  33.  
  34. public function dataAtag()
  35. {
  36. return array(
  37. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  38. null,
  39. '<a href="http://www.chaoticrage.com" target="_blank">',
  40. ),
  41. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  42. array(),
  43. '<a href="http://www.chaoticrage.com" target="_blank">',
  44. ),
  45. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  46. array('class' => 'red'),
  47. '<a href="http://www.chaoticrage.com" class="red" target="_blank">',
  48. ),
  49. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  50. array('target' => 'aaa'),
  51. '<a href="http://www.chaoticrage.com" target="aaa">',
  52. ),
  53. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  54. array('target' => 'aaa', 'class' => 'red'),
  55. '<a href="http://www.chaoticrage.com" class="red" target="aaa">',
  56. ),
  57. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  58. array('target' => ''),
  59. '<a href="http://www.chaoticrage.com">',
  60. ),
  61. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  62. array('target' => null),
  63. '<a href="http://www.chaoticrage.com">',
  64. ),
  65. '{ "class":"\\\\Sprout\\\\Helpers\\\\LinkSpecExternal", "data":"http://www.chaoticrage.com" }',
  66. array('target' => '', 'class' => 'red'),
  67. '<a href="http://www.chaoticrage.com" class="red">',
  68. ),
  69. );
  70. }
  71.  
  72. /**
  73.   * @dataProvider dataAtag
  74.   **/
  75. public function testAtag($spec, $attrs, $expected)
  76. {
  77. $this->assertEquals($expected, Lnk::atag($spec, $attrs));
  78. }
  79.  
  80.  
  81. }
  82.