Skip to content

Commit

Permalink
Issue #3113463 by mtift: Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mtift committed Feb 14, 2020
1 parent ae74210 commit 389bf0f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
58 changes: 58 additions & 0 deletions npr_api/tests/src/Functional/NprApiSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Drupal\Tests\npr_api\Functional;

use Drupal\Tests\BrowserTestBase;

/**
* Test the NPR API Settings form.
*
* @group npr
*/
class NprApiSettingsTest extends BrowserTestBase {

/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['npr_api'];

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* An admin user with permission to administer the NPR API.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();

$this->adminUser = $this->drupalCreateUser([
'administer npr api',
]);
}

/**
* Test the NPR API Settings form.
*/
public function testNprApiSettingsForm() {

// Login as as an admin user.
$this->drupalLogin($this->adminUser);

// Make sure the option exists to select a story node.
$this->drupalGet('admin/config/services/npr/api_config');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('NPR API production URL');
}

}
1 change: 1 addition & 0 deletions npr_story/npr_story.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ package: NPR
type: module
configure: npr_story.config_form
dependencies:
- drupal:media
- npr:npr_api
23 changes: 20 additions & 3 deletions npr_story/tests/src/Functional/NprStoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NprStoryTest extends BrowserTestBase {
*
* @var array
*/
public static $modules = ['npr_api', 'npr_story'];
public static $modules = ['npr_api', 'npr_story', 'media', 'node'];

/**
* An admin user with permission to administer the NPR API.
Expand All @@ -36,20 +36,37 @@ class NprStoryTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();

// Use article as a node to test that nodes can be configured.
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);

$this->adminUser = $this->drupalCreateUser([
'administer npr api',
]);

}

/**
* Test npr_story functionality.
*/
public function testNprStory() {

$story_config_path = 'admin/config/services/npr/story_config';

// Login as as an admin user.
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/config/services/npr/story_config');

// Check for the message that appears when no story node type is selected.
$this->drupalGet($story_config_path);
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Select and save Drupal story node type to choose field mappings');

// Check for dropdown messages when a content type is selected.
$edit = [
'story_node_type' => 'article',
];
$this->drupalPostForm($story_config_path, $edit, 'Save configuration');
$this->assertSession()->pageTextContains('id');
$this->assertSession()->pageTextContains('body');
$this->assertSession()->pageTextContains('byline');

}

Expand Down

0 comments on commit 389bf0f

Please sign in to comment.