vizhash16x16.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. class vizhash16x16Test extends PHPUnit_Framework_TestCase
  3. {
  4. private $_file;
  5. private $_path;
  6. public function setUp()
  7. {
  8. /* Setup Routine */
  9. $this->_path = PATH . 'data';
  10. if(!is_dir($this->_path)) mkdir($this->_path);
  11. $this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png';
  12. serversalt::setPath($this->_path);
  13. }
  14. public function tearDown()
  15. {
  16. /* Tear Down Routine */
  17. chmod($this->_path, 0700);
  18. if(!@unlink($this->_file)) {
  19. throw new Exception('Error deleting file "' . $this->_file . '".');
  20. }
  21. helper::rmdir($this->_path);
  22. }
  23. public function testVizhashGeneratesUniquePngsPerIp()
  24. {
  25. $vz = new vizhash16x16();
  26. $pngdata = $vz->generate('127.0.0.1');
  27. file_put_contents($this->_file, $pngdata);
  28. $finfo = new finfo(FILEINFO_MIME_TYPE);
  29. $this->assertEquals('image/png', $finfo->file($this->_file));
  30. $this->assertNotEquals($pngdata, $vz->generate('2001:1620:2057:dead:beef::cafe:babe'));
  31. $this->assertEquals($pngdata, $vz->generate('127.0.0.1'));
  32. }
  33. }