---
url: 'https://metadrop.net/es/articulos/behat3x-pasos-de-interacciones-con-nodos-para-drupal'
title: 'Behat3.x pasos de interacciones con Nodos para Drupal'
author: 'Carlos Montes'
date: '2017-01-27T11:19:10+00:00'
updated: '2026-06-10T07:07:33+00:00'
type: article
summary: 'En esté artículo agregaremos pasos para manipular nuestros nodos de Drupal'
tags:
  - Behat
  - Testing
  - 'Drupal 7'
published: true
og:
  determiner: Automatic
  site_name: Metadrop
  'image:alt': 'Behat3.x pasos de interacciones con Nodos para Drupal'
  street_address: 'Calle Manuel Luna, 12, 3 Dcha'
  locality: Madrid
  region: Madrid
  postal_code: '28020'
  country_name: España
  email: hola@metadrop.net
  phone_number: '910053180'
schema:
  '@context': 'https://schema.org'
  '@graph':
    -
      '@type': Article
      '@id': 'https://metadrop.net/es/articulos/behat3x-pasos-de-interacciones-con-nodos-para-drupal#article'
      name: 'Behat3.x pasos de interacciones con Nodos para Drupal'
      headline: 'Behat3.x pasos de interacciones con Nodos para Drupal'
      description: "En esté artículo agregaremos pasos para manipular nuestros nodos de Drupal \_"
      about:
        - Behat
        - Testing
        - 'Drupal 7'
      datePublished: '2017-01-13T12:19:10+0100'
      dateModified: '2026-06-10T09:07:33+0200'
      author:
        '@type': Person
        name: 'Carlos Montes'
      publisher:
        '@type': Organization
        '@id': 'https://metadrop.net/#organization'
      mainEntityOfPage: 'https://metadrop.net/es/articulos/behat3x-pasos-de-interacciones-con-nodos-para-drupal'
    -
      '@type': Organization
      '@id': 'https://metadrop.net/#organization'
      url: 'https://metadrop.net/'
      name: Metadrop
      sameAs:
        - 'https://www.drupal.org/metadrop'
        - 'https://twitter.com/metadrop'
        - 'https://asociaciondrupal.es/partner/metadrop'
        - 'https://www.linkedin.com/company/metadrop'
      logo:
        '@type': ImageObject
        url: 'https://metadrop.net/themes/custom/mdrop_radix/logo-metadrop-500-500.jpg'
        width: '500'
        height: '500'
    -
      '@type': ItemPage
      '@id': 'https://metadrop.net/es/articulos/behat3x-pasos-de-interacciones-con-nodos-para-drupal'
      breadcrumb:
        '@type': BreadcrumbList
        itemListElement:
          -
            '@type': ListItem
            position: 1
            name: Inicio
            item: 'https://metadrop.net/es'
          -
            '@type': ListItem
            position: 2
            name: 'Artículos expertos sobre Drupal y tecnología'
            item: 'https://metadrop.net/es/articulos'
      publisher:
        '@type': Organization
        '@id': 'https://metadrop.net/#organization'
---
 1. [Artículos](https://metadrop.net/es/articulos)
 
  

# Behat3.x pasos de interacciones con Nodos para Drupal

Viernes 13 de Enero de 2017

 

 



En esté artículo agregaremos pasos para manipular nuestros nodos de Drupal



   



Con ayuda de estás dos funciones podremos publicar y despublicar nodos. Muy útil si necesitamos tener ciertos contenidos para hacer pruebas sobre ellos.

## Publicación de Nodos

```php
/**
 * @BeforeSuite
 */
public static
function publishNode() { 
  $nids = array();  // Load all nodes in one go for better performance. Example (12, 15)
   
  $nodes = node_load_multiple($nids);
  foreach($nodes as $node) {
       
    $node-> status = 1;  // set status property to 1, Published
       
    node_save($node);   //save the node
  }
}

```

## Despublicación de Nodos

```php
/**
 * @AfterSuite
 */
public static
function unpublishNode() { 
  $nids = array();  // Load all nodes in one go for better performance. Example (1, 5, 15)
   
  $nodes = node_load_multiple($nids); 
  foreach($nodes as $node) {    

    $node-> status = 0; // set status property to 0, Unpublish
       
    node_save($node);   // save the node(s)
  }
}
```

## Recuperar el NID del último nodo creado

```php
 
 /**
   * Take the last nid create. Optional bundle
   *
   * @param string $bundle
   *   Optionally restrict the search to this type of node.
   *
   * @return int
   *   Node id (Nid).
   */
  public function getLastNodeNid($bundle = NULL) {
    if (!empty($bundle)) {
      $query = db_query("SELECT nid FROM node WHERE type = :bundle ORDER BY nid DESC LIMIT 1", array(':bundle' => $bundle));
    }
    else {
      $query = db_query("SELECT nid FROM node ORDER BY nid DESC LIMIT 1");
    }

    return $query->fetchField();
  }

```

A continuación agregamos información sobre las herramientas utilizadas y documentación sobre *Behat* relativa a los pasos

Información sobre Tags @BeforeSuite y @AfterSuite
[https://docs.behat.org/en/v2.5/guides/3.hooks.html#hooks](https://docs.behat.org/en/v2.5/guides/3.hooks.html#hooks "Behat documentación hooks")

Información sobre Drupal Extension y Mink
[https://behat-drupal-extension.readthedocs.io/en/3.1/intro.html](https://behat-drupal-extension.readthedocs.io/en/3.1/intro.html "Behat Drupal Extension")



[Behat](https://metadrop.net/es/articulos?text=Behat)

[Testing](https://metadrop.net/es/articulos?text=Testing)

[Drupal 7](https://metadrop.net/es/articulos?text=Drupal%207)