X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Ftests%2Fsrc%2FUnit%2FTestBase.php;fp=web%2Fmodules%2Fcontrib%2Fdrupalmoduleupgrader%2Ftests%2Fsrc%2FUnit%2FTestBase.php;h=d3c324f9e8041d9335798b3a9f8b72828edfbf4d;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/drupalmoduleupgrader/tests/src/Unit/TestBase.php b/web/modules/contrib/drupalmoduleupgrader/tests/src/Unit/TestBase.php new file mode 100644 index 000000000..d3c324f9e --- /dev/null +++ b/web/modules/contrib/drupalmoduleupgrader/tests/src/Unit/TestBase.php @@ -0,0 +1,82 @@ +info = $this->getAnnotations(); + + $this->dir = $this->mockModule('foo'); + + $this->mockContainer(); + $this->mockTranslator(); + $this->mockLogger(); + $this->initDB(); + + // At the time of this writing, Target will pull the indexer manager out + // of the container right away, so let's mock it. + $indexers = $this->getMock('\Drupal\Component\Plugin\PluginManagerInterface'); + $this->container->set('plugin.manager.drupalmoduleupgrader.indexer', $indexers); + + $this->target = new Target($this->dir->url(), $this->container); + } + + /** + * Instantiates the plugin class covered by this test (as indicated by the + * @covers annotation). The plugin instance is given a randomly generated + * ID and description. Dependencies will be pulled from $this->container, + * so this should only be called once the mock container is ready. + * + * @param array $configuration + * Additional configuration to pass to the instance. + * @param array $plugin_definition + * Additional definition info to pass to the instance. + * + * @return object + * A plugin instance. + */ + protected function getPlugin(array $configuration = [], $plugin_definition = []) { + $plugin_definition['description'] = $this->getRandomGenerator()->sentences(4); + + $class = $this->info['class']['covers'][0]; + return $class::create($this->container, $configuration, $this->randomMachineName(), $plugin_definition); + } + +}