RewriteTest.php in Tamper 8
File
tests/src/Unit/Plugin/Tamper/RewriteTest.php
View source
<?php
namespace Drupal\Tests\tamper\Unit\Plugin\Tamper;
use Drupal\tamper\Plugin\Tamper\Rewrite;
use Drupal\tamper\TamperableItemInterface;
class RewriteTest extends TamperPluginTestBase {
protected function instantiatePlugin() {
$config = [
Rewrite::SETTING_TEXT => '[title] - [body]',
];
return new Rewrite($config, 'rewrite', [], $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 testRewrite() {
$this
->assertEquals('Yay title! - Yay body!', $this->plugin
->tamper('foo', $this
->getMockItem()));
}
public function testWithoutTamperableItem() {
$this
->assertEquals('foo', $this
->instantiatePlugin()
->tamper('foo'));
}
}