/** * @covers ::preSave */ public function testPreSave() { // This method is internal, so check for errors on calling it only. $storage = $this->getMock('\\Drupal\\Core\\Entity\\EntityStorageInterface'); // Our mocked entity->preSave() returns NULL, so assert that. $this->assertNull($this->entity->preSave($storage)); }
/** * @covers ::preSave */ public function testPreSaveDuringSync() { $query = $this->getMock('\\Drupal\\Core\\Entity\\Query\\QueryInterface'); $storage = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface'); $query->expects($this->any())->method('execute')->will($this->returnValue(array())); $query->expects($this->any())->method('condition')->will($this->returnValue($query)); $storage->expects($this->any())->method('getQuery')->will($this->returnValue($query)); $storage->expects($this->any())->method('loadUnchanged')->will($this->returnValue($this->entity)); // Saving an entity will not reset the dependencies array during config // synchronization. $this->entity->set('dependencies', array('module' => array('node'))); $this->entity->preSave($storage); $this->assertEmpty($this->entity->getDependencies()); $this->entity->setSyncing(TRUE); $this->entity->set('dependencies', array('module' => array('node'))); $this->entity->preSave($storage); $dependencies = $this->entity->getDependencies(); $this->assertContains('node', $dependencies['module']); }