SocialAuthEntityTest.php in Social Auth 8.2
File
tests/src/Kernel/SocialAuthEntityTest.php
View source
<?php
namespace Drupal\Tests\social_auth\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\social_auth\Entity\SocialAuth;
class SocialAuthEntityTest extends EntityKernelTestBase {
protected $entity;
protected $entityStorage;
protected $values = [];
public static $modules = [
'social_api',
'social_auth',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('social_auth');
$this->entityStorage = $this->entityTypeManager
->getStorage('social_auth');
$user = $this
->drupalCreateUser();
$this->values = [
'user_id' => $user
->id(),
'plugin_id' => 'social_auth_provider_test',
'provider_user_id' => 'provider_id_test',
'additional_data' => [
'foo' => 'bar',
],
'token' => 'token_test',
];
$this->entity = $this->entityStorage
->create($this->values);
$this->entity
->save();
}
public function testEntityCreation() {
$entity1 = SocialAuth::create($this->values);
$entity2 = $this->entityStorage
->create($this->values);
$values1 = $entity1
->toArray();
$values2 = $entity2
->toArray();
unset($values1['uuid'], $values2['uuid'], $values1['token'], $values2['token']);
self::assertEquals($values1, $values2);
}
public function testUserId() {
self::assertEquals($this->values['user_id'], $this->entity
->getUserId());
}
public function testAdditionalData() {
self::assertEquals($this->values['additional_data'], $this->entity
->getAdditionalData());
$new_value = [];
$this->entity
->setAdditionalData($new_value);
$this->entity
->save();
self::assertEquals($new_value, $this->entity
->getAdditionalData());
}
}