KeyRepositoryAvailableTest.php in Akamai 8.3        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Kernel/KeyRepositoryAvailableTest.php
  
    View source  
  <?php
namespace Drupal\Tests\akamai\Kernel;
use Drupal\KernelTests\KernelTestBase;
class KeyRepositoryAvailableTest extends KernelTestBase {
  
  public static $modules = [
    'akamai',
    'key',
  ];
  
  protected function setUp() {
    parent::setUp();
    $this
      ->installConfig([
      'akamai',
      'key',
    ]);
    $this
      ->generateKeys();
  }
  
  protected function generateKeys() {
    $this->container
      ->get('entity_type.manager')
      ->getStorage('key')
      ->create([
      'id' => 'my_key',
      'label' => 'My Key',
      'key_provider_settings' => [
        'key_value' => 'Super secret value',
      ],
    ])
      ->save();
    $this->container
      ->get('entity_type.manager')
      ->getStorage('key')
      ->create([
      'id' => 'second_key',
      'label' => 'Second Key',
      'key_provider_settings' => [
        'key_value' => 'Yet another key',
      ],
    ])
      ->save();
  }
  
  public function testHasKeyRepositoryIsTrue() {
    $this
      ->assertTrue($this->container
      ->get('akamai.key_provider')
      ->hasKeyRepository());
  }
  
  public function testKeyProviderCanGetKeys() {
    $keys = $this->container
      ->get('akamai.key_provider')
      ->getKeys();
    $this
      ->assertEquals($keys['my_key']
      ->label(), 'My Key');
    $this
      ->assertEquals($keys['my_key']
      ->getKeyValue(), 'Super secret value');
    $this
      ->assertEquals($keys['second_key']
      ->label(), 'Second Key');
    $this
      ->assertEquals($keys['second_key']
      ->getKeyValue(), 'Yet another key');
  }
  
  public function testCanGetSpecificKey() {
    $this
      ->assertEquals($this->container
      ->get('akamai.key_provider')
      ->getKey('second_key'), 'Yet another key');
  }
  
  public function testInvalidKeyIsNull() {
    $this
      ->assertNull($this->container
      ->get('akamai.key_provider')
      ->getKey('some_invalid_key'));
  }
}