cloud-8.x-2.0-beta1/modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceTypePriceControllerTest.php

modules/cloud_service_providers/aws_cloud/tests/src/Functional/Ec2/InstanceTypePriceControllerTest.php
<?php

namespace Drupal\Tests\aws_cloud\Functional\Ec2;

use Drupal\Tests\aws_cloud\Functional\AwsCloudTestCase;

/**
 * Tests AWS Cloud Instance Type Price.
 *
 * @group AWS Cloud
 */
class InstanceTypePriceControllerTest extends AwsCloudTestCase {

  const AWS_CLOUD_PRICE_REPEAT_COUNT = 3;

  /**
   * {@inheritdoc}
   */
  protected function getPermissions() {
    return [
      'view aws cloud instance type prices',
    ];
  }

  /**
   * Tests displaying prices.
   */
  public function testShowPrice() {
    $this->repeatTestShowPrice(self::AWS_CLOUD_PRICE_REPEAT_COUNT);
  }

  /**
   * Repeats testing displaying prices.
   *
   * @param int $max_test_repeat_count
   *   Max test repeating count.
   */
  private function repeatTestShowPrice($max_test_repeat_count = 1) {
    $cloud_context = $this->cloudContext;
    for ($i = 0; $i < $max_test_repeat_count; $i++) {
      $this->drupalGet("/clouds/aws_cloud/$cloud_context/instance_type_price");

      $this->assertResponse(200);
      $this->assertText(t('AWS Cloud Instance Type Prices'));
      foreach (aws_cloud_get_instance_types($cloud_context) as $instance_type_data) {
        $parts = explode(':', $instance_type_data);
        $this->assertText($parts[0]);
      }
    }
  }

  /**
   * Tests displaying prices.
   */
  public function testUpdatePrice() {
    $cloud_context = $this->cloudContext;
    $instance_types = aws_cloud_get_instance_types($cloud_context);

    $this->drupalGet("/clouds/aws_cloud/$cloud_context/instance_type_price");

    $this->assertResponse(200);
    $this->assertText(t('AWS Cloud Instance Type Prices'));
    foreach ($instance_types as $instance_type_data) {
      $parts = explode(':', $instance_type_data);
      $this->assertText($parts[0]);
    }

    // Reset the  cache.
    $cloud_config_plugin = \Drupal::service('plugin.manager.cloud_config_plugin');
    $cloud_config_plugin->setCloudContext($cloud_context);
    $cloud_config = $cloud_config_plugin->loadConfigEntity();
    $cache_key = _aws_cloud_get_instance_type_cache_key_by_region($cloud_config->get('field_region')->value);
    \Drupal::cache()->set($cache_key, []);

    \Drupal::service('router.builder')->rebuild();

    $this->drupalGet("/clouds/aws_cloud/$cloud_context/instance_type_price");
    $this->assertResponse(200);
    $this->assertText(t('AWS Cloud Instance Type Prices'));
    foreach ($instance_types as $instance_type_data) {
      $parts = explode(':', $instance_type_data);
      $this->assertNoText($parts[0]);
    }

    // Click 'Refresh'.
    $this->clickLink(t('Refresh'));
    $this->assertText(t('Updated Instance Type Prices.'));
    $this->assertResponse(200);
    $this->assertText(t('AWS Cloud Instance Type Prices'));
    $new_instance_types = aws_cloud_get_instance_types($cloud_context);
    foreach ($new_instance_types as $instance_type_data) {
      $parts = explode(':', $instance_type_data);
      $this->assertText($parts[0]);
    }
  }

}

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

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