Add a test for if a post has a tweet
This commit is contained in:
parent
3050b53d7d
commit
d7aaeb0ca6
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\custom\Entity\Node;
|
||||
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\discoverable_entity_bundle_classes\ContentEntityBundleInterface;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
* Defines an blog post node class.
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.node.field_has_tweet
|
||||
- node.type.post
|
||||
id: node.post.field_has_tweet
|
||||
field_name: field_has_tweet
|
||||
entity_type: node
|
||||
bundle: post
|
||||
label: 'Has tweet'
|
||||
description: 'Check to include Twitter''s widget.js script for this page.'
|
||||
required: false
|
||||
translatable: false
|
||||
default_value:
|
||||
-
|
||||
value: 0
|
||||
default_value_callback: ''
|
||||
settings:
|
||||
on_label: 'Yes'
|
||||
off_label: 'No'
|
||||
field_type: boolean
|
|
@ -0,0 +1,17 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- node
|
||||
id: node.field_has_tweet
|
||||
field_name: field_has_tweet
|
||||
entity_type: node
|
||||
type: boolean
|
||||
settings: { }
|
||||
module: core
|
||||
locked: false
|
||||
cardinality: 1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
|
@ -0,0 +1,11 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
third_party_settings: { }
|
||||
name: 'Blog post'
|
||||
type: post
|
||||
description: 'A single blog post.'
|
||||
help: ''
|
||||
new_revision: true
|
||||
preview_mode: 1
|
||||
display_submitted: true
|
|
@ -0,0 +1,4 @@
|
|||
name: Oliver Davies Posts Test
|
||||
type: module
|
||||
core_version_requirement: ^8 || ^9
|
||||
hidden: true
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\custom\Kernel\Entity\Node;
|
||||
|
||||
use Drupal\custom\Entity\Node\Post;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
final class PostTest extends EntityKernelTestBase {
|
||||
|
||||
public static $modules = [
|
||||
// Core.
|
||||
'node',
|
||||
|
||||
// Contrib.
|
||||
'discoverable_entity_bundle_classes',
|
||||
|
||||
// Custom.
|
||||
'custom',
|
||||
'opdavies_posts_test',
|
||||
];
|
||||
|
||||
/** @test */
|
||||
public function it_can_determine_if_a_post_contains_a_tweet(): void {
|
||||
/** @var Post $post */
|
||||
$post = Node::create(['type' => 'post']);
|
||||
$this->assertFalse($post->hasTweet());
|
||||
|
||||
/** @var Post $post */
|
||||
$post = Node::create([
|
||||
'field_has_tweet' => TRUE,
|
||||
'type' => 'post',
|
||||
]);
|
||||
$this->assertTrue($post->hasTweet());
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(['opdavies_posts_test']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue