Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DashboardTest.php
Go to the documentation of this file.
1 <?php
7 
12 {
13  public function testAjaxBlockAction()
14  {
15  $this->getRequest()->setParam('block', 'tab_orders');
16  $this->dispatch('backend/admin/dashboard/ajaxBlock');
17 
18  $actual = $this->getResponse()->getBody();
19  $this->assertContains('dashboard-diagram', $actual);
20  }
21 
22  public function testTunnelAction()
23  {
24  $testUrl = \Magento\Backend\Block\Dashboard\Graph::API_URL . '?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World';
25  $handle = curl_init();
26  curl_setopt($handle, CURLOPT_URL, $testUrl);
27  curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
28  try {
29  if (false === curl_exec($handle)) {
30  $this->markTestSkipped('Third-party service is unavailable: ' . $testUrl);
31  }
32  curl_close($handle);
33  } catch (\Exception $e) {
34  curl_close($handle);
35  throw $e;
36  }
37 
38  $gaData = [
39  'cht' => 'lc',
40  'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
41  'chm' => 'B,f4d4b2,0,0,0',
42  'chco' => 'db4814',
43  'chd' => 'e:AAAAAAAAf.AAAA',
44  'chxt' => 'x,y',
45  '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',
46  'chs' => '587x300',
47  'chg' => '16.666666666667,50,1,0',
48  ];
49  $gaFixture = urlencode(base64_encode(json_encode($gaData)));
50 
53  \Magento\Backend\Helper\Dashboard\Data::class
54  );
55  $hash = $helper->getChartDataHash($gaFixture);
56  $this->getRequest()->setParam('ga', $gaFixture)->setParam('h', $hash);
57  $this->dispatch('backend/admin/dashboard/tunnel');
58  $this->assertStringStartsWith("\x89\x50\x4E\x47", $this->getResponse()->getBody()); // PNG header
59  }
60 }
$helper
Definition: iframe.phtml:13
$handle