EVOLUTION-NINJA
Edit File: agov.test
<?php /** * @file * Tests for Agov install profile. * @author Tim Eisenhuth tim dot eisenhuth at previousnext dot com dot au */ class AgovTest extends AgovTestBase { /** * Provides test info. */ public static function getInfo() { return array( 'name' => 'Agov tests', 'description' => "Tests for Agov.", 'group' => 'Agov', ); } /** * Setup function. */ public function setUp() { parent::setUp(array()); } /** * Test anonymous access to pages and some elements. */ protected function testAnonymousPages() { $this->drupalGet('user'); $this->assertRaw('Member login', 'Anonymous user.'); // Get the home page. $this->drupalGet('/'); $this->assertResponse(200, 'View home page as anonymous user.'); $this->assertRaw('Latest News', 'Found Latest News'); $this->assertRaw('Latest updates', 'Found Latest updates.'); $this->assertRaw('block-agov-menu-block-footer', 'Found Footer.'); // About us page. $this->drupalGet('about-us'); $this->assertRaw('About Us', 'Found About us.'); // Services. $this->drupalGet('services'); $this->assertRaw('Services', 'Found Services.'); // Publications. $this->drupalGet('publications'); $this->assertRaw('Publications', 'Found Publications.'); // Contact. $this->drupalGet('contact'); $this->assertRaw('Contact', 'Found Contact.'); } /** * Test posting content. */ public function testPostContent() { // Cant use drupalLogin() as this only returns true if "Log out" is found. $name = $this->testUser->name; $pass = $this->testUser->pass_raw; $this->drupalPost('user', array('name' => $name, 'pass' => $pass), t('Log in')); $this->assertRaw($name, 'User logged in.'); // Get list of test images. $images = $this->drupalGetTestFiles('image'); // Create a managed file for slide node. $slide_image = file_save($images[4]); // Get a node to post for reference field. $query = new EntityFieldQuery(); $entities = $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'page') ->propertyCondition('status', 1) ->propertyCondition('title', 'About Us') ->execute(); $nids = array_keys($entities['node']); $post_node = node_load(array_shift($nids)); // Define content types. $content_types = array( 'blog_article' => array( 'path' => 'blog-article', 'button' => 'Save', 'fields' => array( 'title' => 'test blog article', ), ), 'event' => array( 'path' => 'event', 'button' => 'Save', 'fields' => array( 'title' => 'test event', ), ), 'media_release' => array( 'path' => 'media-release', 'button' => 'Save', 'fields' => array( 'title' => 'test media release', ), ), 'news_article' => array( 'path' => 'news-article', 'button' => 'Save', 'fields' => array( 'title' => 'test news article', ), ), 'promotion' => array( 'path' => 'footer-teaser', 'button' => 'Save', 'fields' => array( 'title' => 'test promotion', 'files[field_image_und_0]' => drupal_realpath($images[4]->uri), 'field_reference[und]' => $post_node->nid, ), ), 'publication' => array( 'path' => 'publication', 'button' => 'Save', 'fields' => array( 'title' => 'test publication', ), ), 'slide' => array( 'path' => 'slide', 'button' => 'Save', 'fields' => array( 'title' => 'test slide', 'field_slide_image[und][0][fid]' => $slide_image->fid, ), ), 'standard_page' => array( 'path' => 'page', 'button' => 'Save', 'fields' => array( 'title' => 'test standard page', ), ), 'webform' => array( 'path' => 'webform', 'button' => 'Save', 'fields' => array( 'title' => 'test webform', ), ), ); // Post each content type. foreach ($content_types as $type) { $this->drupalPost('node/add/' . $type['path'], $type['fields'], t($type['button'])); $this->assertRaw('<h1>' . $type['fields']['title'] . '</h1>', 'Found title `' . $type['fields']['title'] . '`'); // Check for node in the database. $node = db_select('node', 'n')->fields('n')->condition('title', $type['fields']['title'])->execute()->fetchObject(); $this->assertNotEqual($node, FALSE, 'Found node in database.'); } } /** * Tests to ensure relevant date widgets are available. */ public function testDateWidget() { // Cant use drupalLogin() as this only returns true if "Log out" is found. $name = $this->testUser->name; $pass = $this->testUser->pass_raw; $this->drupalPost('user', array('name' => $name, 'pass' => $pass), t('Log in')); // Events. $this->drupalGet('node/add/event'); $this->assertFieldById('edit-field-event-date-und-0-value-day', date('d')); $this->assertFieldById('edit-field-event-date-und-0-value-month', date('m')); $this->assertFieldById('edit-field-event-date-und-0-value-year', date('Y')); $this->assertFieldById('edit-field-event-date-und-0-value2-day', date('d')); $this->assertFieldById('edit-field-event-date-und-0-value2-month', date('m')); $this->assertFieldById('edit-field-event-date-und-0-value2-year', date('Y')); // News Article. $this->drupalGet('node/add/news-article'); $this->assertFieldById('edit-field-news-date-und-0-value-day', date('d')); $this->assertFieldById('edit-field-news-date-und-0-value-month', date('m')); $this->assertFieldById('edit-field-news-date-und-0-value-year', date('Y')); // Publications. $this->drupalGet('node/add/publication'); $this->assertFieldById('edit-field-date-und-0-value-day', date('d')); $this->assertFieldById('edit-field-date-und-0-value-month', date('m')); $this->assertFieldById('edit-field-date-und-0-value-year', date('Y')); } /** * Tests search_config. */ public function testSearchConfig() { // Cant use drupalLogin() as this only returns true if "Log out" is found. $name = $this->testUser->name; $pass = $this->testUser->pass_raw; $this->drupalPost('user', array('name' => $name, 'pass' => $pass), t('Log in')); $this->assertRaw($name, 'User logged in.'); // Get list of test images. $images = $this->drupalGetTestFiles('image'); // Create a managed file for slide node. $slide_image = file_save($images[4]); // Create a slide. $this->drupalGet('node/add/slide'); $edit = array( 'title' => 'Gods Are Bored', 'field_slide_image[und][0][fid]' => $slide_image->fid, 'workbench_moderation_state_new' => 'published', ); $this->drupalPost(NULL, $edit, t('Save')); // Create a page. $this->drupalGet('node/add/page'); $this->drupalPost(NULL, array( 'title' => 'Gold Halo', 'workbench_moderation_state_new' => 'published', ), t('Save')); // Index content. $this->cronRun(); $this->cronRun(); // Search as administrator. $this->drupalGet('search/node/bored'); $this->assertText('Gods Are Bored'); $this->drupalGet('search/node/gold'); $this->assertText('Gold Halo'); // Search as anonymous. $this->drupalLogout(); $this->drupalGet('search/node/bored'); $this->assertNoText('Gods Are Bored'); $this->drupalGet('search/node/gold'); $this->assertText('Gold Halo'); // Search as logged in user. $user = $this->drupalCreateUser(); $this->drupalPost('user', array('name' => $user->name, 'pass' => $user->pass_raw), t('Log in')); $this->drupalGet('search/node/bored'); $this->assertNoText('Gods Are Bored'); $this->drupalGet('search/node/gold'); $this->assertText('Gold Halo'); } /** * Tests admin/content/file works. */ public function testFileListing() { // Cant use drupalLogin() as this only returns true if "Log out" is found. $name = $this->testUser->name; $pass = $this->testUser->pass_raw; $this->drupalPost('user', array('name' => $name, 'pass' => $pass), t('Log in')); $this->assertRaw($name, 'User logged in.'); $this->drupalGet('admin/content/file'); $this->assertResponse(200); } }