cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/tests/src/Functional/Config/K8sCloudConfigTest.php
modules/cloud_service_providers/k8s/tests/src/Functional/Config/K8sCloudConfigTest.php
<?php
namespace Drupal\Tests\k8s\Functional\Config;
use Drupal\Tests\k8s\Functional\K8sTestCase;
/**
* Tests cloud service provider.
*
* @group k8s
*/
class K8sCloudConfigTest extends K8sTestCase {
const K8S_CLOUD_CONFIG_REPEAT_COUNT = 3;
/**
* {@inheritdoc}
*/
protected function getPermissions() {
return [
'administer cloud service providers',
'view all cloud service providers',
'add cloud service providers',
'edit cloud service providers',
'edit own cloud service providers',
'delete cloud service providers',
'delete own cloud service providers',
'view unpublished cloud service providers',
'view own unpublished cloud service providers',
'view published cloud service providers',
'view own published cloud service providers',
'access dashboard',
'view cloud service provider admin list',
'administer k8s',
];
}
/**
* {@inheritdoc}
*/
protected function createCloudContext($bundle_type = 'k8s') {
}
/**
* Tests CRUD for cloud service provider information.
*/
public function testCloudConfig() {
// List k8s.
$this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
// Add a new Config information.
$add = $this->createCloudConfigTestFormData(self::K8S_CLOUD_CONFIG_REPEAT_COUNT);
for ($i = 0; $i < self::K8S_CLOUD_CONFIG_REPEAT_COUNT; $i++) {
unset($add[$i]['cloud_context']);
$this->drupalGet('/admin/structure/cloud_config/add');
$this->assertResponse(200, t('HTTP 200: Add | K8s cloud service provider form'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
// Test if API server field is empty.
$_add = $add;
$_add[$i]['field_api_server[0][value]'] = '';
$this->drupalPostForm('/admin/structure/cloud_config/add',
$_add[$i],
t('Save')
);
$this->assertResponse(200, t('HTTP 200: Not saved | K8s cloud service provider form'));
$this->assertText(t('Error'), t('Make sure w/ Error'));
$this->assertText(t('The API server field cannot be empty.'));
// Test if API server field is empty.
$_add = $add;
$_add[$i]['field_token[0][value]'] = '';
$this->drupalPostForm('/admin/structure/cloud_config/add',
$_add[$i],
t('Save')
);
$this->assertResponse(200, t('HTTP 200: Not saved | K8s cloud service provider form'));
$this->assertText(t('Error'), t('Make sure w/ Error'));
$this->assertText(t('The token field cannot be empty.'));
// Test if both API server field and Token field are empty.
$_add = $add;
$_add[$i]['field_api_server[0][value]'] = '';
$_add[$i]['field_token[0][value]'] = '';
$this->drupalPostForm('/admin/structure/cloud_config/add',
$_add[$i],
t('Save')
);
$this->assertResponse(200, t('HTTP 200: Not saved | K8s cloud service provider form'));
$this->assertText(t('Error'), t('Make sure w/ Error'));
$this->assertText(t('The API server field cannot be empty.'));
$this->assertText(t('The token field cannot be empty.'));
// Test the normal "Save" case.
$this->drupalPostForm('/admin/structure/cloud_config/add',
$add[$i],
t('Save')
);
$this->assertResponse(200, t('HTTP 200: Saved | K8s cloud service provider form'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText(t('Created the cloud service provider: @label.',
['@label' => $add[$i]['name[0][value]']]
));
// Make sure listing for '/admin/structure/cloud_config'.
$this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertLink($add[$i]['name[0][value]']);
// Make sure listing for '/clouds'.
$this->drupalGet('/clouds');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertLink($add[$i]['name[0][value]']);
// Make sure listing for '/admin/config/services/cloud/k8s'.
$this->drupalGet('/admin/config/services/cloud/k8s');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertLink($add[$i]['name[0][value]']);
}
// Edit Config case.
$edit = $this->createCloudConfigTestFormData(self::K8S_CLOUD_CONFIG_REPEAT_COUNT);
for ($i = 0; $i < self::K8S_CLOUD_CONFIG_REPEAT_COUNT; $i++) {
$num = $i + 1;
unset($edit[$i]['cloud_context']);
$this->drupalPostForm("/admin/structure/cloud_config/${num}/edit",
$edit[$i],
t('Save')
);
$this->assertResponse(200, t('HTTP 200: Edit | K8s Form'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
// Make sure listing for '/admin/structure/cloud_config'.
$this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertLink($edit[$i]['name[0][value]']);
// Make sure listing for '/clouds'.
$this->drupalGet('/clouds');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertLink($edit[$i]['name[0][value]']);
// Make sure listing for '/admin/config/services/cloud/k8s'.
$this->drupalGet('/admin/config/services/cloud/k8s');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertLink($edit[$i]['name[0][value]']);
}
// Delete Config Items.
for ($i = 0; $i < self::K8S_CLOUD_CONFIG_REPEAT_COUNT; $i++) {
$num = $i + 1;
$this->drupalPostForm("/admin/structure/cloud_config/${num}/delete",
[],
t('Delete')
);
$this->assertResponse(200, t('HTTP 200: Delete | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertText(t('The cloud service provider @label has been deleted.',
['@label' => $edit[$i]['name[0][value]']]
));
// Because $cloud_context has been deleted.
// Make sure listing.
for ($k = 0; $k < $num; $k++) {
// Make sure listing for '/admin/structure/cloud_config'.
$this->drupalGet('/admin/structure/cloud_config');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertNoLink($edit[$k]['name[0][value]']);
// Make sure listing for '/clouds'.
$this->drupalGet('/clouds');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertNoLink($edit[$k]['name[0][value]']);
// Make sure listing for '/admin/config/services/cloud/k8s'.
$this->drupalGet('/admin/config/services/cloud/k8s');
$this->assertResponse(200, t('HTTP 200: List | K8s'));
$this->assertNoText(t('Notice'), t('Make sure w/o Notice'));
$this->assertNoText(t('Warning'), t('Make sure w/o Warnings'));
$this->assertNoLink($edit[$k]['name[0][value]']);
}
}
}
}
