vizhash16x16.php 1.2 KB

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