vizhash16x16.php 1.2 KB

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