CRM-17725 navigation reset duplicating All reports link
authoreileen <emcnaughton@wikimedia.org>
Thu, 15 Oct 2015 02:56:51 +0000 (15:56 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 15 Oct 2015 02:56:51 +0000 (15:56 +1300)
@colemanw spotted this in QA of CRM-17725 although it doesn't strictly relate

CRM/Core/BAO/Navigation.php
tests/phpunit/CRM/Core/BAO/NavigationTest.php
xml/schema/Core/Navigation.xml

index ca069fc7571cb89094dab6d593f79612db5316ff..b93a74fca7dbaccf285acc490ad5d4c8fc0069fb 100644 (file)
@@ -926,7 +926,7 @@ ORDER BY parent_id, weight";
     }
 
     // Create or update the All Reports link.
-    self::createOrUpdateReportNavItem('All Reports', 'civicrm/report/list', 'reset=1', $reports_nav->id, 'access CiviReport', $domain_id);
+    self::createOrUpdateReportNavItem('All Reports', 'civicrm/report/list', 'reset=1', $reports_nav->id, 'access CiviReport', $domain_id, TRUE);
   }
 
   /**
index 9183de792556c6f5b8f1c38ea2717169f36836ab..cf47eeedc18abcf198d378c6dc2abb55bc7d4ef1 100644 (file)
@@ -49,6 +49,22 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase {
     $this->assertEquals($reportCount, $this->getCountReportInstances());
   }
 
+  /**
+   * Test that All reports link is not stolen.
+   *
+   * There are 2 All reports links by default. What we DON'T want to see is them
+   * both winding up under the Reports menu - since they already exist they should be unchanged
+   * by rebuilding reports.
+   */
+  public function testNoDuplicateAllReportsLink() {
+    $existing_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1));
+    $this->assertNotEquals($existing_links['values'][0]['parent_id'], $existing_links['values'][1]['parent_id']);
+    CRM_Core_BAO_Navigation::rebuildReportsNavigation(CRM_Core_Config::domainID());
+    $new_links = $this->callAPISuccess('Navigation', 'get', array('label' => 'All Reports', 'sequential' => 1));
+    $this->assertEquals($existing_links['values'][0]['parent_id'], $new_links['values'][0]['parent_id']);
+    $this->assertEquals($existing_links['values'][1]['parent_id'], $new_links['values'][1]['parent_id']);
+  }
+
   /**
    * Test that an existing report link is rebuilt under it's parent.
    *
@@ -137,6 +153,17 @@ class CRM_Core_BAO_NavigationTest extends CiviUnitTestCase {
       "SELECT count(*) FROM civicrm_navigation WHERE url LIKE 'civicrm/report/instance/%'");
   }
 
+  /**
+   * Get a count of navigation items that match the url.
+   * @param string $url
+   *
+   * @return int
+   */
+  protected function getCountURL($url) {
+    return CRM_Core_DAO::singleValueQuery(
+      "SELECT count(*) FROM civicrm_navigation WHERE url ='{$url}'");
+  }
+
   /**
    * Run fixNavigationMenu() on a menu which already has navIDs
    * everywhere. They should be unchanged.
index 472ef5b31b8b71355c7452e056a1693ebda1cbbd..cc770f8d178e59b0fdfedcd9acb9d798dd11e2be 100644 (file)
     <title>Navigation parent ID</title>
     <type>int unsigned</type>
     <comment>Parent navigation item, used for grouping</comment>
+    <pseudoconstant>
+      <table>civicrm_navigation</table>
+      <keyColumn>name</keyColumn>
+      <labelColumn>label</labelColumn>
+    </pseudoconstant>
     <add>3.0</add>
   </field>
   <foreignKey>