public function NodeTest::testNodeCRUD in Audit Log 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/NodeTest.php \Drupal\Tests\audit_log\Functional\NodeTest::testNodeCrud()
Tests audit log functionality on node crud operations.
File
- tests/
src/ Functional/ NodeTest.php, line 38
Class
- NodeTest
- Tests audit log functionality on node crud operations.
Namespace
Drupal\Tests\audit_log\FunctionalCode
public function testNodeCRUD() {
$count = db_query("SELECT COUNT(id) FROM {audit_log} WHERE entity_type = 'node'")
->fetchField();
$this
->assertEquals(0, $count);
// Initial creation.
$node = Node::create([
'uid' => $this->webUser
->id(),
'type' => 'article',
'title' => 'test_changes',
]);
$node
->save();
$count = db_query("SELECT COUNT(id) FROM {audit_log} WHERE entity_type = 'node'")
->fetchField();
$this
->assertEquals(1, $count);
// Update the node without applying changes.
$node
->save();
$count = db_query("SELECT COUNT(id) FROM {audit_log} WHERE entity_type = 'node'")
->fetchField();
$this
->assertEquals(2, $count);
// Apply changes.
$node->title = 'updated';
$node
->save();
$count = db_query("SELECT COUNT(id) FROM {audit_log} WHERE entity_type = 'node'")
->fetchField();
$this
->assertEquals(3, $count);
$node
->delete();
$count = db_query("SELECT COUNT(id) FROM {audit_log} WHERE entity_type = 'node'")
->fetchField();
$this
->assertEquals(4, $count);
}