From 9b50597eb243c0447eed6d9f41c9ad2e4de10b0d Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Fri, 13 Feb 2009 02:25:59 +0000 Subject: #369423 by nedjo: Fix drupal_write_record() bug with multi-field primary keys (with tests). --- modules/simpletest/tests/common.test | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'modules/simpletest/tests/common.test') diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 9d8c1d23f..209b4503d 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -782,6 +782,52 @@ class ValidUrlTestCase extends DrupalWebTestCase { } } +/** + * Tests for CRUD API functions. + */ +class DrupalDataApiTest extends DrupalWebTestCase { + function getInfo() { + return array( + 'name' => t('Data API functions'), + 'description' => t('Tests the performance of CRUD APIs.'), + 'group' => t('System'), + ); + } + + function setUp() { + parent::setUp('taxonomy'); + } + + /** + * Test the drupal_write_record() API function. + */ + function testDrupalWriteRecord() { + // Insert an object record for a table with a single-field primary key. + $vocabulary = new StdClass(); + $vocabulary->name = 'test'; + $insert_result = drupal_write_record('taxonomy_vocabulary', $vocabulary); + $this->assertTrue($insert_result == SAVED_NEW, t('Correct value returned when a record is inserted with drupal_write_record() for a table with a single-field primary key.')); + $this->assertTrue(isset($vocabulary->vid), t('Primary key is set on record created with drupal_write_record().')); + + // Update the initial record after changing a property. + $vocabulary->name = 'testing'; + $update_result = drupal_write_record('taxonomy_vocabulary', $vocabulary, array('vid')); + $this->assertTrue($update_result == SAVED_UPDATED, t('Correct value returned when a record updated with drupal_write_record() for table with single-field primary key.')); + + // Insert an object record for a table with a multi-field primary key. + $vocabulary_node_type = new StdClass(); + $vocabulary_node_type->vid = $vocabulary->vid; + $vocabulary_node_type->type = 'page'; + $insert_result = drupal_write_record('taxonomy_vocabulary_node_type', $vocabulary_node_type); + $this->assertTrue($insert_result == SAVED_NEW, t('Correct value returned when a record is inserted with drupal_write_record() for a table with a multi-field primary key.')); + + // Update the record. + $update_result = drupal_write_record('taxonomy_vocabulary_node_type', $vocabulary_node_type, array('vid', 'type')); + $this->assertTrue($update_result == SAVED_UPDATED, t('Correct value returned when a record is updated with drupal_write_record() for a table with a multi-field primary key.')); + } + +} + /** * Tests Simpletest error and exception collecter. */ @@ -853,3 +899,4 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase { } } } + -- cgit v1.2.3