Commit ae6e7af6 authored by alexpott's avatar alexpott
Browse files

Issue #2372201 by chx: Fixed FakeDelete is missing.

parent 08bf45fc
......@@ -87,6 +87,13 @@ public function update($table, array $options = array()) {
return new FakeUpdate($this->databaseContents, $table);
}
/**
* {@inheritdoc}
*/
public function delete($table, array $options = array()) {
return new FakeDelete($this->databaseContents, $table);
}
/**
* {@inheritdoc}
*/
......
<?php
/**
* @file
* Contains Drupal\Core\Database\Driver\fake\FakeDelete.
*/
namespace Drupal\Core\Database\Driver\fake;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Database\Query\Delete;
use Drupal\Core\Database\Query\SelectInterface;
/**
* Defines FakeDelete for use in database tests.
*/
class FakeDelete extends Delete {
/**
* The database table to delete from.
*
* @var string
*/
protected $table;
/**
* The database contents.
*
* @var array
*/
protected $databaseContents;
/**
* Constructs a FakeDelete object.
*
* @param array $database_contents
* The database contents faked as an array. Each key is a table name, each
* value is a list of table rows.
* @param string $table
* The table to delete from.
*/
public function __construct(array &$database_contents, $table) {
$this->databaseContents = &$database_contents;
$this->table = $table;
$this->condition = new Condition('AND');
}
/**
* {@inheritdoc}
*/
public function execute() {
$affected = 0;
if (isset($this->databaseContents[$this->table])) {
$original_row_count = count($this->databaseContents[$this->table]);
$condition = $this->condition;
$this->databaseContents[$this->table] = array_filter($this->databaseContents[$this->table], function ($row_array) use ($condition) {
$row = new DatabaseRow($row_array);
return !ConditionResolver::matchGroup($row, $condition);
});
$affected = $original_row_count - count($this->databaseContents[$this->table]);
}
return $affected;
}
/**
* {@inheritdoc}
*/
public function exists(SelectInterface $select) {
throw new \Exception(sprintf('Method "%s" is not supported', __METHOD__));
}
/**
* {@inheritdoc}
*/
public function where($snippet, $args = array()) {
throw new \Exception(sprintf('Method "%s" is not supported', __METHOD__));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment