9
9
namespace Magento \Cms \Model \Page ;
10
10
11
11
use Magento \Cms \Api \GetPageByIdentifierInterface ;
12
+ use Magento \Framework \App \Request \Http as HttpRequest ;
13
+ use Magento \Framework \App \RequestInterface ;
14
+ use Magento \Framework \ObjectManagerInterface ;
12
15
use Magento \TestFramework \Cms \Model \CustomLayoutManager ;
13
16
use Magento \TestFramework \Helper \Bootstrap ;
14
17
use PHPUnit \Framework \TestCase ;
15
- use Magento \Cms \Model \Page as PageModel ;
16
- use Magento \Framework \App \Request \Http as HttpRequest ;
17
18
18
19
/**
19
20
* Test pages data provider.
22
23
*/
23
24
class DataProviderTest extends TestCase
24
25
{
26
+ private $ providerData = [
27
+ 'name ' => 'test ' ,
28
+ 'primaryFieldName ' => 'page_id ' ,
29
+ 'requestFieldName ' => 'page_id ' ,
30
+ ];
31
+
25
32
/**
26
33
* @var DataProvider
27
34
*/
@@ -42,59 +49,69 @@ class DataProviderTest extends TestCase
42
49
*/
43
50
private $ request ;
44
51
52
+ /**
53
+ * @var ObjectManagerInterface
54
+ */
55
+ private $ objectManager ;
56
+
45
57
/**
46
58
* @inheritDoc
47
59
*/
48
60
protected function setUp (): void
49
61
{
50
- $ objectManager = Bootstrap::getObjectManager ();
51
- $ objectManager ->configure ([
52
- 'preferences ' => [
53
- \Magento \Cms \Model \Page \CustomLayoutManagerInterface::class =>
54
- \Magento \TestFramework \Cms \Model \CustomLayoutManager::class
55
- ]
62
+ $ this ->objectManager = Bootstrap::getObjectManager ();
63
+ $ this ->objectManager ->configure ([
64
+ 'preferences ' => [CustomLayoutManagerInterface::class => CustomLayoutManager::class]
56
65
]);
57
- $ this ->repo = $ objectManager ->get (GetPageByIdentifierInterface::class);
58
- $ this ->filesFaker = $ objectManager ->get (CustomLayoutManager::class);
59
- $ this ->request = $ objectManager ->get (HttpRequest::class);
60
- $ this ->provider = $ objectManager ->create (
66
+ $ this ->repo = $ this -> objectManager ->get (GetPageByIdentifierInterface::class);
67
+ $ this ->filesFaker = $ this -> objectManager ->get (CustomLayoutManager::class);
68
+ $ this ->request = $ this -> objectManager ->get (HttpRequest::class);
69
+ $ this ->provider = $ this -> objectManager ->create (
61
70
DataProvider::class,
62
- [
63
- 'name ' => 'test ' ,
64
- 'primaryFieldName ' => 'page_id ' ,
65
- 'requestFieldName ' => 'page_id ' ,
66
- 'customLayoutManager ' => $ this ->filesFaker
67
- ]
71
+ array_merge ($ this ->providerData , ['customLayoutManager ' => $ this ->filesFaker ])
68
72
);
69
73
}
70
74
71
75
/**
72
76
* Check that custom layout date is handled properly.
73
77
*
74
78
* @magentoDataFixture Magento/Cms/_files/pages_with_layout_xml.php
75
- * @throws \Throwable
79
+ * @dataProvider customLayoutDataProvider
80
+ *
81
+ * @param string $identifier
82
+ * @param string|null $layoutUpdateSelected
76
83
* @return void
77
84
*/
78
- public function testCustomLayoutData (): void
85
+ public function testCustomLayoutData (string $ identifier , ? string $ layoutUpdateSelected ): void
79
86
{
80
- $ data = $ this ->provider ->getData ();
81
- $ page1Data = null ;
82
- $ page2Data = null ;
83
- $ page3Data = null ;
84
- foreach ($ data as $ pageData ) {
85
- if ($ pageData [PageModel::IDENTIFIER ] === 'test_custom_layout_page_1 ' ) {
86
- $ page1Data = $ pageData ;
87
- } elseif ($ pageData [PageModel::IDENTIFIER ] === 'test_custom_layout_page_2 ' ) {
88
- $ page2Data = $ pageData ;
89
- } elseif ($ pageData [PageModel::IDENTIFIER ] === 'test_custom_layout_page_3 ' ) {
90
- $ page3Data = $ pageData ;
91
- }
92
- }
93
- $ this ->assertNotEmpty ($ page1Data );
94
- $ this ->assertNotEmpty ($ page2Data );
95
- $ this ->assertEquals ('_existing_ ' , $ page1Data ['layout_update_selected ' ]);
96
- $ this ->assertNull ($ page2Data ['layout_update_selected ' ]);
97
- $ this ->assertEquals ('test_selected ' , $ page3Data ['layout_update_selected ' ]);
87
+ $ page = $ this ->repo ->execute ($ identifier , 0 );
88
+
89
+ $ request = $ this ->objectManager ->create (RequestInterface::class);
90
+ $ request ->setParam ('page_id ' , $ page ->getId ());
91
+
92
+ $ provider = $ this ->objectManager ->create (
93
+ DataProvider::class,
94
+ array_merge ($ this ->providerData , ['request ' => $ request ])
95
+ );
96
+
97
+ $ data = $ provider ->getData ();
98
+ $ pageData = $ data [$ page ->getId ()];
99
+
100
+ $ this ->assertEquals ($ layoutUpdateSelected , $ pageData ['layout_update_selected ' ]);
101
+ }
102
+
103
+ /**
104
+ * DataProvider for testCustomLayoutData
105
+ *
106
+ * @return array
107
+ */
108
+ public function customLayoutDataProvider (): array
109
+ {
110
+ return [
111
+ ['test_custom_layout_page_1 ' , '_existing_ ' ],
112
+ ['test_custom_layout_page_2 ' , null ],
113
+ ['test_custom_layout_page_3 ' , 'test_selected ' ],
114
+ ];
98
115
}
99
116
100
117
/**
0 commit comments