vizhash16x16.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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)) mkdir($this->_path);
  13. $this->_file = $this->_path . DIRECTORY_SEPARATOR . 'vizhash.png';
  14. serversalt::setPath($this->_path);
  15. }
  16. public function tearDown()
  17. {
  18. /* Tear Down Routine */
  19. chmod($this->_path, 0700);
  20. if(!@unlink($this->_file)) {
  21. throw new Exception('Error deleting file "' . $this->_file . '".');
  22. }
  23. helper::rmdir($this->_path);
  24. }
  25. public function testVizhashGeneratesUniquePngsPerIp()
  26. {
  27. $vz = new vizhash16x16();
  28. $pngdata = $vz->generate('127.0.0.1');
  29. file_put_contents($this->_file, $pngdata);
  30. $finfo = new finfo(FILEINFO_MIME_TYPE);
  31. $this->assertEquals('image/png', $finfo->file($this->_file));
  32. $this->assertNotEquals($pngdata, $vz->generate('2001:1620:2057:dead:beef::cafe:babe'));
  33. $this->assertEquals($pngdata, $vz->generate('127.0.0.1'));
  34. }
  35. }