Chris@0: key = Crypt::randomBytesBase64(55); Chris@0: Chris@0: $this->state = $this->getMock('Drupal\Core\State\StateInterface'); Chris@0: Chris@0: $this->privateKey = new PrivateKey($this->state); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests PrivateKey::get(). Chris@0: */ Chris@0: public function testGet() { Chris@0: $this->state->expects($this->once()) Chris@0: ->method('get') Chris@0: ->with('system.private_key') Chris@0: ->will($this->returnValue($this->key)); Chris@0: Chris@0: $this->assertEquals($this->key, $this->privateKey->get()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests PrivateKey::get() with no private key from state. Chris@0: */ Chris@0: public function testGetNoState() { Chris@0: $this->assertInternalType('string', $this->privateKey->get()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests PrivateKey::setPrivateKey(). Chris@0: */ Chris@0: public function testSet() { Chris@0: $random_name = $this->randomMachineName(); Chris@0: Chris@0: $this->state->expects($this->once()) Chris@0: ->method('set') Chris@0: ->with('system.private_key', $random_name) Chris@0: ->will($this->returnValue(TRUE)); Chris@0: Chris@0: $this->privateKey->set($random_name); Chris@0: } Chris@0: Chris@0: }