The plugin I'm unit testing with phpunit has a dependency on another plugin, using is_plugin_active().
When testing the dependency in my unit test that function always returns false/inactive, when the it is definitely active, because it's working properly in the plugin itself. It seems to be accessible, so there must be some logic error when it comes to this wordpress core function.
This is my code:
function test_requirementsMet_true() {
$this->assertTrue(is_plugin_active('pluginFolder/plugin.php'));
}
Does anyone know of a work-around?
Assuming you scaffolded your tests with WP-CLI, you should know the plugin is loaded as an mu-plugin rather than a vanilla plugin, which means:
Only plugins installed in the plugins/ folder can be active.
Plugins in the mu-plugins/ folder can’t be "activated," so this
function will return false for those plugins.
Related
I'm new to using PHPStorm along with PHPUnit, and the wordpress-develop package.
My projects rely on WooCommerce a lot.
Is it possible to add it as a dependency to the project?
At the moment I get this result:
And have the following setup:
Any help appreciated.
Got it working
What I did was use git to clone the woocommerce project
git clone https://github.com/woocommerce/woocommerce/ temp
Then I copied the tests folder and put it inside my project. Then I kept making edits until it worked with my existing code.
Here is what my project looks like now:
I have a copy of the normal woocommerce project in my includes. The one without the tests, the one you can download from the WordPress plugin repository.
I copied the WooCommerce tests into the project, see folder wc_tests.
Here is what the tests/bootstrap.php file looks like
Note the last line that requires the wc_tests/bootstrap.php file.
I only made one change to the wc_tests file, I changed the plugin directory.
$this->plugin_dir = dirname( $this->tests_dir ) . '/includes/woocommerce';
Combined with a line of code out of screen, it makes the WC available for the project
require_once $this->plugin_dir . '/woocommerce.php';
I'm probably doing some of this wrong, but it works.
Any further questions, tips or advice appreciated.
I'm updating Fishpig Wordpress-Integration to version 4.5.1.5 (with addons ACF, CPT, CS, Root, Multisite) in a new ansible-deployment. Now I get the follwoing error in the Magento-Backend :
Permissions The following file must be writable: /path/to/magento/wp/wp-includes/l10n.php
Why at all should a magento-module have write-permissions on a wordpress-core-file?
We prefer strongly to have separate concerns, so that the wp-core-files can't be compromised by anything from magento-side.
The questions are:
for which task in Fishpig (or it's addons) this write permission will be used?
could the _validateL10nPermissions() be overwritten for not checking this file without loosing an important functionality in Fishpig?
Would be great to get some clarification about this point.
This file needs to be modified because both Magento and WordPress have a PHP function with the same name, specifically the translation function:
function __($args);
It is not possible to have multiple functions in PHP with the same name. The only way to include the WP code base into Magento and make it available is to stop either Magento or WordPress from defining this function. The module chooses to modify the WP file instead of the Magento file.
The modification it makes it a simple one. It simply wraps the function definition in WordPress with a call to function_exists. This checks whether the function has already been defined (ie. in Magento) and if it has, it doesn't define it again. If it hasn't been defined, it defines it.
if (!function_exists('__')) {
function __($args);
}
This allows WordPress to work on it's own and when included into the Magento code. Without this modification, it is not possible to use Magento and WordPress together.
Write permissions are only required if the file does not include the modification. If the file already includes the modification then write permissions are not required. If you don't want to give write permissions on your live server, have the file modification take place either on a dev/staging server or make the file modification yourself as part of your deployment process.
I am using FOSUserBundle in some Symfony2 Projects.
To override the login page, I normally create a Twig file like this: /app/Resources/FOSUserBundle/views/security/login.html.twig.
In the past projects I created, this worked normally and did override the login page.
Recently, I have been working on a new Symfony project with a teammate. Overriding the login page worked in my environment but NOT in his environment. We tried uploading the project to a test server where it also didn't override the login page (It used to override it for other projects we tested).
We are using Symfony 2.7 with Linux Distros for all the environments. In my case, I use Ubuntu Server. My teammate runs Ubuntu Mate and the test server runs Ubuntu.
We checked folder permissions and ownerships and everything is ok.
Everything in the project works except this little twig override for the FOSUserBundle login page.
We already tried php clear:cache and manually deleting the cache folder.
We also tried this solution: What is the issue with not overriding templates in symfony2.6 and FOSUserBundle 1.3, where the answer suggests that the problem is the way PHP caches the file stats. This also didnt' work.
Any suggestions or maybe some PHP configs that we could try?
Thanks in advance,
It may be a problem with a case sensitivity.
Change it to /app/Resources/FOSUserBundle/views/Security/login.html.twig (lower case s -> upper case S). And then check by ls -l (also check your version control if relevant).
I'm building a site starting from the magnolia empty webapp with maven.
All is ok but now I'm now writing the contact page of the site. I'd like to use the magnolia mail module for this. So I installed the mail module and the form module.
Problem:
After installing the form module in magnolia 5.4, the template called "Form" does not appear in the template selection when creating a new page in the pages app.
As it seems from the Documentation, it should be there.
Details:
Other templates, created by me with yaml and freemarker, correctly appear (and i can use them correctly).
The mail module is up and running and configured: i can send a mail to myself with the "verify setting" page, using a template i made, but i'd like to create a contact module for my site.
I installed the module with maven like:
dependency: groupId:info.magnolia, artifactId:magnolia-module-form , version:2.3
and installed it with the usual steps (installed module, wait , correctly completed without messages, started magnolia)
I DO NOT have STK installed since i'm using MTE... and i've other modules installed (resources, site, mail, MTE, DAM, etc...)
Am I missing something or doing something wrong? :|
Otherwise, Can the magnolia mail module simply be used standalone without the form module to send out a email, may be pointing a hand-written form to somewhere?
Or, best option imho: can I make a new form template with yaml? I can't find docs about it.
Thank you!.
Edit: I tried to install the STK along with MTE (I correctly updated to magnolia 5.4.1) but it relies on data-module 2.3.6 (which i don't have in my dependencies and which i don't use) so it won't install the STK. Also , installing STK just for a form template seems overkill to me. I'd prefere to understand how to insert a form in one of my templates.
Preinstalled templates are for STK. If you want to use Magnolia without STK, then you need to write template yourself, but in exchange have much more freedom in what you can do with that template. Once you create and register template you should be able to use it.
Re STK - latest version doesn't have any dependency on data module - see module descriptor. Either I'm blind or there is no such dependency. :D
HTH,
Jan
I've moved my front-end workflow over to Gulp and am having a wicked time when developing static sites. I currently use BrowserSync, which spins up a server and reloads my page every time a change is detected – it's wonderful.
I was wondering if there is way to do this with WordPress when using MAMP? With MAMP PRO obviously using its own servers, is there a way I can tell my gulpfile.js to use BrowserSync while I'm running a WordPress site locally?
Hope that makes sense. Any help is appreciated. Thanks in advance!
I had to somewhat solve this issue for the company where I work.
The result of that work can be found here: https://github.com/MozaikAgency/wp-theme-bootstrap Feel free to browse, use and contribute :)
Note: The following does not specifically refer to MAMP because if you have node and gulp installed on your system it will work irrespective of where the site itself is being hosted/running from. The server running WordPress and the server that browser-sync will spin up are separate and unrelated. For reference we use this alongside XAMP at work to develop our WP themes
Specifically we wanted to have a development environment with all the bells and whistles (and that definitely includes browser-sync), but have a built theme that was clean from development cruft (browser-sync snippets, gulpfile.js etc).
The idea is, you would write only in the dev theme, let's say wp-contents/themes/example-theme_dev, and gulp would handle everything it needs to do, to generate the built theme, into let's say wp-content/themes/example-theme.
Note: This is not a tutorial, just an overview of some things that should be happening to get browser-sync to work with a WordPress setup. You can check out the repo itself to see the full way we tied everything together.
Browser-Sync Implementation
Since we are anyway moving files over from the "dev theme" to the "built theme" we get a chance to transform those files before shifting them over.
During dev mode (default gulp task), one of the transformations will specifically inject the following snippet into the bottom of your theme's functions.php
/**
* DEVELOPMENT MODE ONLY
*
* Browser-sync script loader
* to enable script/style injection
*
*/
add_action( 'wp_head', function () { ?>
<script type="text/javascript" id="__bs_script__">//<![CDATA[
document.write("<script async src='http://HOST:3000/browser-sync/browser-sync-client.js'><\/script>".replace("HOST", location.hostname));
//]]></script>
<?php }, 999);
This action will print out a script into your theme's head to link up to the browser-sync server and will handle all page refresh/injections your build process throws at it.
The actual server that this script points to is booted when you run the following gulp task (also called with the default gulp task):
var browserSync = require('browser-sync');
/**
* Spin up the browser-sync
* socket server to listen for
* and push code changes to the
* browser
*
*/
module.exports = function (done) {
browserSync({
logSnippet: false,
server: false,
open: false,
reloadDelay: 100,
reloadDebounce: 100
});
done();
};
So, you have your browser-sync server up and running and your theme can now update automatically using the script snippet, now all that is left is telling browser-sync what it should update and when.
For this, I found that the best way to approach it was to explicitly tell browser-sync to update right after any transforming gulp tasks, like sass to css processing, were done running. Mostly you just need to add the following to the end of your gulp tasks:
.on('end', browserSync.reload);
where browserSync is simply:
var browserSync = require('browser-sync');
Wrap up
This answer covers the basics you'll need to get browser-sync into your WP workflow. You can check out the wp-theme-bootstrap repo where we put all of this together to see the entire picture of how it works and try it out for yourselves, if you are interested.
We've been using this successfully now at the company for a while now. Hope you find it useful and if you have any suggestions feel free to chime in.