PHPackages                             nucivic/dkanextension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. nucivic/dkanextension

ActiveLibrary[Testing &amp; Quality](/categories/testing)

nucivic/dkanextension
=====================

Provides base DKAN class for Drupal Extension

0.2.0(10y ago)231.7k1[5 PRs](https://github.com/GetDKAN/dkanextension/pulls)MITPHP

Since Nov 16Pushed 9y ago19 watchersCompare

[ Source](https://github.com/GetDKAN/dkanextension)[ Packagist](https://packagist.org/packages/nucivic/dkanextension)[ RSS](/packages/nucivic-dkanextension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (17)Used By (0)

**DEPRECATED:** This module has been moved into [DKAN core](https://github.com/NuCivic/dkan) for release 7.x-1.13. To maintain backward compatibility this project will remain on Github but new features will be applied directly to the DKAN core folder `test/dkanextension`.

Behat DKAN Context
==================

[](#behat-dkan-context)

This creates a feature context for DKAN and NuCivic specific steps.

Install
-------

[](#install)

1. Create a `composer.json` file with the following:

```
{
  "require": {
    "nucivic/dkanextension": "dev-master"
  },
  "config": {
    "bin-dir": "bin/"
  },
}
```

2. Install dependencies: `composer install`
3. Initialize: `behat --init`

Contexts
--------

[](#contexts)

DKANExtension ships with a bunch of "Contexts" or Classes that Behat uses to add step functions or other functionality. By default, none of those contexts are loaded. You need to add each context that you want to use to your `behat.yml` file. Here is an example where we add all the contexts, but you can instead choose to only load the ones you want. This can be very useful if you want to override one of these contexts and use your custom version instead. If you've used the DrupalExtension, which DKANExtension depends on, it works the same way.

### Setting up your behat.yml

[](#setting-up-your-behatyml)

```
default:
  suites:
     default:
        contexts:
          - FeatureContext
          # Load the Drupal Context from DrupalExtension
          - Drupal\DrupalExtension\Context\DrupalContext
          # Load the generic DKAN context
          - Drupal\DKANExtension\Context\DKANContext
          # Load DKAN Groups functionality
          - Drupal\DKANExtension\Context\GroupContext
          # Load DevinciExtension debug functionality
          - Devinci\DevinciExtension\Context\DebugContext:
              asset_dump_path: %paths.base%/../assets/
          # Set the default max wait time when testing JS "wait for.." tests.
          - Devinci\DevinciExtension\Context\JavascriptContext:
              maximum_wait: 30
...
```

### Contexts Available

[](#contexts-available)

All contexts are in the src/Drupal/DKANExtension/Context folder. We're only showing the contexts that you'll consider loading in your behat.yml and only the custom steps they provide.

#### DKANContext.php

[](#dkancontextphp)

The generic context that holds some helper steps

- Sets the default php timezone to `date_default_timezone_set('America/New_York');`
- `@When I search for :term`
- `@Then /^I should see the administration menu$/`
- `@Then /^I should have an "([^"]*)" text format option$/`

#### DKANDataStoryContext.php

[](#dkandatastorycontextphp)

[Extends RawDKANEntityContext](#about-rawdkanentitycontext)

- `@Given data stories:`

    ```
    Data Story Field Mappings:
    'title' => 'title' - Title of the data story (string)
    'author' => 'author' - Author of the data story (username)
    'status' => 'status', - Is this published or not ('Yes', 'No')
    'description' => 'body' - Description of the data story (string)
    'tags' => 'field_tags' - Tags (comma separated strings)

    ```

    **Examples:**

    ```
    Given data stories:
      | author    | title     | description       | status | tags     |
      | TestUser  | Story 01  | Some Description  | Yes    | some tag |
    And I am on the "Story 01" page
    ```

#### DataDashboardContext.php

[](#datadashboardcontextphp)

[Extends RawDKANEntityContext](#about-rawdkanentitycontext)

- `@Given data dashboards:`

    ```
    Dashboard Field Mappings:
    'title' => 'title' - Title of the Data Dashboard (string)

    ```

    **Examples:**

    ```
    Given data dashboards:
      | title         |
      | Dashboard 01  |
    ```

#### DatasetContext.php

[](#datasetcontextphp)

[Extends RawDKANEntityContext](#about-rawdkanentitycontext)

- `@Given datasets:`

    ```
    Dataset Field Mappings:
    'author' => 'author' - author of the Dataset (username)
    'title' => 'title' - Dataset title (string)
    'description' => 'body' - Dataset description (string)
    'publisher' => 'og_group_ref' - Group name (string)
    'published' => 'status' - Published? ('Yes', 'No')
    'tags' => 'field_tags' - Tags to add (comma separated strings)

    ```

    **Examples:**

    ```
    Given groups:
      | author    | title     | published     |
      | TestUser  | Group 01  | Yes           |
    Given datasets:
      | author    | title       | description       | publisher  | published | tags     |
      | TestUser  | Dataset 01  | Some Description  | Group 01   | Yes       | some tag |
    And I am on the "Dataset 01" page
    ```
- `@Then I should see a dataset called :text`

    - `:text` - Title of the dataset (string)

    **Examples:**

    ```
    Given groups:
      | author    | title     | published     |
      | TestUser  | Group 01  | Yes           |
    Given datasets:
      | author    | title       | description       | publisher  | published | tags     |
      | TestUser  | Dataset 01  | Some Description  | Group 01   | Yes       | some tag |
    And I am on the "Group 01" page
    Then I should see a dataset called "Dataset 01"
    ```
- `@Then the Dataset search updates behind the scenes`

    (Deprecated)

#### GroupContext.php

[](#groupcontextphp)

[Extends RawDKANEntityContext](#about-rawdkanentitycontext)

- `@Given groups:`

    ```
    Group Field Mappings:
    'author' => 'author' -  Author of the Group (username)
    'title' => 'title' - Group Name (string)
    'published' => 'status' - Published? ('Yes', 'No')

    ```

    **Examples:**

    ```
    Given groups:
      | author    | title     | published     |
      | TestUser  | Group 01  | Yes           |
    And I am on the "Group 01" page
    ```
- `@Given group memberships:`

    *Assigns users as members of a group with specific roles.*

    ```
    Table fields:
    'user' - (username)
    'group' - Group Name (string)
    'role on group' - ('administrator member', 'member')
    'membership status' - What is the user's group status? ('Active')

    ```

    **Examples:**

    ```
    Given groups:
      | author    | title     | published     |
      | TestUser  | Group 01  | Yes           |
    Given group memberships
      | user       | group     | role on group        | membership status |
      | TestUser   | Group 01  | administrator member | Active            |
    ```
- `@Given /^I am a "([^"]*)" of the group "([^"]*)"$/`

    *Grants the given role to the current user, for the given group.*

    - `:role` - role on group. See `@Given group memberships:`
    - `:group` - Group name (string)

    **Examples:**

    ```
    Given groups:
      | author    | title     | published     |
      | TestUser  | Group 01  | Yes           |
    And I am a "administrator member" of the group "Group 01"
    ```

#### MailContext.php

[](#mailcontextphp)

- Creates the @mail tag for use when testing email notifications in your scenario

(currently no additinal steps)

#### PageContext.php

[](#pagecontextphp)

- `@Given pages:`

    ```
    Table Fields:
    title - Page Name (string) -- Must be unique per scenario.
    url - Relative Path ('/my-page') or full url ('https://facebook.com')

    ```

    **Examples:**

    ```
    @Given pages:
      | title        | url    |
      | Content List | /node  |
    ```
- `@Given I am on (the) :page page`

    *Changes the current page. Knows about pages created by other contexts, like GroupContext as well.*

    - `:page` - title of the page created by `@Given Pages` or one of the other contexts that integrate with PageContext.

    **Examples:**

    Manually Created Pages:

    ```
    Given pages:
      | title        | url    |
      | Content List | /node  |
    And I am on the "Content List" page
    Then I should see "Content"
    ```

    Use pages created by other contexts.

    ```
    Given groups:
      | author    | title     | published     |
      | TestUser  | Group 01  | Yes           |
    And I am on the "Group 01" page
    ```

#### ResourceContext.php

[](#resourcecontextphp)

[Extends RawDKANEntityContext](#about-rawdkanentitycontext)

- `@Given resources:`

    ```
    Resource Field Mappings:
    'author' => 'author' - Username of user (string)
    'title' => 'title' - Resource title (string)
    'description' => 'body' - Resource Description (string)
    'publisher' => 'og_group_ref' - Group name (string)
    'published' => 'status' - ('Yes', 'No')
    'resource format' => 'field_format' - ('CSV', 'XML')
    'dataset' => 'field_dataset_ref' - Dataset name (string)

    ```

About RawDKANEntityContext
--------------------------

[](#about-rawdkanentitycontext)

RawDKANEntityContext is a base Class that the other Content/Entity contexts extend from. It can be used to easily create new contexts for content that have a following features:

- Automatic Deletion of content on teardown.
- Handles any entity (nodes+)
- Creates "pages" in the PageContext so that you can navigate to an item after it's created.
- Handles mapping of "human" field labels to drupal field names and handles adding entities with Tables.
- Handles author mapping of username to uid.
- Uses entity api metadata wrappers throughout, making it easier to set fields in a consistent way.
- Keeps a list of created entities in $entities\[$id\] for teardown and other uses like finding an entity by name.

You should use the existing "entity contexts", or create a new one for your project instead of the DrupalExtension's `@Given content:` which lacks most of these features. Because the entity api needs to be bootstrapped, you can only use the 'drupal driver', not 'drush' or 'blackbox' when using relevant steps.

### Creating a new Entity Context

[](#creating-a-new-entity-context)

To create a new Context for any entity (and nodes), create a new context in your /bootstrap folder. For this example, we'll pretend the entity is a node type called "myentity". Call the file MyEntityContext.php (where MyEntity is the name of your entity.) You can use this template to get started.

```
