Example #1
0
 public function testAddSingleExplicitNotVisibleOmekaNavigationPageUri()
 {
     $page = new Omeka_Navigation_Page_Uri(array('label' => __('Browse Items'), 'uri' => url('items/browse'), 'visible' => false));
     $this->assertNull($page->get('uid'));
     $this->_nav->addPage($page);
     $this->assertEquals(CURRENT_BASE_URL, PUBLIC_BASE_URL);
     $uid = PUBLIC_BASE_URL . '/items/browse';
     $this->assertEquals($uid, $page->get('uid'));
     $this->assertEquals(1, $this->_nav->count());
     $this->assertTrue($this->_nav->hasChildren());
     $firstChild = $this->_nav->getChildren();
     $this->assertEquals($page, $firstChild);
     $this->assertInstanceOf('Omeka_Navigation_Page_Uri', $firstChild);
     $this->assertEquals(__('Browse Items'), $firstChild->getLabel());
     $this->assertEquals(url('items/browse'), $firstChild->getUri());
     $this->assertFalse($firstChild->getVisible());
     $this->assertEquals(0, $firstChild->getOrder());
     $this->assertEquals($uid, $firstChild->get('uid'));
     $this->assertEquals($uid, $firstChild->getHref());
     $this->assertTrue($this->_nav->hasPages());
     $pages = $this->_nav->getPages();
     $this->assertContainsOnly('Omeka_Navigation_Page_Uri', $pages);
     $this->assertContains($page, $pages);
     $this->assertContains($firstChild, $pages);
     $foundPage = $this->_nav->findOneBy('uid', $uid);
     $this->assertEquals($page, $foundPage);
     $this->assertEquals($firstChild, $foundPage);
     $pageArray = $firstChild->toArray();
     $this->assertContains($pageArray, $this->_nav->toArray());
 }
Example #2
0
 /**
  * Validate the form
  *
  * @param  array $data
  * @return boolean
  */
 public function isValid($data)
 {
     if (!parent::isValid($data)) {
         return false;
     }
     $hasErrors = false;
     $missingLabel = false;
     $missingURI = false;
     $duplicateURI = false;
     $uids = array();
     if ($pageLinks = $this->getValue(self::HIDDEN_ELEMENT_ID)) {
         if ($pageLinks = json_decode($pageLinks, true)) {
             foreach ($pageLinks as $pageLink) {
                 if (!$missingLabel && trim($pageLink['label']) == '') {
                     $this->addError('All navigation links must have both labels.');
                     $hasErrors = true;
                     $missingLabel = true;
                 }
                 if (!$missingURI && trim($pageLink['uri']) == '') {
                     $this->addError(__('All navigation links must have URIs.'));
                     $hasErrors = true;
                     $missingURI = true;
                 }
                 if (trim($pageLink['uri']) != '') {
                     try {
                         $page = new Omeka_Navigation_Page_Uri();
                         $page->setHref($pageLink['uri']);
                         $uid = $this->_nav->createPageUid($page->getHref());
                         if (!in_array($uid, $uids)) {
                             $uids[] = $uid;
                         } else {
                             if (!$duplicateURI) {
                                 $this->addError(__('All navigation links must have different URIs.'));
                                 $duplicateURI = true;
                                 $hasErrors = true;
                             }
                         }
                     } catch (Omeka_Navigation_Page_Uri_Exception $e) {
                         $this->addError(__('Invalid URI for "%s" navigation link:  "%s"', $pageLink['label'], $pageLink['uri']));
                         $hasErrors = true;
                     }
                 }
             }
         }
     }
     $hasErrors = $hasErrors || $this->_postHasDeletedUndeletablePage();
     return !$hasErrors;
 }