public function EntitySubjectTest::testNotifyNewEntity in Changed Fields API 8.3
Observer is not notified because node:article is new.
Entity: node:article.
File
- tests/
src/ Unit/ EntitySubjectTest.php, line 235
Class
- EntitySubjectTest
- @coversDefaultClass \Drupal\changed_fields\EntitySubject
Namespace
Drupal\Tests\changed_fields\UnitCode
public function testNotifyNewEntity() {
$observer = $this
->getMockBuilder('Drupal\\changed_fields\\ObserverInterface')
->setMethods([
'getInfo',
'update',
])
->getMock();
$observer
->expects($this
->never())
->method('getInfo');
$observer
->expects($this
->never())
->method('update');
$entity_mock = $this
->getMockBuilder('Drupal\\node\\Entity\\Node')
->disableOriginalConstructor()
->setMethods([
'isNew',
'getEntityTypeId',
'bundle',
])
->getMock();
$entity_mock
->expects($this
->once())
->method('isNew')
->willReturn(TRUE);
$entity_mock
->expects($this
->never())
->method('getEntityTypeId')
->willReturn('node');
$entity_mock
->expects($this
->never())
->method('bundle')
->willReturn('article');
$this
->setProtectedProperty($this->entitySubject, 'entity', $entity_mock);
$this->entitySubject
->attach($observer);
$this->entitySubject
->notify();
$this
->assertTrue($entity_mock === $this->entitySubject
->getEntity());
$this
->assertEquals(NULL, $this->entitySubject
->getChangedFields());
}