random = $this->getMockBuilder('\OCP\Security\ISecureRandom') ->disableOriginalConstructor()->getMock(); $this->csrfTokenGenerator = new \OC\Security\CSRF\CsrfTokenGenerator($this->random); } public function testGenerateTokenWithCustomNumber() { $this->random ->expects($this->once()) ->method('generate') ->with(3) ->willReturn('abc'); $this->assertSame('abc', $this->csrfTokenGenerator->generateToken(3)); } public function testGenerateTokenWithDefault() { $this->random ->expects($this->once()) ->method('generate') ->with(32) ->willReturn('12345678901234567890123456789012'); $this->assertSame('12345678901234567890123456789012', $this->csrfTokenGenerator->generateToken(32)); } }