You are here

function NodesInBlock::testNodeSubmissions in Nodes In Block 6

Test submitting of nodes and see if they appear in blocks and how they are rendered.

File

./nodesinblock.test, line 100
Tests for Nodes in block

Class

NodesInBlock
@file Tests for Nodes in block

Code

function testNodeSubmissions() {
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer blocks',
    'administer nodes',
    'administer nodes in block configuration',
    'administer nodes in block queue',
  ));
  $this
    ->drupalLogin($admin_user);
  $this
    ->_setNodesinblockConfiguration();

  // Created a first node.
  $this
    ->_createNode('page', 1);
  $this
    ->assertRaw('Nodes in block 1', 'Nodes in block 1 queue found');

  // Should show up everywhere.
  $this
    ->drupalGet('node');
  $this
    ->assertRaw('Text 1', 'Title 1 node found');
  $this
    ->drupalGet('node/add');
  $this
    ->assertRaw('Text 1', 'Title 1 node found');

  // Update node to show only up on frontpage.
  $this
    ->_updateNode('1', array(
    'nodesinblock_visibility' => '<front>',
  ));
  $this
    ->drupalGet('node/add');
  $this
    ->assertNoRaw('Text 1', 'Title 1 node not found');
  $this
    ->assertNoRaw('Nodes in block 1', 'Block nodes in block 1 not found');
  $this
    ->drupalGet('node');
  $this
    ->assertRaw('Text 1', 'Title 1 node found');
  $this
    ->assertRaw('Nodes in block 1', 'Block nodes in block 1 found');

  // Update node and change block to 2.
  $this
    ->_updateNode('1', array(
    'nodesinblock_delta' => '1',
    'nodesinblock_visibility' => '<front>',
  ));
  $this
    ->drupalget('node/1/nodesinblock');
  $this
    ->assertRaw('Nodes in block 2', 'Nodes in block 2 queue found');
  $this
    ->drupalGet('node');
  $this
    ->assertNoRaw('Nodes in block 1', 'Block nodes in block 1 not found');
  $this
    ->assertRaw('Nodes in block 2', 'Block nodes in block 2 found');
  $this
    ->assertRaw('Text 1', 'Title 1 node found');

  // Create second node.
  $this
    ->_createNode('page', '2');
  $this
    ->assertRaw('Nodes in block 1', 'Nodes in block 1 queue found');
  $this
    ->drupalGet('node/add');
  $this
    ->assertRaw('Nodes in block 1', 'Block nodes in block 1 found');
  $this
    ->assertRaw('Text 2', 'Title 2 node found');
  $this
    ->assertNoRaw('Text 1', 'Title 1 node not found');
  $this
    ->assertNoRaw('Nodes in block 2', 'Block nodes in block 2 not found');
  $this
    ->drupalGet('node');
  $this
    ->assertRaw('Nodes in block 2', 'Block nodes in block 2 found');
  $this
    ->assertRaw('Text 1', 'Title 1 node found');
  $this
    ->assertRaw('Nodes in block 1', 'Block nodes in block 1 found');
  $this
    ->assertRaw('Text 2', 'Title 2 node found');

  // Do some tests on visibility settings of blocks.
  $this
    ->_updateNode('1', array(
    'nodesinblock_delta' => '0',
    'nodesinblock_visibility' => '*',
  ));
  $this
    ->_updateNode('2', array(
    'nodesinblock_delta' => '0',
    'nodesinblock_visibility' => '<front>',
  ));
  $visib = $this
    ->_getVisibility('0');
  $visib = explode("\n", $visib);
  $this
    ->assertTrue(in_array('<front>', $visib, '&lt;front&gt; visibility found.'));
  $this
    ->assertTrue(in_array('*', $visib, '* visibility found.'));
  $this
    ->_updateNode('1', array(
    'nodesinblock_delta' => '0',
    'nodesinblock_visibility' => 'node/add',
  ));
  $this
    ->_updateNode('2', array(
    'nodesinblock_delta' => '0',
    'nodesinblock_visibility' => 'user',
  ));
  $visib = $this
    ->_getVisibility('0');
  $visib = explode("\n", $visib);
  $this
    ->assertFalse(in_array('<front>', $visib, '&lt;front&gt; visibility not found.'));
  $this
    ->assertFalse(in_array('*', $visib, '&lt;front&gt; visibility not found.'));
  $this
    ->assertTrue(in_array('node/add', $visib, 'node/add visibility found.'));
  $this
    ->assertTrue(in_array('user', $visib, 'user visibility found.'));

  // Delete node and see
  // 1: that record is gone in nodesinblock table.
  // 2: visibility of block is good too.
  node_delete('2');
  $result = db_result(db_query("SELECT nid FROM {nodesinblock} WHERE nid = 2"));
  $this
    ->assertFalse($result, 'Row has been deleted from nodesinblock table');
  $visib = $this
    ->_getVisibility('0');
  $visib = explode("\n", $visib);
  $this
    ->assertFalse(in_array('user', $visib, 'user visibility not found.'));
  $this
    ->assertTrue(in_array('node/add', $visib, 'node/add visibility found.'));
}