cloud-8.x-2.0-beta1/modules/cloud_service_providers/k8s/tests/src/Functional/K8sConfigMapTest.php

modules/cloud_service_providers/k8s/tests/src/Functional/K8sConfigMapTest.php
<?php

namespace Drupal\Tests\k8s\Functional;

/**
 * Tests K8s config map.
 *
 * @group k8s
 */
class K8sConfigMapTest extends K8sTestCase {

  const K8S_CONFIG_MAP_REPEAT_COUNT = 3;

  /**
   * {@inheritdoc}
   */
  protected function getPermissions() {
    $namespaces = $this->createNamespacesRandomTestFormData();
    $this->createNamespaceTestEntity($namespaces[0]);
    $this->namespace = $namespaces[0]['name'];

    return [
      'list k8s config map',
      'view k8s config map',
      'edit k8s config map',
      'add k8s config map',
      'delete k8s config map',
      'view k8s namespace ' . $this->namespace,
    ];
  }

  /**
   * Tests CRUD for Config Map.
   */
  public function testConfigMap() {

    $cloud_context = $this->cloudContext;

    // List Config Map for K8s.
    $this->drupalGet("/clouds/k8s/$cloud_context/config_map");
    $this->assertResponse(200);

    // Add a new Config Map.
    $add = $this->createConfigMapTestFormData(self::K8S_CONFIG_MAP_REPEAT_COUNT, $this->namespace);
    for ($i = 0; $i < self::K8S_CONFIG_MAP_REPEAT_COUNT; $i++) {
      $this->reloadMockData();

      $this->addConfigMapMockData($add[$i]);

      $num = $i + 1;
      $this->drupalPostForm(
        "/clouds/k8s/$cloud_context/config_map/add",
        $add[$i]['post_data'],
        t('Save')
      );
      $this->assertResponse(200);
      $this->assertText(t('The Kubernetes Config Map "@name" has been created.', ['@name' => $add[$i]['name']]));

      // Make sure listing.
      $this->drupalGet("/clouds/k8s/$cloud_context/config_map");
      $this->assertResponse(200);
      $this->assertText($add[$i]['name']);
    }

    // Edit a Config Map.
    $edit = $this->createConfigMapTestFormData(self::K8S_CONFIG_MAP_REPEAT_COUNT, $this->namespace);
    for ($i = 0; $i < self::K8S_CONFIG_MAP_REPEAT_COUNT; $i++) {
      $num = $i + 1;
      $this->updateConfigMapMockData($edit[$i]);

      unset($edit[$i]['post_data']['namespace']);
      $this->drupalPostForm(
        "/clouds/k8s/$cloud_context/config_map/$num/edit",
        $edit[$i]['post_data'],
        t('Save')
      );
      $this->assertResponse(200);
      $this->assertText(t(
        'The Kubernetes Config Map "@name" has been saved.',
        ['@name' => $add[$i]['name']]
      ));
    }

    // Delete Config Map.
    for ($i = 0; $i < self::K8S_CONFIG_MAP_REPEAT_COUNT; $i++) {
      $num = $i + 1;

      $this->deleteConfigMapMockData($add[$i]);

      $this->drupalPostForm(
        "/clouds/k8s/$cloud_context/config_map/$num/delete",
        [],
        t('Delete')
      );
      $this->assertResponse(200);
      $this->assertText(t(
        'The Kubernetes Config Map "@name" has been deleted.',
        ['@name' => $add[$i]['name']]
      ));

      // Make sure listing.
      $this->drupalGet("/clouds/k8s/$cloud_context/config_map");
      $this->assertResponse(200);
      $this->assertNoText($add[$i]['name']);
    }
  }

  /**
   * Tests deleting config maps with bulk operation.
   */
  public function testConfigMapBulk() {
    $cloud_context = $this->cloudContext;
    for ($i = 0; $i < self::K8S_CONFIG_MAP_REPEAT_COUNT; $i++) {
      // Create Config Maps.
      $config_maps = $this->createConfigMapsRandomTestFormData($this->namespace);
      $entities = [];
      foreach ($config_maps as $config_map) {
        $entities[] = $this->createConfigMapTestEntity($config_map);
      }
      $this->deleteConfigMapMockData($config_maps[0]);
      $this->doTestEntityBulk('config_map', $entities);
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc