<?php
namespace Drupal\custom_block\Tests;
use Drupal\translation_entity\Tests\EntityTranslationUITest;
use Drupal\custom_block\Plugin\Core\Entity\CustomBlock;
class CustomBlockTranslationUITest extends EntityTranslationUITest {
protected $name;
public static $modules = array(
'language',
'translation_entity',
'block',
'field_ui',
'custom_block',
);
public static function getInfo() {
return array(
'name' => 'Custom Block translation UI',
'description' => 'Tests the node translation UI.',
'group' => 'Custom Block',
);
}
public function setUp() {
$this->entityType = 'custom_block';
$this->bundle = 'basic';
$this->name = drupal_strtolower($this
->randomName());
$this->testLanguageSelector = FALSE;
parent::setUp();
}
public function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array(
'translate any entity',
'access administration pages',
'administer blocks',
'administer custom_block fields',
));
}
protected function createCustomBlock($title = FALSE, $bundle = FALSE) {
$title = $title ?: $this
->randomName();
$bundle = $bundle ?: $this->bundle;
$custom_block = entity_create('custom_block', array(
'info' => $title,
'type' => $bundle,
'langcode' => 'en',
));
$custom_block
->save();
return $custom_block;
}
protected function getNewEntityValues($langcode) {
return array(
'info' => $this->name,
) + parent::getNewEntityValues($langcode);
}
public function testDisabledBundle() {
$disabled_bundle = $this
->randomName();
$bundle = entity_create('custom_block_type', array(
'id' => $disabled_bundle,
'label' => $disabled_bundle,
'revision' => FALSE,
));
$bundle
->save();
$enabled_custom_block = $this
->createCustomBlock();
$disabled_custom_block = $this
->createCustomBlock(FALSE, $bundle
->id());
$rows = db_query('SELECT * FROM {translation_entity}')
->fetchAll();
$this
->assertEqual(1, count($rows));
$this
->assertEqual($enabled_custom_block
->id(), reset($rows)->entity_id);
}
}