Beispiel #1
0
 /**
  * Tests the join plugin base.
  */
 public function testBasePlugin()
 {
     // Setup a simple join and test the result sql.
     $view = Views::getView('test_view');
     $view->initDisplay();
     $view->initQuery();
     // First define a simple join without an extra condition.
     // Set the various options on the join object.
     $configuration = array('left_table' => 'views_test_data', 'left_field' => 'uid', 'table' => 'users', 'field' => 'uid', 'adjusted' => TRUE);
     $join = $this->manager->createInstance('standard', $configuration);
     $this->assertTrue($join instanceof JoinPluginBase, 'The correct join class got loaded.');
     $this->assertNull($join->extra, 'The field extra was not overriden.');
     $this->assertTrue($join->adjusted, 'The field adjusted was set correctly.');
     // Build the actual join values and read them back from the dbtng query
     // object.
     $query = db_select('views_test_data');
     $table = array('alias' => 'users');
     $join->buildJoin($query, $table, $view->query);
     $tables = $query->getTables();
     $join_info = $tables['users'];
     $this->assertEqual($join_info['join type'], 'LEFT', 'Make sure the default join type is LEFT');
     $this->assertEqual($join_info['table'], $configuration['table']);
     $this->assertEqual($join_info['alias'], 'users');
     $this->assertEqual($join_info['condition'], 'views_test_data.uid = users.uid');
     // Set a different alias and make sure table info is as expected.
     $join = $this->manager->createInstance('standard', $configuration);
     $table = array('alias' => 'users1');
     $join->buildJoin($query, $table, $view->query);
     $tables = $query->getTables();
     $join_info = $tables['users1'];
     $this->assertEqual($join_info['alias'], 'users1');
     // Set a different join type (INNER) and make sure it is used.
     $configuration['type'] = 'INNER';
     $join = $this->manager->createInstance('standard', $configuration);
     $table = array('alias' => 'users2');
     $join->buildJoin($query, $table, $view->query);
     $tables = $query->getTables();
     $join_info = $tables['users2'];
     $this->assertEqual($join_info['join type'], 'INNER');
     // Setup addition conditions and make sure it is used.
     $random_name_1 = $this->randomName();
     $random_name_2 = $this->randomName();
     $configuration['extra'] = array(array('field' => 'name', 'value' => $random_name_1), array('field' => 'name', 'value' => $random_name_2, 'operator' => '<>'));
     $join = $this->manager->createInstance('standard', $configuration);
     $table = array('alias' => 'users3');
     $join->buildJoin($query, $table, $view->query);
     $tables = $query->getTables();
     $join_info = $tables['users3'];
     $this->assertTrue(strpos($join_info['condition'], "users3.name = :views_join_condition_0") !== FALSE, 'Make sure the first extra join condition appears in the query and uses the first placeholder.');
     $this->assertTrue(strpos($join_info['condition'], "users3.name <> :views_join_condition_1") !== FALSE, 'Make sure the second extra join condition appears in the query and uses the second placeholder.');
     $this->assertEqual(array_values($join_info['arguments']), array($random_name_1, $random_name_2), 'Make sure the arguments are in the right order');
 }
 /**
  * Returns some mocked view entity, view executable, and access plugin.
  */
 protected function setupViewExecutableAccessPlugin()
 {
     $view_entity = $this->getMockBuilder('Drupal\\views\\Entity\\View')->disableOriginalConstructor()->getMock();
     $view_entity->expects($this->any())->method('id')->will($this->returnValue('test_id'));
     $view = $this->getMockBuilder('Drupal\\views\\ViewExecutable')->disableOriginalConstructor()->getMock();
     $view->storage = $view_entity;
     // Skip views options caching.
     $view->editing = TRUE;
     $access_plugin = $this->getMockBuilder('Drupal\\views\\Plugin\\views\\access\\AccessPluginBase')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->accessPluginManager->expects($this->any())->method('createInstance')->will($this->returnValue($access_plugin));
     return array($view, $view_entity, $access_plugin);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $wizard_type = $form_state->getValue(array('show', 'wizard_key'));
     $wizard_instance = $this->wizardManager->createInstance($wizard_type);
     $form_state->set('wizard', $wizard_instance->getPluginDefinition());
     $form_state->set('wizard_instance', $wizard_instance);
     $errors = $wizard_instance->validateView($form, $form_state);
     foreach ($errors as $display_errors) {
         foreach ($display_errors as $name => $message) {
             $form_state->setErrorByName($name, $message);
         }
     }
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function validate(array $form, FormStateInterface $form_state)
 {
     $wizard_type = $form_state['values']['show']['wizard_key'];
     $wizard_instance = $this->wizardManager->createInstance($wizard_type);
     $form_state['wizard'] = $wizard_instance->getPluginDefinition();
     $form_state['wizard_instance'] = $wizard_instance;
     $errors = $form_state['wizard_instance']->validateView($form, $form_state);
     foreach ($errors as $display_errors) {
         foreach ($display_errors as $name => $message) {
             $form_state->setErrorByName($name, $message);
         }
     }
 }