Commit 6ef87658 authored by Dries's avatar Dries
Browse files

Issue #1790882 by beejeebus, sun: allow to store value FALSE in the key value store.

parent 6da30cc2
...@@ -35,7 +35,7 @@ public function getCollectionName() { ...@@ -35,7 +35,7 @@ public function getCollectionName() {
*/ */
public function get($key) { public function get($key) {
$values = $this->getMultiple(array($key)); $values = $this->getMultiple(array($key));
return reset($values); return isset($values[$key]) ? $values[$key] : NULL;
} }
/** /**
......
...@@ -37,7 +37,7 @@ public function getCollectionName(); ...@@ -37,7 +37,7 @@ public function getCollectionName();
* The key of the data to retrieve. * The key of the data to retrieve.
* *
* @return mixed * @return mixed
* The stored value, or FALSE if no value exists. * The stored value, or NULL if no value exists.
*/ */
public function get($key); public function get($key);
......
...@@ -39,7 +39,7 @@ public function getCollectionName() { ...@@ -39,7 +39,7 @@ public function getCollectionName() {
* Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get(). * Implements Drupal\Core\KeyValueStore\KeyValueStoreInterface::get().
*/ */
public function get($key) { public function get($key) {
return array_key_exists($key, $this->data) ? $this->data[$key] : FALSE; return array_key_exists($key, $this->data) ? $this->data[$key] : NULL;
} }
/** /**
......
...@@ -36,32 +36,32 @@ protected function setUp() { ...@@ -36,32 +36,32 @@ protected function setUp() {
*/ */
public function testCRUD() { public function testCRUD() {
// Verify that each store returns its own collection name. // Verify that each store returns its own collection name.
$this->assertEqual($this->store1->getCollectionName(), $this->collection1); $this->assertIdentical($this->store1->getCollectionName(), $this->collection1);
$this->assertEqual($this->store2->getCollectionName(), $this->collection2); $this->assertIdentical($this->store2->getCollectionName(), $this->collection2);
// Verify that an item can be stored. // Verify that an item can be stored.
$this->store1->set('foo', 'bar'); $this->store1->set('foo', 'bar');
$this->assertEqual('bar', $this->store1->get('foo')); $this->assertIdentical('bar', $this->store1->get('foo'));
// Verify that the other collection is not affected. // Verify that the other collection is not affected.
$this->assertFalse($this->store2->get('foo')); $this->assertFalse($this->store2->get('foo'));
// Verify that an item can be updated. // Verify that an item can be updated.
$this->store1->set('foo', 'baz'); $this->store1->set('foo', 'baz');
$this->assertEqual('baz', $this->store1->get('foo')); $this->assertIdentical('baz', $this->store1->get('foo'));
// Verify that the other collection is still not affected. // Verify that the other collection is still not affected.
$this->assertFalse($this->store2->get('foo')); $this->assertFalse($this->store2->get('foo'));
// Verify that a collection/name pair is unique. // Verify that a collection/name pair is unique.
$this->store2->set('foo', 'other'); $this->store2->set('foo', 'other');
$this->assertEqual('baz', $this->store1->get('foo')); $this->assertIdentical('baz', $this->store1->get('foo'));
$this->assertEqual('other', $this->store2->get('foo')); $this->assertIdentical('other', $this->store2->get('foo'));
// Verify that an item can be deleted. // Verify that an item can be deleted.
$this->store1->delete('foo'); $this->store1->delete('foo');
$this->assertFalse($this->store1->get('foo')); $this->assertFalse($this->store1->get('foo'));
// Verify that the other collection is not affected. // Verify that the other collection is not affected.
$this->assertEqual('other', $this->store2->get('foo')); $this->assertIdentical('other', $this->store2->get('foo'));
$this->store2->delete('foo'); $this->store2->delete('foo');
$this->assertFalse($this->store2->get('foo')); $this->assertFalse($this->store2->get('foo'));
...@@ -74,7 +74,7 @@ public function testCRUD() { ...@@ -74,7 +74,7 @@ public function testCRUD() {
// Verify that multiple items can be retrieved. // Verify that multiple items can be retrieved.
$result = $this->store1->getMultiple(array('foo', 'baz')); $result = $this->store1->getMultiple(array('foo', 'baz'));
$this->assertEqual($values, $result); $this->assertIdentical($values, $result);
// Verify that the other collection was not affected. // Verify that the other collection was not affected.
$this->assertFalse($this->store2->get('foo')); $this->assertFalse($this->store2->get('foo'));
...@@ -99,6 +99,28 @@ public function testCRUD() { ...@@ -99,6 +99,28 @@ public function testCRUD() {
$this->assertFalse($this->store1->get('bar')); $this->assertFalse($this->store1->get('bar'));
$this->assertFalse($this->store1->getMultiple(array('foo', 'baz'))); $this->assertFalse($this->store1->getMultiple(array('foo', 'baz')));
// Verify that the item in the other collection still exists. // Verify that the item in the other collection still exists.
$this->assertEqual('other', $this->store2->get('foo')); $this->assertIdentical('other', $this->store2->get('foo'));
}
/**
* Tests expected behavior for non-existing keys.
*/
public function testNonExistingKeys() {
// Verify that a non-existing key returns NULL as value.
$this->assertNull($this->store1->get('foo'));
// Verify that a FALSE value can be stored.
$this->store1->set('foo', FALSE);
$this->assertIdentical($this->store1->get('foo'), FALSE);
// Verify that a deleted key returns NULL as value.
$this->store1->delete('foo');
$this->assertNull($this->store1->get('foo'));
// Verify that a non-existing key is not returned when getting multiple keys.
$this->store1->set('bar', 'baz');
$values = $this->store1->getMultiple(array('foo', 'bar'));
$this->assertFalse(isset($values['foo']), "Key 'foo' not found.");
$this->assertIdentical($values['bar'], 'baz');
} }
} }
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