コード例 #1
0
ファイル: TermStorage.php プロジェクト: alnutile/drunatra
 /**
  * {@inheritdoc}
  *
  * @param array $values
  *   An array of values to set, keyed by property name. A value for the
  *   vocabulary ID ('vid') is required.
  */
 public function create(array $values = array())
 {
     // Save new terms with no parents by default.
     if (empty($values['parent'])) {
         $values['parent'] = array(0);
     }
     $entity = parent::create($values);
     return $entity;
 }
コード例 #2
0
 /**
  * Tests groupby with filters.
  */
 public function testGroupByCountOnlyFilters()
 {
     // Check if GROUP BY and HAVING are included when a view
     // Doesn't display SUM, COUNT, MAX... functions in SELECT statement
     for ($x = 0; $x < 10; $x++) {
         $this->storage->create(array('name' => 'name1'))->save();
     }
     $view = Views::getView('test_group_by_in_filters');
     $this->executeView($view);
     $this->assertTrue(strpos($view->build_info['query'], 'GROUP BY'), 'Make sure that GROUP BY is in the query');
     $this->assertTrue(strpos($view->build_info['query'], 'HAVING'), 'Make sure that HAVING is in the query');
 }
コード例 #3
0
 /**
  * @covers ::create()
  */
 public function testCreate()
 {
     $language_manager = $this->getMock('Drupal\\Core\\Language\\LanguageManagerInterface');
     $this->container->set('language_manager', $language_manager);
     $this->container->set('entity.manager', $this->entityManager);
     $this->container->set('module_handler', $this->moduleHandler);
     $entity = $this->getMockBuilder('Drupal\\Core\\Entity\\ContentEntityBase')->disableOriginalConstructor()->setMethods(array('id'))->getMockForAbstractClass();
     $this->entityType->expects($this->atLeastOnce())->method('id')->will($this->returnValue($this->entityTypeId));
     $this->entityType->expects($this->atLeastOnce())->method('getClass')->will($this->returnValue(get_class($entity)));
     $this->entityType->expects($this->atLeastOnce())->method('getKeys')->will($this->returnValue(array('id' => 'id')));
     // ContentEntityStorageBase iterates over the entity which calls this method
     // internally in ContentEntityBase::getProperties().
     $this->entityManager->expects($this->once())->method('getFieldDefinitions')->will($this->returnValue(array()));
     $this->entityType->expects($this->atLeastOnce())->method('isRevisionable')->will($this->returnValue(FALSE));
     $this->entityManager->expects($this->atLeastOnce())->method('getDefinition')->with($this->entityType->id())->will($this->returnValue($this->entityType));
     $this->setUpEntityStorage();
     $entity = $this->entityStorage->create();
     $entity->expects($this->atLeastOnce())->method('id')->will($this->returnValue('foo'));
     $this->assertInstanceOf('Drupal\\Core\\Entity\\EntityInterface', $entity);
     $this->assertSame('foo', $entity->id());
     $this->assertTrue($entity->isNew());
 }