18.10.2016 Views

Drupal 7 Module Development

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating Your First <strong>Module</strong><br />

}<br />

);<br />

public function testBlockInfo() {<br />

$info = module_invoke('first', 'block_info');<br />

$this->assertEqual(1, count($info),<br />

t('<strong>Module</strong> defines a block.'));<br />

}<br />

$this->assertTrue(isset($info['list_modules']),<br />

t('<strong>Module</strong> list exists.'));<br />

public function testBlockView() {<br />

$data = module_invoke('first', 'block_view',<br />

'list_modules');<br />

}<br />

$this->assertTrue(is_array($data),<br />

t('Block returns renderable array.'));<br />

$this->assertEqual(t('Enabled <strong>Module</strong>s'), $data['subject'],<br />

t('Subject is set'));<br />

}<br />

The code above has two test methods:<br />

• testBlockInfo()<br />

• testBlockView()<br />

As the names imply, each method is responsible for testing one of the two block<br />

functions we wrote earlier.<br />

We will begin by taking a close look at testBlockInfo().<br />

public function testBlockInfo() {<br />

$info = module_invoke('first', 'block_info');<br />

$this->assertEqual(1, count($info),<br />

t('<strong>Module</strong> defines a block.'));<br />

}<br />

$this->assertTrue(isset($info['list_modules']),<br />

t('<strong>Module</strong> list exists.'));<br />

[ 56 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!