Exemplo n.º 1
0
 /**
  * Sets up required mocks and the CommentStatistics service under test.
  */
 protected function setUp()
 {
     $this->statement = $this->getMockBuilder('Drupal\\Core\\Database\\Driver\\sqlite\\Statement')->disableOriginalConstructor()->getMock();
     $this->statement->expects($this->any())->method('fetchObject')->will($this->returnCallback(array($this, 'fetchObjectCallback')));
     $this->select = $this->getMockBuilder('Drupal\\Core\\Database\\Query\\Select')->disableOriginalConstructor()->getMock();
     $this->select->expects($this->any())->method('fields')->will($this->returnSelf());
     $this->select->expects($this->any())->method('condition')->will($this->returnSelf());
     $this->select->expects($this->any())->method('execute')->will($this->returnValue($this->statement));
     $this->database = $this->getMockBuilder('Drupal\\Core\\Database\\Connection')->disableOriginalConstructor()->getMock();
     $this->database->expects($this->once())->method('select')->will($this->returnValue($this->select));
     $this->commentStatistics = new CommentStatistics($this->database, $this->getMock('Drupal\\Core\\Session\\AccountInterface'), $this->getMock('Drupal\\Core\\Entity\\EntityManagerInterface'), $this->getMock('Drupal\\Core\\State\\StateInterface'));
 }
 /**
  * Tests ContentEntityDatabaseStorage::onEntityTypeCreate().
  *
  * @covers ::__construct
  * @covers ::onEntityTypeCreate
  * @covers ::getTableMapping
  */
 public function testOnEntityTypeCreate()
 {
     $columns = array('value' => array('type' => 'int'));
     $this->fieldDefinitions = $this->mockFieldDefinitions(array('id'));
     $this->fieldDefinitions['id']->expects($this->any())->method('getColumns')->will($this->returnValue($columns));
     $this->fieldDefinitions['id']->expects($this->once())->method('getSchema')->will($this->returnValue(array('columns' => $columns)));
     $this->entityType->expects($this->once())->method('getKeys')->will($this->returnValue(array('id' => 'id')));
     $this->entityType->expects($this->any())->method('getKey')->will($this->returnValueMap(array(array('id', 'id'), array('uuid', NULL), array('bundle', NULL), array('id' => 'id'), array('id' => 'id'))));
     $this->setUpEntityStorage();
     $expected = array('description' => 'The base table for entity_test entities.', 'fields' => array('id' => array('type' => 'serial', 'not null' => TRUE)), 'primary key' => array('id'), 'unique keys' => array(), 'indexes' => array(), 'foreign keys' => array());
     $schema_handler = $this->getMockBuilder('Drupal\\Core\\Database\\Schema')->disableOriginalConstructor()->getMock();
     $schema_handler->expects($this->any())->method('createTable')->with($this->equalTo('entity_test'), $this->equalTo($expected));
     $this->connection->expects($this->once())->method('schema')->will($this->returnValue($schema_handler));
     $storage = $this->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage')->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager))->setMethods(array('getStorageSchema'))->getMock();
     $key_value = $this->getMock('Drupal\\Core\\KeyValueStore\\KeyValueStoreInterface');
     $schema_handler = $this->getMockBuilder('Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorageSchema')->setConstructorArgs(array($this->entityManager, $this->entityType, $storage, $this->connection))->setMethods(array('installedStorageSchema', 'createSharedTableSchema'))->getMock();
     $schema_handler->expects($this->any())->method('installedStorageSchema')->will($this->returnValue($key_value));
     $storage->expects($this->any())->method('getStorageSchema')->will($this->returnValue($schema_handler));
     $storage->onEntityTypeCreate($this->entityType);
 }
Exemplo n.º 3
0
 /**
  * @covers ::deleteProvider
  * @covers ::__construct
  */
 function testDeleteProviders()
 {
     $this->connection->expects($this->once())->method('delete')->with($this->equalTo('authmap'))->will($this->returnValue($this->delete));
     $authmap = new Authmap($this->connection);
     $authmap->delete("test_provider");
 }