Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ServiceSerializationTest.php
Go to the documentation of this file.
1 <?php
7 
9 {
13  protected $_version;
14 
18  protected $_restResourcePath;
19 
20  protected function setUp()
21  {
22  $this->_markTestAsRestOnly();
23  $this->_version = 'V1';
24  $this->_restResourcePath = "/{$this->_version}/testmodule4/";
25  }
26 
30  public function testGetServiceCall()
31  {
32  $itemId = 1;
33  $name = 'Test';
34  $serviceInfo = [
35  'rest' => [
36  'resourcePath' => $this->_restResourcePath . $itemId,
38  ],
39  ];
40  $item = $this->_webApiCall($serviceInfo, []);
41  $this->assertEquals($itemId, $item['entity_id'], 'id field returned incorrectly');
42  $this->assertEquals($name, $item['name'], 'name field returned incorrectly');
43  }
44 
48  public function testUpdateServiceCall()
49  {
50  $itemId = 1;
51  $name = 'Test';
52  $serviceInfo = [
53  'rest' => [
54  'resourcePath' => $this->_restResourcePath . $itemId,
56  ],
57  ];
58  $item = $this->_webApiCall($serviceInfo, ['request' => ['name' => $name]]);
59  $this->assertEquals($itemId, $item['entity_id'], 'id field returned incorrectly');
60  $this->assertEquals($name, $item['name'], 'name field returned incorrectly');
61  }
62 
66  public function testNestedDataObjectCall()
67  {
68  $itemId = 1;
69  $name = 'Test';
70  $serviceInfo = [
71  'rest' => [
72  'resourcePath' => $this->_restResourcePath . $itemId . '/nested',
74  ],
75  ];
76  $item = $this->_webApiCall($serviceInfo, ['request' => ['details' => ['name' => $name]]]);
77  $this->assertEquals($itemId, $item['entity_id'], 'id field returned incorrectly');
78  $this->assertEquals($name, $item['name'], 'name field returned incorrectly');
79  }
80 
81  public function testScalarResponse()
82  {
83  $id = 2;
84  $serviceInfo = [
85  'rest' => [
86  'resourcePath' => "{$this->_restResourcePath}scalar/{$id}",
88  ],
89  ];
90  $this->assertEquals($id, $this->_webApiCall($serviceInfo), 'Scalar service output is serialized incorrectly.');
91  }
92 
93  public function testExtensibleCall()
94  {
95  $id = 2;
96  $serviceInfo = [
97  'rest' => [
98  'resourcePath' => "{$this->_restResourcePath}extensibleDataObject/{$id}",
100  ],
101  ];
102 
103  $name = 'Magento';
104  $requestData = [
105  'name' => $name,
106  ];
107  $item = $this->_webApiCall($serviceInfo, ['request' => $requestData]);
108  $this->assertEquals($id, $item['entity_id'], 'id field returned incorrectly');
109  $this->assertEquals($name, $item['name'], 'name field returned incorrectly');
110  }
111 }
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$id
Definition: fieldset.phtml:14
if(!isset($_GET['name'])) $name
Definition: log.php:14