3 namespace Drupal\Tests\drupalmoduleupgrader\Unit\Plugin\DMU\Converter\Functions;
8 * @group DMU.Converter.Functions
9 * @covers \Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions\DrupalWriteRecord
11 class DrupalWriteRecordTest extends FunctionCallModifierTestBase {
13 public function testRewriteUpdateArrayKey() {
14 $function_call = Parser::parseExpression('drupal_write_record("foobar", $record, array("id"));');
15 $rewritten = $this->plugin->rewrite($function_call, $this->target);
16 $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
17 $this->assertEquals('\Drupal::database()->merge("foobar")->fields($record)->key(array("id"))->execute()', $rewritten->getText());
20 public function testRewriteUpdateStringKey() {
21 $function_call = Parser::parseExpression('drupal_write_record("foobar", $record, "baz")');
22 $rewritten = $this->plugin->rewrite($function_call, $this->target);
23 $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
24 $this->assertEquals('\Drupal::database()->merge("foobar")->fields($record)->key(["baz"])->execute()', $rewritten->getText());
27 public function testRewriteInsert() {
28 $function_call = Parser::parseExpression('drupal_write_record("foobar", $record)');
29 $rewritten = $this->plugin->rewrite($function_call, $this->target);
30 $this->assertInstanceOf('\Pharborist\Objects\ObjectMethodCallNode', $rewritten);
31 $this->assertEquals('\Drupal::database()->insert("foobar")->fields($record)->execute()', $rewritten->getText());