| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
class NodeFactoryTest extends DrupalTestCase { |
class NodeFactoryBase extends DrupalTestCase { |
| 4 |
|
function createStory() { |
| 5 |
|
$edit = $this->prepareNode(); |
| 6 |
|
return $this->saveNode( $edit); |
| 7 |
|
} |
| 8 |
|
|
| 9 |
|
function prepareNode( $type = 'story') { |
| 10 |
|
$title = $type . ' '. basename( __FILE__) .'_'. date(DATE_ATOM); |
| 11 |
|
$body = 'Body of '. $title; |
| 12 |
|
|
| 13 |
|
$edit = node_factory_create_node($type); |
| 14 |
|
node_factory_set_value( $edit, 'title', $title); |
| 15 |
|
node_factory_set_value( $edit, 'body', $body); |
| 16 |
|
|
| 17 |
|
return $edit; |
| 18 |
|
} |
| 19 |
|
|
| 20 |
|
function saveNode( $edit) { |
| 21 |
|
$nid = node_factory_save_node( $edit, FALSE); |
| 22 |
|
return $nid; |
| 23 |
|
} |
| 24 |
|
} |
| 25 |
|
|
| 26 |
|
class NodeFactoryUserRefTest extends NodeFactoryBase { |
| 27 |
|
function get_info() { |
| 28 |
|
return array( |
| 29 |
|
'name' => t('Node Factory User Reference Test'), |
| 30 |
|
'description' => t('Test for the CCK userreference widget.'), |
| 31 |
|
'group' => t('Node Factory Tests'), |
| 32 |
|
); |
| 33 |
|
} |
| 34 |
|
|
| 35 |
|
function testCreateUserRef() { |
| 36 |
|
if ($this->assertFalse( !module_exists('userreference'), 'user reference module enabled')) { |
| 37 |
|
$edit = $this->prepareNode('nf_ur_auto_test'); |
| 38 |
|
|
| 39 |
|
// nodereference needs user NAME |
| 40 |
|
global $user; |
| 41 |
|
node_factory_set_value( $edit, 'field_user_ref_auto', $user->name); |
| 42 |
|
$nid = $this->saveNode( $edit); |
| 43 |
|
$node = node_load( array( 'nid' => $nid)); |
| 44 |
|
$this->assertEqual( $node->field_user_ref_auto[0][uid], $user->uid, 'saved user reference should be equal to user running test'); |
| 45 |
|
} |
| 46 |
|
} |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
class NodeFactoryTest extends NodeFactoryBase { |
| 50 |
function get_info() { |
function get_info() { |
| 51 |
return array( |
return array( |
| 52 |
'name' => t('Node Factory Test'), |
'name' => t('Node Factory Test'), |
| 59 |
$node_type = 'story'; |
$node_type = 'story'; |
| 60 |
|
|
| 61 |
if ($this->assertFalse( !module_exists('taxonomy'), 'taxonomy module installed')) { |
if ($this->assertFalse( !module_exists('taxonomy'), 'taxonomy module installed')) { |
|
|
|
| 62 |
$vocs = taxonomy_get_vocabularies( $node_type); |
$vocs = taxonomy_get_vocabularies( $node_type); |
|
|
|
| 63 |
if ($this->assertFalse( count($vocs) == 0, t('taxonomy attached to !n', array( '!n' => $node_type)))) { |
if ($this->assertFalse( count($vocs) == 0, t('taxonomy attached to !n', array( '!n' => $node_type)))) { |
| 64 |
$voc = array_shift( $vocs); |
$voc = array_shift( $vocs); |
| 65 |
if ($this->assertFalse( !$voc->tags, t('freetagging set'))) { |
if ($this->assertFalse( !$voc->tags, t('freetagging set. Using a,b,c and tid==9'))) { |
| 66 |
$edit = $this->prepareNode(); |
$edit = $this->prepareNode(); |
| 67 |
$edit['title'] = 'testAddTaxonomy '. $edit['title']; |
$edit['title'] = 'testAddTaxonomy '. $edit['title']; |
| 68 |
|
|
| 77 |
|
|
| 78 |
function testCreatePagePrologue() { |
function testCreatePagePrologue() { |
| 79 |
$edit = node_factory_create_node('page'); |
$edit = node_factory_create_node('page'); |
|
|
|
| 80 |
$this->assertNotNull($edit['uid'], t('uid set')); |
$this->assertNotNull($edit['uid'], t('uid set')); |
| 81 |
} |
} |
| 82 |
|
|
| 83 |
function testCreateStory() { |
function testCreateStory() { |
| 84 |
$this->createStory(); |
$nid = $this->createStory(); |
| 85 |
} |
$this->assertNotEqual($nid, FALSE, t('Saving node should result in a nid = !n.', array( '!n' => l('new', "node/$nid")))); |
| 86 |
|
return $nid; |
|
function testCreateNodeRef() { |
|
|
|
|
|
$edit = $this->prepareNode(); |
|
|
$ref = $this->saveNode( $edit); |
|
|
|
|
|
$this->assertFalse( !module_exists('content'), 'content module installed'); |
|
|
$edit = $this->prepareNode('node_factory_node_ref'); |
|
|
node_factory_set_value( $edit, 'field_node_factory_node_ref', $ref); |
|
|
$this->saveNode( $edit); |
|
| 87 |
} |
} |
| 88 |
|
|
| 89 |
function testCreateStoryRefAutoSingle() { |
function testCreateStoryRefAutoSingle() { |
| 90 |
$edit = $this->prepareNode(); |
$ref_nid = $nid = $this->createStory(); |
|
$ref = $this->saveNode( $edit); |
|
|
|
|
|
$this->assertFalse( !module_exists('content'), 'content module installed'); |
|
|
$edit = $this->prepareNode('nf_sr_auto_test'); |
|
|
node_factory_set_value( $edit, 'field_story_ref_auto', $ref); |
|
|
$this->saveNode( $edit); |
|
|
} |
|
|
|
|
|
|
|
|
function createStory() { |
|
|
$edit = $this->prepareNode(); |
|
|
return $this->saveNode( $edit); |
|
|
} |
|
|
|
|
|
function prepareNode( $type = 'story') { |
|
|
$title = $type . ' '. basename( __FILE__) .'_'. date(DATE_ATOM); |
|
|
$body = 'Body of '. $title; |
|
| 91 |
|
|
| 92 |
$edit = node_factory_create_node($type); |
if ($this->assertFalse( !module_exists('content'), 'content module installed')) { |
| 93 |
node_factory_set_value( $edit, 'title', $title); |
$edit = $this->prepareNode('nf_sr_auto_test'); |
| 94 |
node_factory_set_value( $edit, 'body', $body); |
node_factory_set_value( $edit, 'field_story_ref_auto', $ref_nid); |
| 95 |
|
$nid = $this->saveNode( $edit); |
| 96 |
return $edit; |
$node = node_load( array( 'nid' => $nid)); |
| 97 |
} |
$this->assertEqual( $node->field_story_ref_auto[0][nid], $ref_nid, 'node references should be equal'); |
| 98 |
|
} |
|
function saveNode( $edit) { |
|
|
$nid = node_factory_save_node( $edit, FALSE); |
|
|
$this->assertNotEqual($nid, FALSE, t('Saving node should result in a nid = !n.', array( '!n' => l('new', "node/$nid")))); |
|
|
return $nid; |
|
| 99 |
} |
} |
|
|
|
| 100 |
} |
} |
| 101 |
?> |
?> |