Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CategoryAttributeRepositoryTest.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Catalog\Api;
8 
10 {
11  const SERVICE_NAME = 'catalogCategoryAttributeRepositoryV1';
12  const SERVICE_VERSION = 'V1';
13  const RESOURCE_PATH = '/V1/categories/attributes';
14 
18  public function testGet()
19  {
20  $attributeCode = 'test_attribute_code_666';
22 
23  $this->assertTrue(is_array($attribute));
24  $this->assertArrayHasKey('attribute_id', $attribute);
25  $this->assertArrayHasKey('attribute_code', $attribute);
26  $this->assertEquals($attributeCode, $attribute['attribute_code']);
27  }
28 
29  public function testGetList()
30  {
31  $searchCriteria = [
32  'searchCriteria' => [
33  'filter_groups' => [
34  [
35  'filters' => [
36  [
37  'field' => 'frontend_input',
38  'value' => 'text',
39  'condition_type' => 'eq',
40  ],
41  ],
42  ],
43  ],
44  'current_page' => 1,
45  'page_size' => 2,
46  ],
48  ];
49 
50  $serviceInfo = [
51  'rest' => [
52  'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
54  ],
55  'soap' => [
56  'service' => self::SERVICE_NAME,
57  'serviceVersion' => self::SERVICE_VERSION,
58  'operation' => self::SERVICE_NAME . 'GetList',
59  ],
60  ];
61 
62  $response = $this->_webApiCall($serviceInfo, $searchCriteria);
63 
64  $this->assertArrayHasKey('search_criteria', $response);
65  $this->assertArrayHasKey('total_count', $response);
66  $this->assertArrayHasKey('items', $response);
67 
68  $this->assertEquals($searchCriteria['searchCriteria'], $response['search_criteria']);
69  $this->assertTrue($response['total_count'] > 0);
70  $this->assertTrue(count($response['items']) > 0);
71 
72  $this->assertNotNull($response['items'][0]['default_frontend_label']);
73  $this->assertNotNull($response['items'][0]['attribute_id']);
74  }
75 
80  protected function getAttribute($attributeCode)
81  {
82  $serviceInfo = [
83  'rest' => [
84  'resourcePath' => self::RESOURCE_PATH . '/' . $attributeCode,
86  ],
87  'soap' => [
88  'service' => self::SERVICE_NAME,
89  'serviceVersion' => self::SERVICE_VERSION,
90  'operation' => self::SERVICE_NAME . 'Get',
91  ],
92  ];
93  return $this->_webApiCall($serviceInfo, ['attributeCode' => $attributeCode]);
94  }
95 }
$response
Definition: 404.php:11
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
$searchCriteria
$attributeCode
Definition: extend.phtml:12