123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- /**
- * @file
- * Tests for the xmlsitemap_engines module.
- */
- /**
- * Functional Test.
- *
- * @codingStandardsIgnoreStart
- */
- class XMLSitemapEnginesFunctionalTest extends XMLSitemapTestHelper {
- /**
- * Submit URL.
- *
- * @var string
- */
- protected $submit_url;
- /**
- * Get Info.
- *
- * @codingStandardsIgnoreEnd
- */
- public static function getInfo() {
- return array(
- 'name' => 'XML sitemap engines functional tests',
- 'description' => 'Functional tests for the XML sitemap engines module.',
- 'group' => 'XML sitemap',
- );
- }
- /**
- * Setup.
- */
- public function setUp($modules = array()) {
- $modules[] = 'xmlsitemap_engines';
- $modules[] = 'xmlsitemap_engines_test';
- parent::setUp($modules);
- $this->admin_user = $this->drupalCreateUser(array('access content', 'administer xmlsitemap'));
- $this->drupalLogin($this->admin_user);
- // @todo For some reason the test client does not have clean URLs while
- // the test runner does, so it causes mismatches in watchdog assertions
- // later.
- variable_set('clean_url', 0);
- $this->submit_url = url('ping', array('absolute' => TRUE, 'query' => array('sitemap' => ''))) . '[sitemap]';
- }
- /**
- * Submit Engines.
- */
- public function submitEngines() {
- variable_set('xmlsitemap_engines_submit_last', REQUEST_TIME - 10000);
- variable_set('xmlsitemap_generated_last', REQUEST_TIME - 100);
- variable_set('xmlsitemap_engines_minimum_lifetime', 0);
- xmlsitemap_engines_cron();
- $this->assertTrue(variable_get('xmlsitemap_engines_submit_last', 0) > (REQUEST_TIME - 100), 'Submitted the sitemaps to search engines.');
- }
- /**
- * Test Prepare URL.
- *
- * @codingStandardsIgnoreStart
- */
- public function testPrepareURL() {
- // @codingStandardsIgnoreEnd
- $sitemap = 'http://example.com/sitemap.xml';
- $input = 'http://example.com/ping?sitemap=[sitemap]&foo=bar';
- $output = 'http://example.com/ping?sitemap=http://example.com/sitemap.xml&foo=bar';
- $this->assertEqual(xmlsitemap_engines_prepare_url($input, $sitemap), $output);
- }
- /**
- * Test Submit Sitemaps.
- */
- public function testSubmitSitemaps() {
- $sitemaps = array();
- $sitemap = new stdClass();
- $sitemap->uri = array(
- 'path' => 'http://example.com/sitemap.xml',
- 'options' => array(),
- );
- $sitemaps[] = $sitemap;
- $sitemap = new stdClass();
- $sitemap->uri = array(
- 'path' => 'http://example.com/sitemap-2.xml',
- 'options' => array(),
- );
- $sitemaps[] = $sitemap;
- xmlsitemap_engines_submit_sitemaps($this->submit_url, $sitemaps);
- $this->assertWatchdogMessage(array(
- 'type' => 'xmlsitemap',
- 'message' => 'Recieved ping for @sitemap.',
- 'variables' => array(
- '@sitemap' => 'http://example.com/sitemap.xml',
- ),
- ));
- $this->assertWatchdogMessage(array(
- 'type' => 'xmlsitemap',
- 'message' => 'Recieved ping for @sitemap.',
- 'variables' => array(
- '@sitemap' => 'http://example.com/sitemap-2.xml',
- ),
- ));
- }
- /**
- * Test Ping.
- */
- public 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.'));
- $this->submitEngines();
- $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.'));
- }
- /**
- * Test Custom URL.
- *
- * @codingStandardsIgnoreStart
- */
- public function testCustomURL() {
- // @codingStandardsIgnoreEnd
- $edit = array('xmlsitemap_engines_custom_urls' => 'an-invalid-url');
- $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
- $this->assertText('Invalid URL an-invalid-url.');
- $this->assertNoText('The configuration options have been saved.');
- $url = url('ping', array('absolute' => TRUE));
- $edit = array('xmlsitemap_engines_custom_urls' => $url);
- $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
- $this->assertText(t('The configuration options have been saved.'));
- $this->submitEngines();
- $this->assertWatchdogMessage(array(
- 'type' => 'xmlsitemap',
- 'message' => 'Submitted the sitemap to %url and received response @code.',
- 'variables' => array(
- '%url' => $url,
- '@code' => '404',
- ),
- ));
- $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' => $this->submit_url);
- $this->drupalPost('admin/config/search/xmlsitemap/engines', $edit, t('Save configuration'));
- $this->assertText(t('The configuration options have been saved.'));
- $this->submitEngines();
- $url = xmlsitemap_engines_prepare_url($this->submit_url, url('sitemap.xml', array('absolute' => TRUE)));
- $this->assertWatchdogMessage(array(
- 'type' => 'xmlsitemap',
- 'message' => 'Submitted the sitemap to %url and received response @code.',
- 'variables' => array(
- '%url' => $url,
- '@code' => '200',
- ),
- ));
- $this->assertWatchdogMessage(array(
- 'type' => 'xmlsitemap',
- 'message' => 'Recieved ping for @sitemap.',
- 'variables' => array(
- '@sitemap' => url('sitemap.xml', array(
- 'absolute' => TRUE,
- )),
- ),
- ));
- }
- }
|