PrivateKeyTest.php in Drupal 9
File
core/tests/Drupal/Tests/Core/PrivateKeyTest.php
View source
<?php
namespace Drupal\Tests\Core;
use Drupal\Core\PrivateKey;
use Drupal\Tests\UnitTestCase;
use Drupal\Component\Utility\Crypt;
class PrivateKeyTest extends UnitTestCase {
protected $state;
protected $privateKey;
protected $key;
protected function setUp() : void {
parent::setUp();
$this->key = Crypt::randomBytesBase64(55);
$this->state = $this
->createMock('Drupal\\Core\\State\\StateInterface');
$this->privateKey = new PrivateKey($this->state);
}
public function testGet() {
$this->state
->expects($this
->once())
->method('get')
->with('system.private_key')
->will($this
->returnValue($this->key));
$this
->assertEquals($this->key, $this->privateKey
->get());
}
public function testGetNoState() {
$this
->assertIsString($this->privateKey
->get());
}
public function testSet() {
$random_name = $this
->randomMachineName();
$this->state
->expects($this
->once())
->method('set')
->with('system.private_key', $random_name)
->will($this
->returnValue(TRUE));
$this->privateKey
->set($random_name);
}
}