| 1 |
|
<?php |
| 2 |
|
|
| 3 |
|
class NodeFactoryTest extends DrupalTestCase { |
| 4 |
|
function get_info() { |
| 5 |
|
return array( |
| 6 |
|
'name' => t('Node Factory Test'), |
| 7 |
|
'description' => t('Assure that all cool features of your module work.'), |
| 8 |
|
'group' => t('Node Factory Tests'), |
| 9 |
|
); |
| 10 |
|
} |
| 11 |
|
|
| 12 |
|
function testCreatePagePrologue() { |
| 13 |
|
$edit = node_factory_create_node('page'); |
| 14 |
|
|
| 15 |
|
$this->assertNotNull($edit['uid'], t('Empty uid')); |
| 16 |
|
} |
| 17 |
|
|
| 18 |
|
function testCreateStory() { |
| 19 |
|
$this->createStory(); |
| 20 |
|
} |
| 21 |
|
|
| 22 |
|
function testCreateNodeRef() { |
| 23 |
|
|
| 24 |
|
$edit = $this->prepareNode(); |
| 25 |
|
$ref = $this->saveNode( $edit); |
| 26 |
|
|
| 27 |
|
$this->assertFalse( !module_exists('content'), 'content module installed'); |
| 28 |
|
$edit = $this->prepareNode('node_factory_node_ref'); |
| 29 |
|
node_factory_set_value( $edit, 'field_node_factory_node_ref', $ref); |
| 30 |
|
$this->saveNode( $edit); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
function testCreateStoryRefAutoSingle() { |
| 34 |
|
$edit = $this->prepareNode(); |
| 35 |
|
$ref = $this->saveNode( $edit); |
| 36 |
|
|
| 37 |
|
$this->assertFalse( !module_exists('content'), 'content module installed'); |
| 38 |
|
$edit = $this->prepareNode('nf_sr_auto_test'); |
| 39 |
|
node_factory_set_value( $edit, 'field_story_ref_auto', $ref); |
| 40 |
|
$this->saveNode( $edit); |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
function createStory() { |
| 45 |
|
$edit = $this->prepareNode(); |
| 46 |
|
return $this->saveNode( $edit); |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
function prepareNode( $type = 'story') { |
| 50 |
|
$title = $type . ' '. basename( __FILE__) .'_'. date(DATE_ATOM); |
| 51 |
|
$body = 'Body of '. $title; |
| 52 |
|
|
| 53 |
|
$edit = node_factory_create_node($type); |
| 54 |
|
node_factory_set_value( $edit, 'title', $title); |
| 55 |
|
node_factory_set_value( $edit, 'body', $body); |
| 56 |
|
|
| 57 |
|
return $edit; |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
function saveNode( $edit) { |
| 61 |
|
$nid = node_factory_save_node( $edit, FALSE); |
| 62 |
|
$this->assertNotEqual($nid, FALSE, t('Saving node should result in a nid = !n.', array( '!n' => l('new', "node/$nid")))); |
| 63 |
|
return $nid; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
} |
| 67 |
|
?> |