NodeFieldOverridesTest.php in Zircon Profile 8
File
core/modules/node/src/Tests/NodeFieldOverridesTest.php
View source
<?php
namespace Drupal\node\Tests;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
class NodeFieldOverridesTest extends EntityUnitTestBase {
protected $user;
public static $modules = array(
'user',
'system',
'field',
'node',
);
protected function setUp() {
parent::setUp();
$this
->installConfig(array(
'user',
));
$this->user = $this
->createUser();
\Drupal::service('current_user')
->setAccount($this->user);
}
public function testFieldOverrides() {
if (!NodeType::load('ponies')) {
NodeType::create([
'name' => 'Ponies',
'type' => 'ponies',
])
->save();
}
$override = BaseFieldOverride::loadByName('node', 'ponies', 'uid');
if ($override) {
$override
->delete();
}
$uid_field = \Drupal::entityManager()
->getBaseFieldDefinitions('node')['uid'];
$config = $uid_field
->getConfig('ponies');
$config
->save();
$this
->assertEqual($config
->get('default_value_callback'), 'Drupal\\node\\Entity\\Node::getCurrentUserId');
$node = Node::create([
'type' => 'ponies',
]);
$owner = $node
->getOwner();
$this
->assertTrue($owner instanceof \Drupal\user\UserInterface);
$this
->assertEqual($owner
->id(), $this->user
->id());
}
}