HashTest.php in Tamper 8
File
tests/src/Unit/Plugin/Tamper/HashTest.php
View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\tamper\Exception\TamperException;
use Drupal\tamper\Plugin\Tamper\Hash;
use Drupal\tamper\TamperableItemInterface;
class HashTest extends TamperPluginTestBase {
protected function instantiatePlugin() {
return new Hash([], 'hash', [], $this
->getMockSourceDefinition());
}
protected function getMockItem() {
$item = $this
->createMock(TamperableItemInterface::class);
$item
->expects($this
->any())
->method('getSource')
->willReturn([
'title' => 'Yay title!',
'body' => 'Yay body!',
'foo' => 'bar',
]);
return $item;
}
public function testHash() {
$hashed_values = md5(serialize([
'title' => 'Yay title!',
'body' => 'Yay body!',
'foo' => 'bar',
]));
$this
->assertEquals($hashed_values, $this->plugin
->tamper('', $this
->getMockItem()));
$this
->assertEquals('foo', $this->plugin
->tamper('foo', $this
->getMockItem()));
}
public function testHashWithOverride() {
$plugin = new Hash([
Hash::SETTING_OVERRIDE => TRUE,
], 'hash', [], $this
->getMockSourceDefinition());
$hashed_values = md5(serialize([
'title' => 'Yay title!',
'body' => 'Yay body!',
'foo' => 'bar',
]));
$this
->assertEquals($hashed_values, $plugin
->tamper('', $this
->getMockItem()));
$this
->assertEquals($hashed_values, $plugin
->tamper('foo', $this
->getMockItem()));
}
public function testEmptyTamperableItem() {
$this
->expectException(TamperException::class);
$this
->expectExceptionMessage('Tamperable item can not be null.');
$this->plugin
->tamper('foo');
}
}