DashboardTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Controller\Adminhtml;
  7. /**
  8. * @magentoAppArea adminhtml
  9. */
  10. class DashboardTest extends \Magento\TestFramework\TestCase\AbstractBackendController
  11. {
  12. public function testAjaxBlockAction()
  13. {
  14. $this->getRequest()->setParam('block', 'tab_orders');
  15. $this->dispatch('backend/admin/dashboard/ajaxBlock');
  16. $actual = $this->getResponse()->getBody();
  17. $this->assertContains('dashboard-diagram', $actual);
  18. }
  19. public function testTunnelAction()
  20. {
  21. $testUrl = \Magento\Backend\Block\Dashboard\Graph::API_URL . '?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World';
  22. $handle = curl_init();
  23. curl_setopt($handle, CURLOPT_URL, $testUrl);
  24. curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
  25. try {
  26. if (false === curl_exec($handle)) {
  27. $this->markTestSkipped('Third-party service is unavailable: ' . $testUrl);
  28. }
  29. curl_close($handle);
  30. } catch (\Exception $e) {
  31. curl_close($handle);
  32. throw $e;
  33. }
  34. $gaData = [
  35. 'cht' => 'lc',
  36. 'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
  37. 'chm' => 'B,f4d4b2,0,0,0',
  38. 'chco' => 'db4814',
  39. 'chd' => 'e:AAAAAAAAf.AAAA',
  40. 'chxt' => 'x,y',
  41. 'chxl' => '0:|10/13/12|10/14/12|10/15/12|10/16/12|10/17/12|10/18/12|10/19/12|1:|0|1|2',
  42. 'chs' => '587x300',
  43. 'chg' => '16.666666666667,50,1,0',
  44. ];
  45. $gaFixture = urlencode(base64_encode(json_encode($gaData)));
  46. /** @var $helper \Magento\Backend\Helper\Dashboard\Data */
  47. $helper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
  48. \Magento\Backend\Helper\Dashboard\Data::class
  49. );
  50. $hash = $helper->getChartDataHash($gaFixture);
  51. $this->getRequest()->setParam('ga', $gaFixture)->setParam('h', $hash);
  52. $this->dispatch('backend/admin/dashboard/tunnel');
  53. $this->assertStringStartsWith("\x89\x50\x4E\x47", $this->getResponse()->getBody()); // PNG header
  54. }
  55. }