You are here

public function SerializationTest::testItemCloning in Search API 8

Tests that cloning of items works correctly.

File

tests/src/Kernel/System/SerializationTest.php, line 226

Class

SerializationTest
Tests that various classes can be properly serialized and/or cloned.

Namespace

Drupal\Tests\search_api\Kernel\System

Code

public function testItemCloning() {
  $item = $this
    ->createTestItem();
  $clone = clone $item;
  $item
    ->setBoost(3);
  $item
    ->setExcerpt('Test 1');
  $item
    ->getExtraData('foo')->bar = 2;
  $item
    ->setExtraData('test', 3);
  $item
    ->setLanguage('de');
  $item
    ->setScore(3.14);
  $item
    ->getField('test')
    ->setLabel('Foobar');
  $item_2 = $this
    ->createTestItem();
  $this
    ->assertEquals($item_2, $clone);
  $this
    ->assertNotSame($item
    ->getExtraData('foo'), $clone
    ->getExtraData('foo'));
  $this
    ->assertNotSame($item
    ->getField('test'), $clone
    ->getField('test'));
  $this
    ->assertNotSame($item
    ->getField('foo'), $clone
    ->getField('foo'));
}