public function ProxyItemTest::testGet in Purge 8.3
Tests \Drupal\purge\Plugin\Purge\Queue\ProxyItem::__get.
File
- tests/
src/ Kernel/ Queue/ ProxyItemTest.php, line 41
Class
- ProxyItemTest
- Tests \Drupal\purge\Tests\Queue\ProxyItem.
Namespace
Drupal\Tests\purge\Kernel\QueueCode
public function testGet() : void {
$i = $this
->getInvalidations(1);
$i
->setStateContext('a');
$i
->setState(InvalidationInterface::PROCESSING);
$i
->setProperty('foo', 'bar');
$i
->setStateContext(NULL);
$p = new ProxyItem($i, $this->buffer);
$this->buffer
->set($i, TxBuffer::CLAIMED);
// Test the 'item_id' property and changing it directly on the buffer.
$this
->assertNull($p->item_id);
$this->buffer
->setProperty($i, 'item_id', '5');
$this
->assertEquals('5', $p->item_id);
$this->buffer
->delete($i);
$this
->assertNull($p->item_id);
$this->buffer
->set($i, TxBuffer::CLAIMED);
$this
->assertNull($p->item_id);
// Test the 'data' array property and its peculiar format.
$this
->assertTrue(is_array($p->data));
$this
->assertEquals($i
->getPluginId(), $p->data[ProxyItem::DATA_INDEX_TYPE]);
$this
->assertEquals($i
->getType(), $p->data[ProxyItem::DATA_INDEX_TYPE]);
$this
->assertTrue(is_array($p->data[ProxyItem::DATA_INDEX_STATES]));
$this
->assertEquals(1, count($p->data[ProxyItem::DATA_INDEX_STATES]));
$this
->assertTrue(isset($p->data[ProxyItem::DATA_INDEX_STATES]['a']));
$this
->assertEquals(InvalidationInterface::PROCESSING, $p->data[ProxyItem::DATA_INDEX_STATES]['a']);
$this
->assertEquals($i
->getExpression(), $p->data[ProxyItem::DATA_INDEX_EXPRESSION]);
$this
->assertTrue(isset($p->data[ProxyItem::DATA_INDEX_PROPERTIES]['a']['foo']));
$this
->assertEquals('bar', $p->data[ProxyItem::DATA_INDEX_PROPERTIES]['a']['foo']);
// Test the 'created' property and changing it directly on the buffer.
$this
->assertNull($p->created);
$this->buffer
->setProperty($i, 'created', 123456789);
$this
->assertEquals(123456789, $p->created);
// Test that bad properties throw a InvalidPropertyException as expected.
foreach ([
'properties',
'buffer',
'test',
] as $property) {
$thrown = FALSE;
try {
$p->{$property};
} catch (InvalidPropertyException $e) {
$thrown = TRUE;
}
$this
->assertTrue($thrown);
}
}