View source
<?php
namespace Drupal\Tests\onlyone\Traits;
trait OnlyOneUnitTestTrait {
public function getContentTypesObjectList() {
$content_types = [
[
'page' => [
(object) [
'language' => 'en',
'total' => 1,
'configured' => TRUE,
'name' => 'Basic Page',
],
(object) [
'language' => 'es',
'total' => 1,
'configured' => TRUE,
'name' => 'Basic Page',
],
],
'blog' => [
(object) [
'language' => '',
'total' => 0,
'configured' => TRUE,
'name' => 'Blog Post',
],
],
'car' => [
(object) [
'language' => 'und',
'total' => 1,
'configured' => FALSE,
'name' => 'Car',
],
(object) [
'language' => 'xzz',
'total' => 2,
'configured' => FALSE,
'name' => 'Car',
],
(object) [
'language' => 'en',
'total' => 1,
'configured' => FALSE,
'name' => 'Car',
],
],
'article' => [
(object) [
'language' => 'und',
'total' => 1,
'configured' => FALSE,
'name' => 'Article',
],
(object) [
'language' => 'en',
'total' => 2,
'configured' => FALSE,
'name' => 'Article',
],
(object) [
'language' => 'es',
'total' => 1,
'configured' => FALSE,
'name' => 'Article',
],
],
],
[
'blog' => [
(object) [
'language' => 'en',
'total' => 1,
'configured' => TRUE,
'name' => 'Blog Post',
],
],
'car' => [
(object) [
'language' => '',
'total' => 0,
'configured' => FALSE,
'name' => 'Car',
],
],
],
[
'page' => [
(object) [
'language' => 'en',
'total' => 1,
'configured' => TRUE,
'name' => 'Basic Page',
],
(object) [
'language' => 'es',
'total' => 1,
'configured' => TRUE,
'name' => 'Basic Page',
],
],
'car' => [
(object) [
'language' => '',
'total' => 0,
'configured' => TRUE,
'name' => 'Car',
],
],
'article' => [
(object) [
'language' => 'es',
'total' => 3,
'configured' => FALSE,
'name' => 'Article',
],
],
],
[
'page' => [
(object) [
'total' => 1,
'configured' => TRUE,
'name' => 'Basic Page',
],
],
'blog' => [
(object) [
'total' => 2,
'configured' => TRUE,
'name' => 'Blog Post',
],
],
'car' => [
(object) [
'total' => 0,
'configured' => FALSE,
'name' => 'Car',
],
],
'article' => [
(object) [
'total' => 5,
'configured' => FALSE,
'name' => 'Article',
],
],
],
[
'blog' => [
(object) [
'total' => 0,
'configured' => TRUE,
'name' => 'Blog Post',
],
],
'car' => [
(object) [
'total' => 1,
'configured' => FALSE,
'name' => 'Car',
],
],
],
[
'page' => [
(object) [
'total' => 1,
'configured' => TRUE,
'name' => 'Basic Page',
],
],
'car' => [
(object) [
'total' => 5,
'configured' => TRUE,
'name' => 'Car',
],
],
'article' => [
(object) [
'total' => 3,
'configured' => FALSE,
'name' => 'Article',
],
],
],
];
$language_labels = array_column($this
->getLanguageMap(), 1, 0);
for ($i = 0; $i < 6; $i++) {
foreach ($content_types[$i] as $conten_type => $languages) {
foreach ($languages as $language => $values) {
if ($i < 3) {
$total_nodes = $values->total ? $this
->getStringTranslationStub()
->formatPlural($values->total, '@language: @total Node', '@language: @total Nodes', [
'@language' => $language_labels[$values->language],
'@total' => $values->total,
]) : $this
->getStringTranslationStub()
->translate('0 Nodes');
}
else {
$total_nodes = $values->total ? $this
->getStringTranslationStub()
->formatPlural($values->total, '@total Node', '@total Nodes', [
'@total' => $values->total,
]) : $this
->getStringTranslationStub()
->translate('0 Nodes');
}
$content_types[$i][$conten_type][$language]->total_nodes = $total_nodes;
}
}
}
return $content_types;
}
public function getLanguageMap() {
$language_map = [
[
'en',
'En',
],
[
'es',
'Es',
],
[
'',
'Not specified',
],
[
'und',
'Not specified',
],
[
'xzz',
'Not applicable',
],
];
return $language_map;
}
public function getContentTypesList() {
$content_types_list = [
'page' => 'Basic Page',
'blog' => 'Blog Post',
'car' => 'Car',
'article' => 'Article',
];
return $content_types_list;
}
}