Commit b2c9f7bb authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3167070 by Xiaohua Guan, yas: Add test cases for list up VMware virtual machine(s)

parent d5d7f7ac
Loading
Loading
Loading
Loading
+98
Changes for modules/cloud_service_providers/vmware/tests/src/Functional/VmwareTestBase.php: 98 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\vmware\Functional;

use Drupal\cloud\Entity\CloudConfig;
use Drupal\cloud\Entity\CloudContentEntityBase;
use Drupal\Tests\cloud\Functional\CloudTestBase;
use Drupal\Tests\vmware\Traits\VmwareTestEntityTrait;
use Drupal\Tests\vmware\Traits\VmwareTestFormDataTrait;
use Drupal\Tests\vmware\Traits\VmwareTestMockTrait;

/**
 * Base Test Case class for Vmware.
 */
abstract class VmwareTestBase extends CloudTestBase {

  use VmwareTestEntityTrait;
  use VmwareTestFormDataTrait;
  use VmwareTestMockTrait;

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = [
    'cloud',
    'vmware',
  ];

  /**
   * Set up test.
   *
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  protected function setUp() {

    parent::setUp();

    $this->init(__CLASS__, $this);
  }

  /**
   * Create cloud context.
   *
   * @param string $bundle
   *   The CloudConfig Bundle Type ('vmware').
   *
   * @return \Drupal\cloud\Entity\CloudConfig
   *   The cloud service provider (CloudConfig) entity.
   */
  protected function createCloudContext($bundle = 'vmware'): CloudContentEntityBase {
    $random = $this->random;
    $this->cloudContext = $random->name(8);
    return $this->createTestEntity(CloudConfig::class, [
      'type'                    => $bundle,
      'cloud_context'           => $this->cloudContext,
      'name'                    => sprintf('Vmware - %s - %s', date('Y/m/d H:i:s'), $random->name(8, TRUE)),
      'field_vcenter_url'       => $random->name(32, TRUE),
      'field_vcenter_username'  => $random->name(32, TRUE),
      'field_vcenter_password'  => $random->name(32, TRUE),
    ]);
  }

  /**
   * Test bulk operation for entities.
   *
   * @param string $type
   *   The name of the entity type. For example, instance.
   * @param array $entities
   *   The data of entities.
   * @param string $operation
   *   The operation.
   * @param string $passive_operation
   *   The passive voice of operation.
   * @param string $path_prefix
   *   The URL path of prefix.
   *
   * @throws \Behat\Mink\Exception\ExpectationException
   * @throws \Behat\Mink\Exception\ResponseTextException
   */
  protected function runTestEntityBulk(
    $type,
    array $entities,
    $operation = 'delete',
    $passive_operation = 'deleted',
    $path_prefix = '/clouds/vmware'): void {

    $this->runTestEntityBulkImpl(
      $type,
      $entities,
      $operation,
      $passive_operation,
      $path_prefix
    );
  }

}
+45
Changes for modules/cloud_service_providers/vmware/tests/src/Functional/VmwareVmTest.php: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\vmware\Functional;

use Drupal\Tests\cloud\Traits\CloudConfigTestEntityTrait;

/**
 * Tests Vmware VM.
 *
 * @group Vmware
 */
class VmwareVmTest extends VmwareTestBase {

  use CloudConfigTestEntityTrait;

  public const VMWARE_VM_REPEAT_COUNT = 1;

  /**
   * {@inheritdoc}
   */
  protected function getPermissions(): array {
    return [
      'list vmware vm',
      'add vmware vm',
      'view vmware vm',
      'edit vmware vm',
      'delete vmware vm',
    ];
  }

  /**
   * Tests CRUD for VM.
   *
   * @throws \Behat\Mink\Exception\ResponseTextException
   * @throws \Behat\Mink\Exception\ExpectationException
   */
  public function testVm(): void {
    $cloud_context = $this->cloudContext;

    // List VM for VMware.
    $this->drupalGet("/clouds/vmware/$cloud_context/vm");
    $this->assertNoErrorMessage();
  }

}
+14
Changes for modules/cloud_service_providers/vmware/tests/src/Traits/VmwareTestEntityTrait.php: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\vmware\Traits;

use Drupal\Tests\cloud\Traits\CloudTestEntityTrait;

/**
 * The trait creating test entity for vmware testing.
 */
trait VmwareTestEntityTrait {

  use CloudTestEntityTrait;

}
+10
Changes for modules/cloud_service_providers/vmware/tests/src/Traits/VmwareTestMockTrait.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\vmware\Traits;

/**
 * The trait creating mock data for vmware testing.
 */
trait VmwareTestMockTrait {

}