From 24a24ac6be27e47bdd503fc508026737154392a5 Mon Sep 17 00:00:00 2001
From: Yuriy Gerasimov <yuri.gerasimov@gmail.com>
Date: Sun, 3 Apr 2011 13:47:28 +0300
Subject: [PATCH] Issue #992882 by ygerasimov: Add test for create node with taxonomy terms added.

---
 tests/functional/ServicesResourceNodeTests.test |   50 +++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/tests/functional/ServicesResourceNodeTests.test b/tests/functional/ServicesResourceNodeTests.test
index 6aae85b..ce6b38e 100644
--- a/tests/functional/ServicesResourceNodeTests.test
+++ b/tests/functional/ServicesResourceNodeTests.test
@@ -23,6 +23,7 @@ class ServicesResourceNodetests extends ServicesWebtestCase {
    */
   public function setUp() {
     parent::setUp(
+      'taxonomy',
       'autoload',
       'ctools',
       'services',
@@ -153,6 +154,55 @@ class ServicesResourceNodetests extends ServicesWebtestCase {
   }
 
   /**
+   * Create node with taxonomy terms added.
+   */
+  public function testEndpointResourceNodeCreateWithTaxonomyTerms() {
+    // Create and log in our privileged user.
+    $this->privilegedUser = $this->drupalCreateUser(array(
+      'administer services',
+      'administer nodes',
+      'administer taxonomy',
+    ));
+    $this->drupalLogin($this->privilegedUser);
+
+    // Create vocabulary.
+    $edit = array(
+      'name' => $this->randomName(),
+      'multiple' => 1,
+      'nodes[page]' => 1,
+    );
+    $this->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, t('Save'));
+
+    // Create three terms.
+    for ($i = 0; $i < 3; $i++) {
+      $term = array(
+        'name' => $this->randomName(),
+      );
+      $this->drupalPost('admin/content/taxonomy/1/add/term', $term, t('Save'));
+    }
+
+    $node = array(
+      'nid' => NULL,
+      'title' => $this->randomString(),
+      'body' => $this->randomString(),
+      'name' => $this->privilegedUser->name,
+      'type' => 'page',
+      'taxonomy' => array(1 => array(
+        1 => 1,
+        2 => 2,
+      )),
+    );
+
+    $response = $this->servicesPost($this->endpoint->path . '/node', array('node' => $node));
+
+    // Get number of attached taxonomy terms from this node. We do it manually
+    // as we cannot get terms on node_load as as empty array is statically
+    // cached in taxonomy_node_get_terms() and we cannot clear the cache.
+    $terms_number = db_result(db_query('SELECT COUNT(*) result FROM {term_node} r INNER JOIN {node} n ON n.vid = r.vid WHERE n.nid = %d', $response['body']['nid']));
+    $this->assertTrue($terms_number == 2, t('Node with two terms was successfully created.'), 'NodeResource: Create');
+  }
+
+  /**
   * testing node_resource Update
   */
   public function testEndpointResourceNodeUpdate() {
-- 
1.7.0.4

