Commit 83d12c87 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4106 (Issues in Sitemap consistency)

parent 58d4e102
Loading
Loading
Loading
Loading
+45 −3
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ class sitemap_test_set extends cms_test_case
{
    public $sitemap;
    public $flattened;
    public $options;
    public $meta_gather;

    public function setUp()
    {
@@ -37,13 +39,13 @@ class sitemap_test_set extends cms_test_case
        $valid_node_types = null;
        $child_cutoff = null;
        $max_recurse_depth = null;
        $options = SITEMAP_GEN_NONE;
        $this->options = SITEMAP_GEN_NONE | SITEMAP_GEN_KEEP_FULL_STRUCTURE;
        $zone = '_SEARCH';
        $meta_gather = SITEMAP_GATHER__ALL | SITEMAP_GEN_USE_PAGE_GROUPINGS;
        $this->meta_gather = SITEMAP_GATHER__ALL;

        $GLOBALS['SITE_DB']->query_delete('bookmarks'); // Interferes with rules

        $this->sitemap = retrieve_sitemap_node($page_link, $callback, $valid_node_types, $child_cutoff, $max_recurse_depth, $options, $zone, $meta_gather);
        $this->sitemap = retrieve_sitemap_node($page_link, $callback, $valid_node_types, $child_cutoff, $max_recurse_depth, $this->options, $zone, $this->meta_gather);
        $this->flattened = $this->flatten_sitemap($this->sitemap);

        parent::setUp();
@@ -74,6 +76,46 @@ class sitemap_test_set extends cms_test_case
        return $ret;
    }

    public function testIsSearchable()
    {
        $properties_compare = [
            'content_type',
            'content_id',
            'page_link',
            'permissions',
            'privilege_page',
        ];

        foreach ($this->flattened as $page_link => $node) {
            if ($page_link == '') {
                continue;
            }

            $node_searched = retrieve_sitemap_node($page_link, null, null, null, null, $this->options, '_SEARCH', $this->meta_gather);
            $this->assertTrue($node_searched !== null, 'Could not do a search for ' . $page_link);
            if ($node_searched !== null) {
                foreach ($properties_compare as $property) {
                    $node_property = isset($node[$property]) ? $node[$property] : null;
                    $node_searched_property = isset($node_searched[$property]) ? $node_searched[$property] : null;
                    $this->assertTrue($node_property === $node_searched_property, 'Search produced different node for ' . $page_link . ' (comparing ' . $property . '; ' . serialize($node_property) . '; vs ' . serialize($node_searched_property) . ')');
                    if ($node_property !== $node_searched_property) {
                        if (!empty($_GET['debug'])) { // TODO: Change to $this->debug in v11
                            var_dump($node_property);
                            var_dump($node_searched_property);
                        }
                    }
                }
                if (!isset($node['title'])) {
                    $this->assertTrue(false, 'Null title for ' . $page_link);
                } elseif (!isset($node_searched['title'])) {
                    $this->assertTrue(false, 'Null title on search result for ' . $page_link);
                } else {
                    $this->assertTrue($node['title']->evaluate() == $node_searched['title']->evaluate(), 'Search produced different node for ' . $page_link . ' (comparing title)');
                }
            }
        }
    }

    public function testIsConclusive()
    {
        if ($this->sitemap === null) {
+2 −1
Original line number Diff line number Diff line
@@ -127,8 +127,9 @@ class Hook_sitemap_banner extends Hook_sitemap_content
    public function get_node($page_link, $callback = null, $valid_node_types = null, $child_cutoff = null, $max_recurse_depth = null, $recurse_level = 0, $options = 0, $zone = '_SEARCH', $meta_gather = 0, $row = null, $return_anyway = false)
    {
        $page_link_fudged = preg_replace('#:source=#', ':', $page_link);
        $_ = $this->_create_partial_node_structure($page_link, $callback, $valid_node_types, $child_cutoff, $max_recurse_depth, $recurse_level, $options, $zone, $meta_gather, $row);
        $_ = $this->_create_partial_node_structure($page_link_fudged, $callback, $valid_node_types, $child_cutoff, $max_recurse_depth, $recurse_level, $options, $zone, $meta_gather, $row);
        if ($_ === null) {

            return null;
        }
        list($content_id, $row, $partial_struct) = $_;
+14 −0
Original line number Diff line number Diff line
@@ -42,6 +42,20 @@ class Hook_sitemap_calendar_type extends Hook_sitemap_content
        return 'cms_calendar';
    }

    /**
     * Find if a page-link will be covered by this node.
     *
     * @param  ID_TEXT $page_link The page-link.
     * @return integer A SITEMAP_NODE_* constant.
     */
    public function handles_page_link($page_link)
    {
        if (preg_match('#^\w+:calendar:browse$#', $page_link) != 0) {
            return false;
        }
        return parent::handles_page_link($page_link);
    }

    /**
     * Find details of a virtual position in the sitemap. Virtual positions have no structure of their own, but can find child structures to be absorbed down the tree. We do this for modularity reasons.
     *
+7 −2
Original line number Diff line number Diff line
@@ -123,8 +123,13 @@ class Hook_sitemap_comcode_page extends Hook_sitemap_page

        $row = $this->_load_row_from_page_groupings($row, $meta_gather, $zone, $page);

        if ($page == 'start') { // TODO: Change in v11
            $test_icon = find_theme_image('icons/24x24/menu/' . $page, true);
            $test_icon_2x = find_theme_image('icons/48x48/menu/' . $page, true);
        } else {
            $test_icon = find_theme_image('icons/24x24/menu/pages/' . $page, true);
            $test_icon_2x = find_theme_image('icons/48x48/menu/pages/' . $page, true);
        }
        if ($test_icon == '') {
            $test_icon = find_theme_image('icons/24x24/menu/site_meta/' . $page, true);
            $test_icon_2x = find_theme_image('icons/48x48/menu/site_meta/' . $page, true);
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class Hook_sitemap_config_category extends Hook_sitemap_base
    public function handles_page_link($page_link)
    {
        $matches = array();
        if (preg_match('#^([^:]*):admin_config(:browse|$)#', $page_link, $matches) != 0) {
        if (preg_match('#^([^:]*):admin_config(:(browse|category)|$)#', $page_link, $matches) != 0) {
            $zone = $matches[1];
            $page = 'admin_config';

Loading