DownloadTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Nesk\Puphpeteer\Tests;
  3. use Nesk\Puphpeteer\Puppeteer;
  4. use Nesk\Rialto\Data\JsFunction;
  5. use PHPUnit\Framework\ExpectationFailedException;
  6. use Nesk\Puphpeteer\Resources\ElementHandle;
  7. class DownloadTest extends TestCase
  8. {
  9. public function setUp(): void
  10. {
  11. parent::setUp();
  12. // Serve the content of the "/resources"-folder to test these.
  13. $this->serveResources();
  14. // Launch the browser to run tests on.
  15. $this->launchBrowser();
  16. }
  17. /**
  18. * Downloads an image and checks string length.
  19. *
  20. * @test
  21. */
  22. public function download_image()
  23. {
  24. // Download the image
  25. $page = $this->browser
  26. ->newPage()
  27. ->goto($this->url . '/puphpeteer-logo.png');
  28. $base64 = $page->buffer()->toString('base64');
  29. $imageString = base64_decode($base64);
  30. // Get the reference image from resources
  31. $reference = file_get_contents('tests/resources/puphpeteer-logo.png');
  32. $this->assertTrue(
  33. mb_strlen($reference) === mb_strlen($imageString),
  34. 'Image is not the same length after download.'
  35. );
  36. }
  37. /**
  38. * Downloads an image and checks string length.
  39. *
  40. * @test
  41. */
  42. // public function download_large_image()
  43. // {
  44. // // Download the image
  45. // $page = $this->browser
  46. // ->newPage()
  47. // ->goto($this->url . '/denys-barabanov-jKcFmXCfaQ8-unsplash.jpg');
  48. // $base64 = $page->buffer()->toString('base64');
  49. // $imageString = base64_decode($base64);
  50. // // Get the reference image from resources
  51. // $reference = file_get_contents('tests/resources/denys-barabanov-jKcFmXCfaQ8-unsplash.jpg');
  52. // $this->assertTrue(
  53. // mb_strlen($reference) === mb_strlen($imageString),
  54. // 'Large image is not the same length after download.'
  55. // );
  56. // }
  57. }