Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
XssProtectionTest.php
Go to the documentation of this file.
1 <?php
8 
11 
12 class XssProtectionTest extends \PHPUnit\Framework\TestCase
13 {
19  public function testGetValue($userAgent, $expectedHeader)
20  {
21  $headerServiceMock = $this->getMockBuilder(\Magento\Framework\HTTP\Header::class)
22  ->disableOriginalConstructor()
23  ->getMock();
24  $headerServiceMock->expects($this->once())->method('getHttpUserAgent')->willReturn($userAgent);
25  $model = (new ObjectManager($this))->getObject(
26  \Magento\Framework\App\Response\HeaderProvider\XssProtection::class,
27  ['headerService' => $headerServiceMock]
28  );
29  $this->assertSame($expectedHeader, $model->getValue());
30  }
31 
35  public function userAgentDataProvider()
36  {
37  return [
38  [
39  'user-agent' => 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; GTB7.4)',
40  'expected-header' => XssProtection::HEADER_DISABLED
41  ],
42  [
43  'user-agent' => 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/4.0; GTB7.4)',
44  'expected-header' => XssProtection::HEADER_ENABLED
45  ],
46  [
47  'user-agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) Chrome/41.0.2227.1 Safari/537.36',
48  'expected-header' => XssProtection::HEADER_ENABLED
49  ],
50  ];
51  }
52 }