Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
AppAreaTest Class Reference
Inheritance diagram for AppAreaTest:

Public Member Functions

 testGetTestAppArea ($annotations, $expectedArea)
 
 getTestAppAreaDataProvider ()
 
 testGetTestAppAreaWithInvalidArea ()
 
 testStartTestWithDifferentAreaCodes (string $areaCode)
 
 testStartTestPreventDoubleAreaLoadingAfterReinitialization ()
 
 testStartTestPreventDoubleAreaLoading ()
 
 startTestWithDifferentAreaCodes ()
 

Protected Member Functions

 setUp ()
 

Protected Attributes

 $_object
 
 $_applicationMock
 
 $_testCaseMock
 

Detailed Description

Definition at line 11 of file AppAreaTest.php.

Member Function Documentation

◆ getTestAppAreaDataProvider()

getTestAppAreaDataProvider ( )

Definition at line 49 of file AppAreaTest.php.

50  {
51  return [
52  'method scope' => [['method' => ['magentoAppArea' => ['adminhtml']]], 'adminhtml'],
53  'class scope' => [['class' => ['magentoAppArea' => ['frontend']]], 'frontend'],
54  'mixed scope' => [
55  [
56  'class' => ['magentoAppArea' => ['adminhtml']],
57  'method' => ['magentoAppArea' => ['frontend']],
58  ],
59  'frontend',
60  ],
61  'default area' => [[], 'global']
62  ];
63  }

◆ setUp()

setUp ( )
protected

Definition at line 28 of file AppAreaTest.php.

29  {
30  $this->_testCaseMock = $this->createMock(\PHPUnit\Framework\TestCase::class);
31  $this->_applicationMock = $this->createMock(\Magento\TestFramework\Application::class);
32  $this->_object = new \Magento\TestFramework\Annotation\AppArea($this->_applicationMock);
33  }

◆ startTestWithDifferentAreaCodes()

startTestWithDifferentAreaCodes ( )

Provide test data for testStartTestWithDifferentAreaCodes().

Returns
array

Definition at line 117 of file AppAreaTest.php.

118  {
119  return [
120  [
121  'area_code' => Area::AREA_GLOBAL,
122  ],
123  [
124  'area_code' => Area::AREA_ADMINHTML,
125  ],
126  [
127  'area_code' => Area::AREA_FRONTEND,
128  ],
129  [
130  'area_code' => Area::AREA_WEBAPI_REST,
131  ],
132  [
133  'area_code' => Area::AREA_WEBAPI_SOAP,
134  ],
135  [
136  'area_code' => Area::AREA_CRONTAB,
137  ],
138  [
139  'area_code' => Area::AREA_GRAPHQL,
140  ],
141  ];
142  }

◆ testGetTestAppArea()

testGetTestAppArea (   $annotations,
  $expectedArea 
)
Parameters
array$annotations
string$expectedArea@dataProvider getTestAppAreaDataProvider

Definition at line 40 of file AppAreaTest.php.

41  {
42  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
43  $this->_applicationMock->expects($this->any())->method('getArea')->will($this->returnValue(null));
44  $this->_applicationMock->expects($this->once())->method('reinitialize');
45  $this->_applicationMock->expects($this->once())->method('loadArea')->with($expectedArea);
46  $this->_object->startTest($this->_testCaseMock);
47  }

◆ testGetTestAppAreaWithInvalidArea()

testGetTestAppAreaWithInvalidArea ( )

@expectedException \Magento\Framework\Exception\LocalizedException

Definition at line 68 of file AppAreaTest.php.

69  {
70  $annotations = ['method' => ['magentoAppArea' => ['some_invalid_area']]];
71  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
72  $this->_object->startTest($this->_testCaseMock);
73  }

◆ testStartTestPreventDoubleAreaLoading()

testStartTestPreventDoubleAreaLoading ( )

Definition at line 102 of file AppAreaTest.php.

103  {
104  $annotations = ['method' => ['magentoAppArea' => ['adminhtml']]];
105  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
106  $this->_applicationMock->expects($this->once())->method('getArea')->will($this->returnValue('adminhtml'));
107  $this->_applicationMock->expects($this->never())->method('reinitialize');
108  $this->_applicationMock->expects($this->never())->method('loadArea');
109  $this->_object->startTest($this->_testCaseMock);
110  }

◆ testStartTestPreventDoubleAreaLoadingAfterReinitialization()

testStartTestPreventDoubleAreaLoadingAfterReinitialization ( )

Definition at line 91 of file AppAreaTest.php.

92  {
93  $annotations = ['method' => ['magentoAppArea' => ['global']]];
94  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
95  $this->_applicationMock->expects($this->at(0))->method('getArea')->will($this->returnValue('adminhtml'));
96  $this->_applicationMock->expects($this->once())->method('reinitialize');
97  $this->_applicationMock->expects($this->at(2))->method('getArea')->will($this->returnValue('global'));
98  $this->_applicationMock->expects($this->never())->method('loadArea');
99  $this->_object->startTest($this->_testCaseMock);
100  }

◆ testStartTestWithDifferentAreaCodes()

testStartTestWithDifferentAreaCodes ( string  $areaCode)

Check startTest() with different allowed area codes.

@dataProvider startTestWithDifferentAreaCodes

Parameters
string$areaCode

Definition at line 81 of file AppAreaTest.php.

82  {
83  $annotations = ['method' => ['magentoAppArea' => [$areaCode]]];
84  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
85  $this->_applicationMock->expects($this->any())->method('getArea')->willReturn(null);
86  $this->_applicationMock->expects($this->once())->method('reinitialize');
87  $this->_applicationMock->expects($this->once())->method('loadArea')->with($areaCode);
88  $this->_object->startTest($this->_testCaseMock);
89  }

Field Documentation

◆ $_applicationMock

$_applicationMock
protected

Definition at line 21 of file AppAreaTest.php.

◆ $_object

$_object
protected

Definition at line 16 of file AppAreaTest.php.

◆ $_testCaseMock

$_testCaseMock
protected

Definition at line 26 of file AppAreaTest.php.


The documentation for this class was generated from the following file: