<?php
// $Id: xmlsitemap_engines.test,v 1.5 2010/01/24 05:33:27 davereid Exp $

/**
 * @file
 * Unit tests for the xmlsitemap_engines module.
 */
class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
  public static function getInfo() {
    return array(
      'name' => 'XML sitemap engines interface tests',
      'description' => 'Functional tests for the XML sitemap engines module.',
      'group' => 'XML sitemap',
    );
  }

  function setUp() {
    parent::setUp('xmlsitemap_engines', 'xmlsitemap_engines_test');
    $this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
    $this->drupalLogin($this->admin_user);
    variable_set('xmlsitemap_generated_last', REQUEST_TIME);
  }

  function testPing() {
    $edit = array('xmlsitemap_engines_engines[simpletest]' => TRUE);
    $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'));

    xmlsitemap_engines_cron();
    $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.'));
    $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Recieved ping for @sitemap.'));
  }

  function testCustomURL() {
    $edit = array('xmlsitemap_engines_custom_urls' => 'an-invalid-url');
    $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
    $this->assertText(t('Invalid custom URL an-invalid-url.'));
    $this->assertNoText(t('The configuration options have been saved.'));

    $edit = array('xmlsitemap_engines_custom_urls' => url('ping', array('absolute' => TRUE)));
    $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'));

    xmlsitemap_engines_cron();
    $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'Submitted the sitemap to %url and received response @code.'));
    $this->assertWatchdogMessage(array('type' => 'xmlsitemap', 'message' => 'No valid sitemap parameter provided.'));
    $this->assertWatchdogMessage(array('type' => 'page not found', 'message' => 'ping'));

    $edit = array('xmlsitemap_engines_custom_urls' => url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => '[sitemap]'))));
    $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'));
  }
}
