@@ -62,7 +62,7 @@ class YamlRunnerTest extends \PHPUnit\Framework\TestCase
62
62
* @var string[] A list of supported features
63
63
*/
64
64
private static $ supportedFeatures = [
65
- 'stash_in_path ' , 'warnings ' , 'headers '
65
+ 'stash_in_path ' , 'warnings ' , 'headers ' , ' contains '
66
66
];
67
67
68
68
/**
@@ -154,12 +154,7 @@ public static function setUpBeforeClass()
154
154
155
155
public function setUp ()
156
156
{
157
- $ this ->client = Elasticsearch \ClientBuilder::create ()
158
- ->setHosts ([self ::getHost ()]);
159
- if (getenv ('TEST_SUITE ' ) === 'xpack ' ) {
160
- $ this ->client ->setSSLVerification (__DIR__ . '/../../../.ci/certs/ca.crt ' );
161
- }
162
- $ this ->client = $ this ->client ->build ();
157
+ $ this ->client = Utility::getClient ();
163
158
}
164
159
165
160
public function tearDown ()
@@ -306,6 +301,10 @@ public function processOperation($operation, $lastOperationResult, array &$conte
306
301
return $ this ->operationSkip ($ operation ->{$ operationName }, $ lastOperationResult , $ testName );
307
302
}
308
303
304
+ if ('contains ' === $ operationName ) {
305
+ return $ this ->operationContains ($ operation ->{$ operationName }, $ lastOperationResult , $ context , $ testName );
306
+ }
307
+
309
308
self ::markTestIncomplete (sprintf ('Operation %s not supported for test "%s" ' , $ operationName , $ testName ));
310
309
}
311
310
@@ -789,6 +788,24 @@ public function operationSkip($operation, $lastOperationResult, string $testName
789
788
return $ lastOperationResult ;
790
789
}
791
790
791
+ /**
792
+ * Check if a field in the last operation contains a value
793
+ *
794
+ * @param object $operation
795
+ * @param array|string|null $lastOperationResult
796
+ * @param array $context
797
+ * @param string $testName
798
+ */
799
+ public function operationContains ($ operation , $ lastOperationResult , &$ context , string $ testName )
800
+ {
801
+ $ value = $ this ->resolveValue ($ lastOperationResult , key ($ operation ), $ context );
802
+ $ expected = current ($ operation );
803
+
804
+ $ this ->assertContains ($ expected , $ value , 'Failed to contains in test ' . $ testName );
805
+
806
+ return $ lastOperationResult ;
807
+ }
808
+
792
809
/**
793
810
* Assert an expected error
794
811
*
@@ -1065,10 +1082,10 @@ function ($item) {
1065
1082
$ skip = true ;
1066
1083
}
1067
1084
1068
- if (!$ skip && key ($ documentParsed ) === 'setup ' ) {
1085
+ if (!$ skip && is_array ( $ documentParsed ) && key ($ documentParsed ) === 'setup ' ) {
1069
1086
$ setup = $ documentParsed ;
1070
1087
$ setupSkip = $ skip ;
1071
- } elseif (!$ teardown && key ($ documentParsed ) === 'teardown ' ) {
1088
+ } elseif (!$ teardown && is_array ( $ documentParsed ) && key ($ documentParsed ) === 'teardown ' ) {
1072
1089
$ teardown = $ documentParsed ;
1073
1090
} else {
1074
1091
$ documentsParsed [] = [$ documentParsed , $ skip || $ setupSkip , $ setup , $ teardown , $ fileName ];
@@ -1083,27 +1100,44 @@ function ($item) {
1083
1100
*/
1084
1101
private function clean ()
1085
1102
{
1086
- $ host = static ::getHost ();
1087
- $ ch = curl_init ($ host ."/* " );
1088
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
1089
- curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "DELETE " );
1090
- curl_setopt ($ ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
1091
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 0 );
1092
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 0 );
1103
+ // Delete all indices
1104
+ $ this ->client ->indices ()->delete ([
1105
+ 'index ' => '* '
1106
+ ]);
1093
1107
1094
- $ response = curl_exec ($ ch );
1095
- curl_close ($ ch );
1108
+ // Delete all template
1109
+ $ this ->client ->indices ()->deleteTemplate ([
1110
+ 'name ' => '* '
1111
+ ]);
1096
1112
1097
- $ ch = curl_init ($ host ."/_template/* " );
1098
- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
1099
- curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , "DELETE " );
1100
- curl_setopt ($ ch , CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
1101
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 0 );
1102
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 0 );
1113
+ if (getenv ('TEST_SUITE ' ) === 'xpack ' ) {
1114
+ # Get all roles
1115
+ $ roles = $ this ->client ->security ()->getRole ();
1116
+ # Delete custom roles (metadata._reserved = 0)
1117
+ foreach ($ roles as $ role => $ values ) {
1118
+ if ($ values ['metadata ' ]['_reserved ' ] === 0 ) {
1119
+ $ this ->client ->security ()->deleteRole ([
1120
+ 'name ' => $ role
1121
+ ]);
1122
+ }
1123
+ }
1103
1124
1104
- $ response = curl_exec ($ ch );
1105
- curl_close ($ ch );
1125
+ # Get all users
1126
+ $ users = $ this ->client ->security ()->getUser ();
1127
+ # Delete custom users (metadata._reserved = 0)
1128
+ foreach ($ users as $ user => $ values ) {
1129
+ if ($ values ['metadata ' ]['_reserved ' ] === 0 ) {
1130
+ $ this ->client ->security ()->deleteUser ([
1131
+ 'username ' => $ user
1132
+ ]);
1133
+ }
1134
+ }
1106
1135
1136
+ # Get all privileges
1137
+ $ privileges = $ this ->client ->security ()->getPrivileges ();
1138
+
1139
+ }
1140
+
1107
1141
$ this ->rmDirRecursively ('/tmp/test_repo_create_1_loc ' );
1108
1142
$ this ->rmDirRecursively ('/tmp/test_repo_restore_1_loc ' );
1109
1143
$ this ->rmDirRecursively ('/tmp/test_cat_repo_1_loc ' );
0 commit comments