You are here

public function SkinrApiTest::testSkinrSkinHooks in Skinr 8.2

Test hook invocations for CRUD operations on skin configurations.

File

src/Tests/SkinrApiTest.php, line 316
Contains \Drupal\skinr\Tests\SkinrApiTest.

Class

SkinrApiTest
Tests Skinr API functionality.

Namespace

Drupal\skinr\Tests

Code

public function testSkinrSkinHooks() {
  $skin = Skin::create(array(
    'theme' => 'skinr_test_subtheme',
    'element_type' => 'block',
    'element' => 'system__user-menu',
    'skin' => 'skinr_test_subtheme',
    'options' => array(
      'option1' => 'option1',
      'option2' => 'option2',
    ),
    'status' => 1,
  ));
  $_SESSION['skinr_test'] = array();
  $skin
    ->save();
  $this
    ->assertHookMessage('skinr_test_skinr_skin_presave called');
  $this
    ->assertHookMessage('skinr_test_skinr_skin_insert called');
  $_SESSION['skinr_test'] = array();
  $skin = Skin::load($skin
    ->id());
  $this
    ->assertHookMessage('skinr_test_skinr_skin_load called');
  $_SESSION['skinr_test'] = array();

  /* @var Skin $skin */
  $skin = \Drupal::entityManager()
    ->getStorage('skin')
    ->loadUnchanged($skin
    ->id());
  $this
    ->assertHookMessage('skinr_test_entity_load called');
  $_SESSION['skinr_test'] = array();
  $skin
    ->setOptions(array(
    'option3' => 'option3',
  ));
  $skin
    ->save();
  $this
    ->assertHookMessage('skinr_test_skinr_skin_presave called');
  $this
    ->assertHookMessage('skinr_test_skinr_skin_update called');
  $_SESSION['skinr_test'] = array();
  $skin
    ->delete();
  $this
    ->assertHookMessage('skinr_test_entity_delete called');
}