SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/tests/spamHelperTest.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\Spam;
  15.  
  16.  
  17. /**
  18. * Test suite
  19. **/
  20. class spamHelperTest extends PHPUnit_Framework_TestCase
  21. {
  22.  
  23. public function testGlue()
  24. {
  25. $html = Spam::glue();
  26.  
  27. $this->assertContains('<div', $html);
  28. $this->assertContains('</div>', $html);
  29. $this->assertContains('<input name="_email"', $html);
  30. $this->assertContains('id="f_', $html);
  31. $this->assertContains('<label for="f_', $html);
  32.  
  33. // Label for= and input id= should match
  34. $count = preg_match_all('/="f_[^"]+"/', $html, $matches);
  35. $this->assertEquals(2, $count);
  36. $this->assertEquals($matches[0][0], $matches[0][1]);
  37. }
  38.  
  39. public function testDetect()
  40. {
  41. $this->assertEmpty(Spam::detect(''));
  42. $this->assertEmpty(Spam::detect('a'));
  43. $this->assertEmpty(Spam::detect('ê'));
  44.  
  45. $this->assertArrayHasKey('html', Spam::detect('<b>'));
  46. $this->assertArrayHasKey('html', Spam::detect('<b>hello</b>'));
  47. $this->assertArrayHasKey('html', Spam::detect('<img>'));
  48. $this->assertArrayNotHasKey('html', Spam::detect('< b >'));
  49.  
  50. $this->assertArrayHasKey('url', Spam::detect('http://www.example.com'));
  51. $this->assertArrayHasKey('url', Spam::detect('www.example.com'));
  52. $this->assertArrayNotHasKey('url', Spam::detect('http example com'));
  53.  
  54. $this->assertArrayHasKey('email', Spam::detect('test@example.com'));
  55. $this->assertArrayHasKey('email', Spam::detect('test.test@example.com'));
  56. $this->assertArrayNotHasKey('email', Spam::detect('test @ test'));
  57. }
  58.  
  59. }
  60.